#!/usr/bin/perl -w # ###################################################################### +##### # # videoinfo.pm # # V 0.2.0 du 13/12/2004 # support de ffmpeg CVS # # 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 # renvoie les différentes infos sur un fichier video # dans un hash ########################################################## sub videoinfo { # commande ffmpeg my $ffmpeg='/usr/bin/ffmpeg'; # variables my %finfo = ('duration' => "00:00:00.0", 'bitrate' => "0", 'vcodec' => "", 'vformat' => "", 'vsize' => "", 'framerate' => "0.00", 'acodec' => "", 'samplerate' => "0", 'stereo' => "0", # 0 false (mono), 1 true (stereo) 'audiorate' => "0" ); # fichier à traiter my $file=shift; # échappement des caractères spéciaux $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>; # recherche des éléments foreach (@res) { # durée et bitrate if ( m!Duration: (\d\d:\d\d:\d\d\.\d), start: (\d|\.)+, bitrate: ( +\d+) kb/s! ) { $finfo{'duration'}=$1; $finfo{'bitrate'}=$3; next; } # vcodec, vformat et framerate if ( /(\d\d\.\d\d) fps\(r\): Video: (\w*), (\w+), (\d*x\d*)/) { $finfo{'framerate'}=$1; $finfo{'vcodec'}=$2; $finfo{'vformat'}=$3; $finfo{'vsize'}=$4; next; } # acodec, samplerate, stereo et 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; } ########################################## # fin ########################################## 1;
In reply to Re: Multimedia metadata extraction - how to have it all?
by wazoox
in thread Multimedia metadata extraction - how to have it all?
by robins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |