Thursday, September 25, 2008

Converting real video to ipod compatible mp4

I was trying to convert some real video lectures I downloaded to ipod compatible format for later viewing. I looked for a program that would do the job for me. They fall mainly into two classes: ffmpeg based and mencoder based. ffmpeg is nice, except it doesn't work for some proprietary codecs (and my videos happened to use one). mencoder works for everything but has arcane options. After trying several candidates, I could not find one that worked.

Finally, I gave up and read up mencoder's manual page (which is well hidden on Windows). So here's a little script that I came up with to use with MinGW:

#!/bin/sh mencoder.exe "$1" -vfm realvid -sws 9 -oac mp3lame -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:turbo -of lavf -lavfopts format=mp4 -o "${1%.*}".mp4 -vc rv20win -ac rasiprwin

But that didn't work either. Apparently, ipod only supports a subset of the H.264 standard. After long hours of searching, I found the solution on an mplayer mailing list and modified it to work for my videos:

REM encoder_for_ipod.bat for %%i in (*.rm) do mencoder -vf harddup -of lavf -lavfopts format=ipod -af lavcresample=44100 -oac faac -faacopts mpeg=4:object=2:quality=50:raw -ovc x264 -x264encopts global_header:qp=30:threads=auto:level_idc=13:nocabac -vc rv20win -ac rasiprwin %%i -o %%~ni.mp4

Powered by ScribeFire.