Using mencoder to encode video taken with Canon SD1200 

Joined:
01/15/2009
Posts:
82

January 15, 2010 05:00:14    Last update: January 15, 2010 05:03:49
Video taken with the Canon SD1200 camera comes in the AVI format, where the video is MJPEG and the audio is PCM. For some weird reason it doesn't play on my Windows XP box! The video is sluggish and the audio is often interrupted. But it works fine on my old Windows 2000 box.

Since it's taking too much space anyway, I used mencoder to compress the video with XVID encoding and audio with MP3. This is the script.
#!/usr/bin/perl
$destdir = "C:/Documents and Settings/woolf/My Documents/My Videos";
$encodelog = "C:/tmp/mencoder.log";

$MEDIAINFO = "mediainfo"; # where is mediainfo executable?
$MENCODER = "C:/local/MPlayer-athlon-svn-29319/mencoder";

if ($#ARGV < 0) {
    print "Usage $0 <inputfile>\n";
    exit 1;
}

$srcfile = $ARGV[0];
if (not -f $srcfile) {
    print "File \"$srcfile\" does not exist\n";
    exit 1;
}

# capture the video time and store it with the new file
$pid = open(MEDIA_INFO, "-|");
$SIG{PIPE} = sub { die "whoops, pipe broke" };
if ($pid) { #parent
    while (<MEDIA_INFO>) {
	if (/Mastered date/) { # Mastered date: Sat Dec 5 12:25:42 2009
	    chomp;
	    ($recorded_date = $_) =~ s/(.*: )//;
	    last;
	}
    }
    close MEDIA_INFO or warn "Kid exited: $?";
}
else { # child
    exec($MEDIAINFO, $srcfile) or die "Can't exec mediainfo: $!";
}

$destfile = "$destdir/$srcfile";
unlink $encodelog;

# encoding pass 1
system($MENCODER,
    $srcfile,
    "-o",
    "NUL",
    "-passlogfile",
    $encodelog,
    "-oac",
    "mp3lame",
    "-lameopts",
    "abr:br=140:aq=5:vol=2.2",
    "-ovc",
    "xvid",
    "-xvidencopts",
    "pass=1");

# encoding pass 2
system($MENCODER,
    $srcfile,
    "-info",
    "comment=\"Recorded date: $recorded_date\"",
    "-o",
    $destfile,
    "-passlogfile",
    $encodelog,
    "-oac",
    "mp3lame",
    "-lameopts",
    "abr:br=140:aq=5:vol=2.2",
    "-ovc",
    "xvid",
    "-xvidencopts",
    "pass=2:bitrate=2500");


Tools used:
Share |
| Comment  | Tags