ffmpeg version#!/usr/bin/perl -w # ###################################################################### +##### # # videoinfo.pm # # V 0.3.1 08/04/05 # returns duration in frames (25f/s default) # # V 0.3.0 08/01/05 # use mpginfo instead of ffmpeg # # V 0.2.0 du 13/12/2004 # support of ffmpeg CVS # # V 0.1.0 of 20/11/2004 # ###################################################################### +##### # # Copyright (c) Intellique 2004 # All rights reserved. # # # This program is free software; you can redistribute it and/or mod +ify # it under the terms of the GNU General Public License as published + by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. use strict; require Exporter; our @ISA=qw(Exporter); our @EXPORT=qw(videoinfo); # débug (set to true top get debugging messages) my $debug; # mpginfo command my $mpginfo='/usr/bin/mpgtx -i'; ########################################################## # videoinfo # returns media information in a hash # ########################################################## sub videoinfo { # variables my %finfo = ('duration' => "0", # duration in frames 'bitrate' => "0", # Mux bitrate video + audio 'vcodec' => "", 'vformat' => "", 'framerate' => "0.00", 'acodec' => "", 'samplerate' => "0", 'stereo' => "0", # 0 false (mono), 1 true (stereo) 'audiorate' => "0" ); # file to test my $file=shift; # escaping characters $file=~s/(\W)/\\$1/g; my @res; #scan only MPEG if ( $file =~ m/(MP.)$/i) { @res= `$mpginfo $file` or warn "can't run $mpginfo\n"; } # parse mpgtx output foreach (@res) { # bitrate total if ( m!Muxrate : (\d+\.?\d*) Mbps! ) { $finfo{'bitrate'}=$1; next; } # Duration if ( m!Duration: (.*[0-9][0-9]\.[0-9][0-9])s! ) { $finfo{'duration'}=$1; # convert to frame count my @tu=split(/:|\./, $finfo{'duration'}); # parse duration from end my ($c, $s, $m, $h)=reverse(@tu); # duration in seconds, converted to frames later no warnings qw(uninitialized); $finfo{'duration'}=($h*360000+$m*6000+$s*100+$c)/100; use warnings; next; } # vformat and framerate if ( /Size \[(\d+ x \d+)\]\s+(\d+\.\d+) fps/) { $finfo{'vformat'}=$1; $finfo{'framerate'}=$2; next; } # acodec if ( m!Audio : (.*)! ) { $finfo{'acodec'}=$1; next; } # audiorate and samplerate if ( m!\s+(\d+) kbps (\d+) Hz! ) { $finfo{'audiorate'}=$1; $finfo{'samplerate'}=$2; next; } # Stereo or mono if ( /Stereo/ ) { $finfo{'stereo'}=1; } } # compute the duration in frames if ($finfo{'framerate'}>1) { $finfo{'duration'}=sprintf( "%.0f", $finfo{'duration'}*$finfo{'fra +merate'}); } else { #if no framerate (audio) set to default 25/s $finfo{'duration'}=sprintf( "%.0f", $finfo{'duration'}*25); } return %finfo; } ########################################## # end ########################################## 1;
#!/usr/bin/perl -w # ###################################################################### +##### # # # V 0.2.0 du 13/12/2004 # support of ffmpeg CVS # # videoinfo.pm # V 0.1.0 du 20/11/2004 # ###################################################################### +##### # # Copyright (c) Intellique 2004 # All rights reserved. # # # This program is free software; you can redistribute it and/or mod +ify # it under the terms of the GNU General Public License as published + by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. use strict; require Exporter; use IPC::Open3; our @ISA=qw(Exporter); our @EXPORT=qw(videoinfo); ########################################################## # videoinfo # returns media information in a hash # ########################################################## sub videoinfo { # ffmpeg command my $ffmpeg='/usr/bin/ffmpeg'; # variables my %finfo = ('duration' => "00:00:00.0", 'bitrate' => "0", 'vcodec' => "", 'vformat' => "", 'framerate' => "0.00", 'acodec' => "", 'samplerate' => "0", 'stereo' => "0", # 0 false (mono), 1 true (stereo) 'audiorate' => "0" ); # fichier à traiter my $file=shift; # escaping characters $file=~s/(\W)/\\$1/g; open3("</dev/null",">/dev/null",\*ERPH, "$ffmpeg -i $file") or die "ca +n't run $ffmpeg\n"; my @res=<ERPH>; # parse ffmpeg output foreach (@res) { # duration and bitrate if ( m!Duration: ([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]), bitrate +: (\d*) kb/s! ) { $finfo{'duration'}=$1; $finfo{'bitrate'}=$2; } # vcodec, vformat and framerate if ( /Video: (\w*), (\d*x\d*), (\d*.\d*) fps/) { $finfo{'vcodec'}=$1; $finfo{'vformat'}=$2; $finfo{'framerate'}=$3; } # acodec, samplerate, stereo and audiorate if ( m!Audio: (\w*), (\d*) Hz, (mono|stereo), (\d*) kb/s!) { $finfo{'acodec'}=$1; $finfo{'samplerate'}=$2; $finfo{'stereo'}=(($3 eq 'stereo')|| 0 ); $finfo{'audiorate'}= +$4; } } return %finfo; } ########################################## # end ########################################## 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Video information
by ihb (Deacon) on May 09, 2005 at 20:06 UTC | |
by wazoox (Prior) on May 09, 2005 at 20:45 UTC | |
|
Re: Video information
by jeffa (Bishop) on May 09, 2005 at 16:48 UTC |