Here is one way to get the size and bitrate of a video using ffmpeg:
getvideosize.pl
Example usage:
Output: 854x480 537
getvideosize.pl
#!/usr/bin/perl -w use strict; use warnings; my $file = $ARGV[0]; die "usage: arg1 must be a video file\n" unless $file; sub trim { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } open (FILE, "ffmpeg -i \"$file\" 2>&1 |"); while (<FILE>) { my $line = $_; next unless ($line =~ m/^\s+Stream #.+?: Video/); my @pieces = split (',', $line); my @vsize = split (' ', trim ($pieces[2])); my @vbits = split (' ', trim ($pieces[3])); my $video_size = trim (shift @vsize); my $video_bits = trim (shift @vbits); print "$video_size $video_bits\n"; last; }
Example usage:
./getvideosize.pl http://bennugd-vlc.googlecode.com/files/sintel_trail +er-480p.mp4
Output: 854x480 537
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Get size and bitrate of video with perl and ffmpeg
by zengargoyle (Deacon) on Jul 30, 2012 at 20:35 UTC | |
Re: Get size and bitrate of video with perl and ffmpeg
by jwkrahn (Abbot) on Jul 31, 2012 at 04:06 UTC | |
Re: Get size and bitrate of video with perl and ffmpeg
by aitap (Curate) on Aug 04, 2012 at 14:38 UTC |
Back to
Cool Uses for Perl