Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I made a simple script that uses "du" to show me how much each divx movie I have takes space on disk. Now, I'd like to add feature to show movie length besides the file size.
I know that many (all?) movie players like mplayer, xine, etc. know this data, but I haven't found a way to retrieve it from them.
It would be great if I could just do:
mplayer --get-length movie.avi
what kind of files are you doing? if you're just looking at simple avi files all the time then it's actually very very very simple.
Code:
chris@kermit chris $ ./aviinfo /var/film/futurama/futurama-1-01-space_pilot_3000.avi
ms per frame: 50000
total frames: 26186
width: 352
height: 240
chris@kermit chris $ cat aviinfo
#!/usr/bin/perl
use strict;
open (AVI, $ARGV[0]);
my $data = "";
my $i;
# find hdrl
for (1..200) {
read AVI, $data, 4;
last if $data eq "hdrl"
}
#while ($data ne "hdrl")
#{ read AVI, $data, 4 }
# find avih
read AVI, $data, 4;
# waste 4
read AVI, $data, 4;
# ms per frame
read AVI, $data, 4;
print"ms per frame: " . converttoint($data). "\n";
# waste 12
read AVI, $data, 12;
# total frames
read AVI, $data, 4;
print"total frames: " . converttoint($data). "\n";
# waste 12
read AVI, $data, 12;
# width
read AVI, $data, 4;
print "width: " . converttoint($data) . "\n";
# height
read AVI, $data, 4;
print "height: " . converttoint($data) . "\n";
sub converttoint {
my $total=0;
for ($i = 0; $i < length($data); $i++) {
my $c = substr($data, $i, 1);
my $value = 256**$i * ord($c);
$total += $value;
}
return $total;
}
don't worry if you're not used to perl... you'll do fine to just hack out the bits you don't want and reformat the results etc... you can do it!
it's easy to get a similar result from mplayer, using the -identify option, but this is much slower, and will still require parsing and processing anyway.
There is also tcprobe, part of the transcode package, that can (usually) tell you the running time of most videos. 'tcprobe -i filename'
Extracting the relevant information, though, would require additional scripting stuff with perl or whatnot. If you plan to re-use the information inside a script, you'll probably need to do something like acid_kewpie's script does.
You're right, it'd be great if there was a simple little utility to spit out that kind of info. I have some scripts that need to know frame rate, resolution, etc. Maybe if no such thing exists, I should work on writing one...
edit: Looks like 'mplayer -identify' produces the best starting place for such output (thanks acid_kewpie!), especially when run from the 'midentify' script (mine's in /usr/share/doc/mplayer-1.0_pre4/TOOLS) that suppresses other output. Here's a little script (complete hack, but gets the job done)
Perhaps instead of the for-loop construct, you could use the -exec option of 'find' to execute the script for each result. Not sure of the exact syntax, but try:
Code:
find . -iname '*.avi' -exec size.sh '{}' ';'
That should run size.sh, passing each result of 'find' to it in turn. Not sure how to get it to print out each one as it does them, but I guess you could make that part of size.sh. Maybe this:
Originally posted by wapcaplet Perhaps instead of the for-loop construct, you could use the -exec option of 'find' to execute the script for each result. Not sure of the exact syntax, but try:
Code:
find . -iname '*.avi' -exec size.sh '{}' ';'
Excellent.
That's exactly what I needed. I did try something with -exec but didn't know that I had to use {}
I have altered size.sh to output exactly what I want, so now I got the complete script that parses my entire movie database and prints movie names with sizes in MB and length. It also groups them by partitions and writes subtotals and total (in GB). (If anyone needs it, I can post it here)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.