Using VLC to Create iPod Ready Video


A few days ago I wrote about using VLC to turn MPEG2 video from the Tivo into something that will work on your iPod. I had some funny problems with the aspect ratio and the GUI-based approach is fine for a single video, but it's time consuming since each conversion takes near real-time (i.e. one our of video takes a little more than one hour to transcode to MPEG4). Well, there's a better way.

VLC has a command line interface and it works lovely. Not only can you run the command on multiple files in batch mode, but you can set the aspect ratio and width and height to ensure it plays back right on the iPod. For some reason the video from the Tivo thinks it's encoded at 352x480, even though it displays it correctly in VLC. When you transcode it to MPEG4, Quicktime uses the bad width and height.

Here's the shell script I used to transcode the Tivo MPEG2 to MPEG4 for the iPod. This should work for any MPEG2 source file--there's nothing specific to the Tivo in it.

#!/bin/bash
/Applications/VLC.app/Contents/MacOS/VLC -vvv "$1.mpg" \\
 --sout "#transcode{vcodec=mp4v,vb=1024,scale=1, \\
 acodec=mp4a,ab=128,channels=2}:standard{access=file, \\
 url=$1.mp4}" \\
 --aspect-ratio "4:3" --sout-transcode-width 360 \\
 --sout-transcode-height 240 --sout-transcode-fps 30    

This works even when the file name has spaces. The script assumes that VLC is in the /Applications directory on the Mac. If you use Linux or Windows, the flags will all be the same, just change the command name to reference the right executable. Windows users are on their own for making the shell variables work. Note: This script expects the MPEG2 file without the .mpg extension as its argument.

This will run for a while and spit out lots of debugging messages. When it's done it doesn't exit, but rather announces that it's playlist is empty. Ctrl-C quits just fine.

The resulting file can be loaded directly into iTunes (using the "Add to Library" command) and plays just fine. Now, I can download several files, use DirectShow Dump to remove the Tivo DRM (which is fast even in Virtual PC) and then transcode them for the iPod in batch while I sleep.