Shows you how many hours of avi video you have.

/usr/share/mplayer/midentify.sh `find . -name "*.avi" -print` | grep ID_LENGTH | awk -F "=" '{sum += $2} END {print sum/60/60; print "hours"}'
midentify.sh is part of mplayer, but you might have to locate it on your box.
Sample Output
35.5096
hours

4
By: equant
2009-11-17 03:33:20

What Others Think

This seems to work a bit more reliably for me and finds other types of files. Plus, you don't need that grep. find . \( -name "*.flv" -o -name "*.avi" -o -name "*.ogm" -o -name "*.wmv" -o -name "*.mpg" \) -exec /usr/share/mplayer/midentify.sh {} \;|awk -F= '/ID_LENGTH/{sum+=$2}END{print sum/3600,"hours"}'
eightmillion · 598 weeks and 3 days ago
It's interesting that that's more reliable. I wonder why that is. It's certainly nice to get rid of the unnecessary grep. If you want to find multiple file types, I'd suggest considering using find's -iregex find . -iregex '.*\(avi\|swf\|wmv\|mpg\|ogm\)' I think that'd make it easier to add/subtract file types. Also it'd be case insensitive.
equant · 598 weeks and 3 days ago
That iregex is much better. I also modified the awk a bit to give hours, minutes, and seconds. find . -iregex '.*\(avi\|swf\|wmv\|mpg\|ogm\)' -exec /usr/share/mplayer/midentify.sh {} +|awk -F= '/ID_LENGTH/{sum+=$2}END{a=sum/3600;m=(a-int(a))*60;s=(m-int(m))*60;printf "%s %.2d:%.2d:%.2d\n","Total time:",a,m,s}'
eightmillion · 598 weeks and 3 days ago
And /usr/share/doc/mplayer/examples/midentify.sh for Karmic
DJArty · 598 weeks and 3 days ago
find -print0 | xargs -0 /usr/../midentify is waaaaaay more reliable than /usr/../midentify `find ` Command substitution has its uses. But pipes with xargs -0 is certainly more reliable!!
jnash · 598 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: