#!/usr/bin/perl # Requirements: # - Need to set up location of mencoder # - Need to set up location of ffmpeg # # OS Support: # - Tested on windows XP SP2 # - Tested on Mac OS X r10.4 # # Input: AVI file # Output: FLV file (in user's Videos directory) # options: # -rotate [90,180,270] // rotate original AVI, in degrees # -lint // print command lines, but don't execute # GLOBALS $opt_rotate = undef; $opt_lint = undef; $opt_o = undef; $HEIGHT = 360; $WIDTH = 480; if ($^O eq "MSWin32") { $MENCODER = "c:\\Documents and Settings\\jshrall\\My Documents\\bin\\MPlayer\\mencoder.exe"; $FFMPEG = "c:\\Documents and Settings\\jshrall\\My Documents\\bin\\ffmpeg\\bin\\ffmpeg.exe"; $RM = "del"; $CP = "copy"; } elsif ($^O eq "darwin") { $MENCODER = "/usr/local/bin/mencoder"; $FFMPEG = "/opt/local/bin/ffmpeg"; $RM = "rm"; $CP = "cp"; } else { die "Sorry, I do not understand your OS: $^O. Goodbye\n"; } # PROGRAM @args = &parse_args; if (scalar @args == 0 || !-e $args[0]) { warn "\nERROR: Input file missing.\n"; &help(); } # Make file names $input_file = $args[0]; if ($input_file !~ /\.avi$/i) { warn "Unsupported input file type. Please use AVI files only\n"; &help(); } # tmp file is used as a temporary output file - we don't want to # mess with the original and risk corruption! ($tmp_file = $input_file) =~ s/\.avi$/_tmp.avi/i; if (!defined($opt_o)) { # Construct the output file name if ($^O eq "MSWin32") { ($output_file = $input_file) =~ s|.*\\(.*)\.avi$|$1|i; # Dump the file to the user's videos directory $output_file = $ENV{USERPROFILE} . "\\My Documents\\My Videos\\$output_file.flv"; } elsif ($^O eq "darwin") { ($output_file = $input_file) =~ s|.*/(.*)\.avi$|$1|i; # Dump the file to the user's videos directory $output_file = $ENV{HOME} . "\\Videos\\$output_file.flv"; } } else { $output_file = $opt_o; } # rotate AVI if needed if (defined($opt_rotate)) { &syscall(qq!"$MENCODER" -vf rotate=$opt_rotate -o "$tmp_file" -oac copy -ovc lavc "$input_file"!); } else { &syscall(qq!$CP "$input_file" "$tmp_file"!); } &syscall(qq!"$FFMPEG" -i "$tmp_file" -y -b 700k -r 20 -f flv -vcodec flv -ab 56k -ar 22050 -s ${WIDTH}x$HEIGHT "$output_file"!); &syscall(qq!$RM "$tmp_file"!); sub parse_args { my (@args, $tmp); for ($i=0; $i<=$#ARGV; $i++) { if ($ARGV[$i] eq "-o") { $opt_o = $ARGV[++$i] } elsif ($ARGV[$i] eq "-rotate") { $opt_rotate = $ARGV[++$i] / 90; if ($opt_rotate == 1 || $opt_rotate == 3) { $tmp = $HEIGHT; $HEIGHT = $WIDTH; $WIDTH = $tmp; } } elsif ($ARGV[$i] =~ /^(-lint)$/) { $opt_lint = 1; } elsif ($ARGV[$i] =~ /^(-h|-help)$/) { &help(); } else { push(@args, $ARGV[$i]); } } return @args; } sub help { print <