#!/usr/bin/perl -w # flvconvert.pl - use ffmpeg to convert an avi to flv # does not recursively dive into directories # # last modified 2-3-07 # by Pig Monkey (pm@pig-monkey.com) ##################################################### use strict; use File::Basename; use File::Spec; unless (@ARGV) { print "Usage: perl flvconvert.pl [OPTIONS] [FILES]\n\t Options:\n\t\t --size\tSpecify video size. Defaults to 320x240 if none specified.\n\t\t --fps\tSpecify frames per second. Defaults to 15 if none specified.\n\t\t --thumb\tCreate a jpeg from the first frame\n\t Example:\n\t\t perl flvconvert.pl file1.avi file2.avi video/* \n\t\t perl flvconvert.pl --size 640x480 --fps 30 file.avi\n"; exit; } my $ffmpeg = `which ffmpeg`; # find ffmpeg chomp ($ffmpeg); if ($ffmpeg eq "") { die "Couldn't find ffmpeg.\n"; } my $size = "320x240"; my $fps = "15"; my $thumbnail; while ($ARGV[0] =~ /^\-.*/) { if ($ARGV[0] eq "--size") { # check if user specified dimensions shift @ARGV; $size = $ARGV[0]; shift @ARGV; } elsif ($ARGV[0] eq "--fps") { # check if user specified fps shift @ARGV; $fps = $ARGV[0]; shift @ARGV; } elsif ($ARGV[0] eq "--thumb") { # check if user wants a thumbnail shift @ARGV; $thumbnail = 1; } else { print "Unrecognized option.\n"; exit; } } foreach (@ARGV) { unless ( (-e $_) && ($_ =~ /.*\.avi$/) ) { # make sure file exists and is .avi print "File $_ does not exist or is not an AVI. Skipping.\n"; next; } my $basename = basename $_; my $dirname = dirname $_; my $filename = $basename; $filename =~ s/(.*)\..*/$1/; # strip the file extension my $newfile = File::Spec->catfile($dirname, $filename) . ".flv"; # add a .flv extension my $newimg = File::Spec->catfile($dirname, $filename) . ".jpg"; # add a .jpg extension system $ffmpeg, "-i", $_, "-ab", "56", "-ar", "11025", "-r", $fps, "-b", "500", "-s", $size , $newfile; system $ffmpeg, "-i", $_, "-f", "mjpeg", "-t", "0.001", $newimg if $thumbnail; }