Here's the script :
-
#!/usr/bin/perl
-
use strict;
-
use JSON;
-
-
my $files = "[\n";
-
-
while(){
-
my ( $md5 ) = split( " ", `md5sum $_` );
-
my $ffmpegInfo = `ffmpeg -i $_ 2>/dev/stdout`;
-
my $file = {fileName => $_,md5 => $md5,bruteInfo => `file $_`};
-
for( split( "\n", $ffmpegInfo ) ){
-
if( /bitrate\:\ ([\d]*?)\ kb\/s/ ){ $file->{ bitrate } = $1; }
-
if( /Duration\:\ (.*?)\,\ start/ ){ $file->{ duration } = $1; }
-
if( /Video\:\ (.*?)\,\ (.*?)\,\ (.*?)\,\ (.*?)\ fps/ ){ $file->{ codec } = $1;$file->{ video } = $2;$file->{ resolution } = $3;$file->{ fps } = $4; }
-
if( /Audio\:\ (.*?)\,\ ([\d]*?)\ Hz\,.*?\,(.*?)\ kb\/s/ ){ $file->{ audioCodec } = $1;$file->{ hertz } = $2;$file->{ audioBitRate } = $3; }
-
if( $file->{ duration } =~ /(\d\d)\:(\d\d)\:(\d\d)\.(\d)/ ){ $file->{ durationSeconds } = ( $1 * 3600 ) + ( $2 * 60 ) + $3 ; }
-
}
-
my $command = "ffmpeg -i $_ ";
-
if( $file->{ bitrate }> 1000 ){ $command .= " -b 1000 " }else{ $command .= " -b " . $file->{ bitrate } . " " }
-
$command .= " $md5.flv ";
-
system( $command );
-
$files .= objToJson( $file ) . ",\n";
-
}
-
-
$files .= "]";
-
-
print $files;
-
How to use it :
find . -name '*YAPC*.avi' |perl encode.pl > info.js
What it does ?
* Searches for all my YAPC videos.
Then for each file :
* The script gets various information about the file ( video/audio info, length, MD5sum - which will be used for file naming )
* It encodes the movies to Flash Video format.
* And finally saves all Info about the files in a nice JSON file.
This of course is not perfect ( you'll probably often get bugs due to bad Audio Rate for example, but it's easy to fix )
Requirements :
* You need to have ffmpeg compiled with the --enable-mp3lame option ( see : http://ubuntuguide.org/wiki/Ubuntu:Feisty#How_to_enable_lame_for_FFMPEG_.28needed_to_encode_FLV_with_sound.29 )
* You need the JSON Perl module ( see : http://search.cpan.org/~makamaka/JSON-1.13/lib/JSON.pm )
Next time we'll see how to reuse the files we've created, client side, in a very funky way with very little of javascript code ![]()
And you'll get everything you need to get any video you want ready for streaming in just a bunch of minutes.

Entries (RSS)