Ripping DVD’s for iPod (and Touch) using MEncoder

It’s pretty simple, really. Just use the right video/audio options and you’re both iPod- and iPod Touch-compatible:


if [[ "$2" == "" ]]; then
	echo "Usage: $0 <inputfile> <outputname>"
	echo "(<outputname> does not need an extension!)"
	exit 1

mencoder $1 -sws 9 -of lavf -lavfopts format=mp4 \
-vf scale=-2:320,dsize=576:320:0,harddup \
-ovc x264 \
-x264encopts bitrate=1381:vbv_maxrate=1500:vbv_bufsize=2000:nocabac:me=umh:trellis=1:level_idc=30:global_header:threads=2:pass=1:turbo \
-oac faac \
-alang en \
-faacopts mpeg=4:object=2:br=160:raw -channels 2 -srate 48000 -o $2.tmp.mp4

if [[ "$?" != "0" ]]; then exit "$EXIT_CODE"; fi

mencoder $1 -sws 9 -of lavf -lavfopts format=mp4 \
-vf scale=-2:320,dsize=576:320:0,harddup \
-ovc x264 \
-x264encopts bitrate=1381:vbv_maxrate=1500:vbv_bufsize=2000:nocabac:me=umh:subq=6:frameref=6:trellis=1:level_idc=30:global_header:threads=2:pass=2 \
-oac faac \
-alang en \
-faacopts mpeg=4:object=2:br=160:raw -channels 2 -srate 48000 -o $2.tmp.mp4

if [[ "$?" != "0" ]]; then exit "$EXIT_CODE"; fi

echo "ATTENTION: Movie is done but iTunes won't recognize it!"
echo "Use NicMP4Box to create an iTunes-compatible movie file!"
# nicmp4box -add $2.tmp.mp4 $2.mp4

I modified this with a 4:3 aspect ratio in mind, but it should scale to 16:4 aspect ratio automatically when given such a DVD. I have yet to test that.

Note the ending lines there. That’s the catch. If you are using Linux, and Linux software to transfer your movies to your iPod, you’re good to go as it is. On the other hand, if you use iTunes, you’ve got a problem. Apparently iTunes refuses to recognize the movies you give it unless “the ‘itunes’ atom is set to the correct value. You can add the atom to the file with nicMP4Box ( ) “. Update: Read the comments for information on how to bypass the nicmp4box requirement in Linux.

Thanks to the folks at the MEncoder usage discussions for the answer!

Post a comment or leave a trackback: Trackback URL.


  • Daniel  On November 10, 2008 at 11:50 pm

    It blows up complaining second pass has more frames thant first, what would this look like doing it in a single pass?



  • Jacob  On November 13, 2008 at 10:29 am

    That’s going to be a mencoder issue. I recommend you get support at the proper mplayer/mencoder support areas:

  • None  On December 21, 2008 at 1:11 pm

    Thank you for your script.

    I’m a bit of a n00b when it comes to video transcoding. I’m wondering why there is a need to do two passes? Can you not do it in a single pass, as I do for DVDs to the Sony PSP? And if you can what are the advantages/disadvantages.

    • Jacob  On December 21, 2008 at 1:33 pm

      Two passes is a lot better than a single pass. The first pass allows the encoder to take a look at what your video is like, and get an idea of how it wants to fine tune everything on the second pass. During the second pass it does the actual re-encoding.

      A single pass is more rough. The encoder will not have a chance to slim down the video’s size and efficiency. However, it completes a lot faster.

  • None  On December 22, 2008 at 9:15 am

    Thanks for the tips and please allow me to offer one to you.

    While this script and Mencoder worked OK, it took nearly 4 hours to do one DVD that resulted in a 1.2GB MP4 file that MP4Box errors out on.

    I later found out that Handbrake, the preferred OS X transcoder, is now also available for Linux and includes a GUI.

    Handbrake transcoded the same DVD in a little under an hour and the resulting MP4 was just 450MB. The GUI made option selection very easy but, it also included presets for many devices including the iPod Touch.

    Now to be fair, the Handbrake preset for the iPod Touch used a much lower bitrate than your script, ~700. But, I was unable to distinguish a significant difference in picture quality between the two MP4s on a 17″ screen, let alone the 3″ screen of the iPod. I did note that the Mencoder MP4 had a thin artifact stripe down the right edge of the screen. It was not intrusive enough to be objectionable but, it was noticeable and the Handbrake version did not have the stripe.

    I hope this helps you or someone else. Thanks again for your help.

  • Borden  On December 23, 2008 at 6:04 pm

    Newer versions of MEncoder have a format=iPod option in -lavfdopts which people say fixes the iTunes atom problem.

  • gprime  On January 20, 2009 at 4:24 pm

    Are you using windows for this script. It seems to be a batch file. I was asking because you are using nicmp4box. Where you able to get a linux binary?

    Please let me know, i have an encoding script that requires this for my streaming videos of my website. For some reason my flash player(playing mp4’s) needs this to stream properly.


    • Jacob  On January 22, 2009 at 2:21 pm

      nicmp4box is no longer required. Read the above comments for more information.

  • Lee Bigelow  On February 7, 2009 at 11:33 am

    I made a bash shell script for mencoder that works very well for me.
    No nicmp4box needed and you can choose between lavc or h264 encodings.

  • Ken  On December 20, 2009 at 11:21 am

    I use transcode and ffmpeg to rip and transcode on linux with a bash script.

    audio=0 # audio track; usually 0 for english
    device=/dev/dvd # input device (could be anything)
    name=myMovie # name of the output

    function getchapters {
    tcprobe -i /dev/dvd -T 1 -H 10 2>&1 | egrep “\[Chapter ..\] ” | cut -d ” ” –
    f 3 | perl -pi -e ‘s/\n/ /’ | perl -pi -e ‘s/,$//’ | perl -pi -e ‘s/\]//g’

    echo “Reading chapters…”
    getchapters $title $device > $name.chapters
    list=`cat $name.chapters`
    for chapter in $list
    echo doing $chapter
    rm -f *.fifo
    mkfifo vid.fifo
    mkfifo aud.fifo
    echo -n “Video…”
    tcextract -i vid.fifo -t vob -x mpeg2 > tmp.m2v &
    echo “Audio…”
    tcextract -i aud.fifo -t vob -x ac3 -a $audio > tmp.ac3 &
    time tccat -i $device -T $title,$chapter | tee aud.fifo vid.fifo > /dev/null
    ffmpeg -y -i tmp.m2v -i tmp.ac3 -f mov -s 320×240 -qscale 3 -ab 128000 -threads
    4 $name.$

  • Zaph  On July 6, 2011 at 3:57 pm

    Thanks for your help !

    Your script did not work for the Ipod Classic that I wanted to copy the video to. After some googling I was able to adapt your script to do this. Also the nicmp4box call can be replaced by an MPB4Box call from the gpac packet that should be available in most linux distributions.

    Enjoy + Thanks a lot !


  • By DVD Transcoding With HandBrake « Net Codger on January 13, 2009 at 8:51 am

    […] a script or command line recipe for the iPod Touch transcoding job at hand. I finally settled upon this script at the My Humble Corner blog. The script was straightforward enough for me to read and understand […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: