#!/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 modify # 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",\*ERPH, "$ffmpeg -i $file") or die "can't run $ffmpeg\n"; my @res=; # 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;