Content Cleanup Required
This article should be cleaned-up to follow the content standards in the Wiki Guide. More info...

Encoding Video for the iPod Video

This is a guide for encoding video to a format acceptable by the 5th generation iPods, aka the iPod Video (The format is also compatible with 6th generation iPods, iPhones, Apple TV's, and the QuickTime player / iTunes. The following methods have been tested successfully on Ubuntu Breezy through Gutsy. They require adding new repositories (Feisty and higher) or rebuilding your system's ffmpeg (before Feisty), so be warned that the modifications to your system from this guide won't be officially supported by Canonical.

If you need more information, make sure to check out the iPod Video wiki page, as well as the Guide to Transferring Video to the iPod Video.

As for encoding, you will have to recompile ffmpeg so that it has the correct configuration in order to encode videos in the format required by the iPod Video. This guide walks you through compiling and installing ffmpeg correctly, as well as encoding video correctly using ffmpeg.

However, you could also just choose to use a tool which will do all of this automatically for you. And here's how!

Arista (frontend to Gstreamer)

Arista Transcoder is an easy to install and easy to use frontend to Gstreamer and comes with iPod presets. It is available in the default Ubuntu repositories. It is bafflingly simple and worked out of the box on my Lucid system: using gtkpod, the resulting *.m4v was imported to the iPod and played just fine.

mvPod (frontend to mencoder)

There is a new solution available to convert easily any video to iPod compatible. This new solution, mvPod, use the popular mencoder to convert and display all information. mvPod want to be a reference to easily encode video.

Here the feature list of mvPod.

  • Easy selection of input video and output file.
  • Easy selection of Encoding options with pre-define profiles.
    • iPod H264
    • iPod Xvid
  • Selection of audio stream when encoding DVD or video files
  • Provide detail informations about the input videos
  • Preview of video
  • Manage multiple video files (Batch process)
  • Encode DVD video direclty
  • Selection of the video resolution (640x480, 320x240)
  • Possibility to change the video & audio bitrate

mvPod Official web site (http://sourceforge.net/projects/mvpod/)

To run this program, you will need the gpac libraries:

sudo aptitude install gpac

Mark Pilgrim's script (frontend to mencoder)

This script does not use ffmpeg (like the others) and allows you to bypass the hassles of the other methods that require you to add new repositories or even rebuild ffmpeg. mencoder also does better with WMV, Real Video, and other very proprietary formats by allowing you to take advantage of w32codecs. Like pypodconv below, it also uses the high-quality H.264 video codec.

sudo aptitude install lsdvd mplayer gpac zenity mencoder
sudo wget http://diveintomark.org/public/2007/06/podencoder.txt -O /usr/local/bin/podencoder
sudo chmod +x /usr/local/bin/podencoder
podencoder foo.mpg
podencoder foo.avi
podencoder foo.wmv
podencoder --help

Fixing ffmpeg on Ubuntu

See FFMpeg page for details.

Script 1: pypodconv Script

This is a newer (03/2007) Python script that encapsulates all the below functionality into a script. It requires ffmpeg AND gpac to work. And due to the number of people who apparently glanced over that, here it is again: You need gpac from multiverse for the script to function. (If you forget to install that, the encoding will fail at the very end, nullifying your hours of encoding work). Here's a "screenshot":

jdong@severance:~/src/pypodconv$ pypodconv
Usage: pypodconv [options]

  -h, --help            show this help message and exit
  -i INPUT, --input=INPUT
                        Source file to encode
  --sd, --320, --standard-definition
                        Encode to Standard Definition (that is, 320xNNN,
                        native iPod screen resolution) [DEFAULT]
  --hd, --640, --high-definition
                        Encode to High Definition (that is, 640xNNN, maximum
                        iPod-supported resolution
  -c CODEC, --codec=CODEC
                        Video Codec: h264 [DEFAULT], xvid, or mpeg4.
  -o OUTPUT, --output=OUTPUT
                        Output file, with file extension.
  -b VBITRATE, --vbitrate=VBITRATE
                        Video Bitrate, in kbit/s. (default: 200)
  -p PASSES, --passes=PASSES
                        Number of passes. (Default: 2)

To install, download pypodconv and save it to /tmp. Then, run:

sudo apt-get install gpac
sudo mv /tmp/pypodconv /usr/local/bin/pypodconv
sudo chmod +x /usr/local/bin/pypodconv

For Gutsy and SVN ffmpeg, use this pypodconv.

The basic operation is:

pypodconv -i INPUT_FILE -o OUTPUT_FILE

This by default creates a 200kbit/s 320xNNN 2-pass H.264 video, suitable for iPod viewing. The help printout is useful for figuring out the other methods of usage. For example, if I want to make 500kbit high-definition encodes, I'd do:

pypodconv -i INPUT_FILE -o OUTPUT_FILE --hd -b 500

Support: For now, I will handle support personally through my e-mail: jdong <at> ubuntu (dot) com. If demand rises then I will make a formal Launchpad product.

Script 2: ipodvidenc Script

Finally, to encode the videos you can create a script for converting your videos to iPod Video format.


This should pop up a blank document. Now, just copy and paste this code into it:

## ipodvidenc - The iPod Video Encoder for Linux.
## Created by Eric Hewitt, January 9, 2006.
## Released under the GPL.  Go nuts.


echo "What would you like to name the output file (sans extension)?"

read output_file_name

echo "$output_file_name will be located in $PWD. Is this acceptable? [y/n]"

read output_file_loc_permis

if [ $output_file_loc_permis = 'n' ] || [ $output_file_loc_permis = 'N' ]
        echo "Where would you like to store $output_file_name.mov?"
        read output_dir

ffmpeg -i ${input_file} -f mp4 -vcodec mpeg4 -maxrate 1000k -b 700k -qmin 3 -qmax 5 -bufsize 4096k -g 300 -acodec aac -ab 192k -s 320x240 -aspect 4:3 ${output_dir}/${output_file_name}.mov

Save as ipodvidenc in your present working directory (it will be moved, anyway). Back in the terminal, run:

chmod 755 ipodvidenc
sudo mv ipodvidenc /usr/bin

Now, when you want to encode a video to iPod format, run this command:

ipodvidenc video.avi

It will run you through a few prompts and then encode the video and put it into the correct format.

As of January 15th, 2006, using this method will work with raw .vob files, meaning that you no longer have to transcode your DVDs! If you followed this guide before Januray 15th, 2006, you can get .vob encoding support by doing the following:

sudo apt-get install liba52-0.7.4 liba52-0.7.4-dev

Edit the debian/rules file in the ffmpeg source folder to include:

confflags += --enable-a52

Then reconfigure, remake, and reinstall.

Using ffmpeg

If you would like to have more control than ipodvidenc or thinliquid film gives, and just use an ffmpeg command, and perhaps set it as an alias, the command is as follows:

ffmpeg -i input_file.avi -f mp4 -vcodec mpeg4 -maxrate 1000k -b 700k -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec libfaac -ab 192k -s 320x240 -aspect 4:3 output_file.mov

This encodes a 700kbit MPEG-4 ASP (i.e. "xvid") format video using ffmpeg's mpeg4 encoder. Alternatively, you may use the xvid codec, which squeezes a bit more quality for the same bitrate than the above command, though it is slightly slower. Simply replace "mpeg4" with "xvid". Since Firmware 1.2 and higher, you can bump -maxrate and/or -b to 2500, and resolution (-s) to 640x480. Note that you will need to bump up the bitrate to at least 1000kbit if you want a good-looking 640x480 mpeg4-ASP video.

HandBrake (frontend to ffmpeg)

HandBrake comes with iPod presets and can be easily installed using two ppa repositories. The first provides the stable version of the programme (https://launchpad.net/~handbrake-ubuntu/+archive/ppa/+packages).

In case you have issues with the stable version (which I had on my Lucid system), the second repo provides frequent snapshot builds of HandBrake SVN (https://edge.launchpad.net/~stebbins/+archive/handbrake-snapshots/+packages).

thinliquidfilm (frontend to ffmpeg)

If you would prefer to use a gui to encode video, then you can use thinliquidfilm. thinliquidfilm is a gui frontend for ffmpeg, specifically designed to encode ipod compatible videos. You can find it here. It requires ffmpeg (compiled as set out above) and pyqt (which is installed as part of the kubuntu-desktop package). There are other non-essential dependencies for uploading to an ipod (see the Guide to Transferring Video to the iPod Video for more details) and mplayer is required to preview encoded videos before encoding).

thinliquidfilm will:

  • Batch process any number of files;
  • Display detailed information about source video files;
  • Change output settings for one or many files;
  • Save default settings for future sessions;
  • Configure output quality settings;
  • Choose between mpeg4 and h264 as output codec;
  • Choose between 320 and 640 output video width, while maintaining aspect ratio;
  • Choose between 1 or 2 pass encoding;
  • Preview encoded videos before encoding;
  • Progress bar to show encoding progress;
  • Uses ffmpeg as the encoding engine;
  • Upload encoded files to your ipod directly;
  • Set file information for upload to your ipod;
  • Add files to existing or new video playlists on your ipod;
  • Add pre-encoded videos to the transfer list;
  • Add files for encoding via the included servicemenu.

Installation is very simple with the included installation script. The website has comprehensive documentation on installing and using thinliquidfilm, and therefore there is no point in repeating it here. Unfortunately the installation script makes hard assumptions on the availability of KDE and may fail if you don't have it installed.

H.264 Encoding

H.264 (MPEG-4 AVC) is a newer codec that the iPod supports. It's able to deliver similar quality at half the bitrate of MPEG-4 ASP! However, it is an extremely slow and CPU-intensive encoder. Expect the encode to take 5x longer than mpeg4 or xvid. You also need ffmpeg compiled with x264 support. As of 20-Dec-2006 this guide has been updated to reflect that, but if you rebuilt your ffmpeg before then, you need to follow the "fixing ffmpeg" procedure again for x264 support.

Due to this enormous speed tradeoff, it's most practical to use H.264 for encoding high-resolution 640x480 video suitable for outputting to a TV (or also for viewing on your computer). Here's the ffmpeg command for doing a 500kbit 640x480 H.264 encode:

ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec h264 -b 500 -bt 175 -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -max_b_frames 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -max_qdiff 4 -i_quant_factor 0.71428572 -rc_max_rate 768 -rc_buffer_size 244 -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null

ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec h264 -b 500 -bt 175 -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -max_b_frames 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -max_qdiff 4 -i_quant_factor 0.71428572 -rc_max_rate 768 -rc_buffer_size 244 -cmp 1 -s 640x480 -acodec aac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4

Due to the iPod's limited feature support for H.264, the command for doing the encode is that much more complex. You can also adjust the bitrate controls (-b is average bitrate, -rc_max_rate is the max instantaneous bitrate spike allowed). The iPod supports up to 1500kbit. Note that this is a 2-pass encode. Doing two passes allows for more accurate bitrate control and substantially better quality, but the encode will take twice as long as a one-pass. The resulting mp4 looks great on the iPod, on the TV, and even on a 1280x800 laptop screen.

You can also use H.264 to do 320x240 encodes if you are not interested in the ability to output the mp4 on your TV or your computer. Simply replace 640x480 with 320x240. You can also reduce the average bitrate (-b) to 175, and it still looks flawless. Quality is still "bearable" even down to around 130kbit. Try doing that with xvid!

Note that as of December 2006, the SVN version of ffmpeg has renamed several options and some options now use bits/s instead of kilobits. The following command is the same as above except modified to work with the new SVN version:

ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec libx264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null

ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec libx264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -acodec libfaac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4

Another note. As of October, 2007 (or before), the syntax has changed slightly. The names of the codecs are now more generic (h264 vs. libx264, aac vs. libfaac):

ffmpeg -y -i input_file.avi -an -v 1 -threads auto -vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 1 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -f mp4 -pass 1 /dev/null

ffmpeg -y -i input_file.avi -v 1 -threads auto -vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -acodec aac -ab 96 -ar 48000 -ac 2 -f mp4 -pass 2 output_file.mp4

Encoding from a DVD source

As mentioned, ffmpeg is able to take .VOB files from the video_ts directory of a dvd as a source. However, VOBs are usually split arbitrarily into 1GB pieces, sometimes even two titles are mixed together in one VOB, making it very inconvenient to use this method of encoding.

However, our good friend mplayer will come to the rescue. By instructing mplayer to play a particular title, you can dump the complete vob for that title directly to the hard disk. You will need mplayer installed (also from Multiverse)

mplayer dvd://1 -dumpstream -dumpfile dump.vob

This will output the first title of your DVD to dump.vob, which you can then give to ffmpeg as the input. Note that mplayer doesn't generate any progress indication and will appear to 'hang' during this process. Please be patient! If you are familiar with mplayer, you can fine-tune that command to dump a particular chapter, range of chapters, or many other modifications, too.

An alternate method is to do an ordinary DVD rip to an AVI or other format using your favorite DVD ripping tool, then feed that output to ffmpeg. The benefit to this approach is that there are many nice DVD-ripping GUI's to choose title/chapters, audio streams, cropping, and so on. The downsides are that you will suffer a slightly degraded quality and you have to wait for the dvd to rip to AVI format before being able to use ffmpeg to convert it to MP4.

Widescreen Resolutions

Your iPod supports a maximum of 640x480 or 320x240, but anything in that's below those specs would work. For widescreen, just adjust that ratio so that the width <= 640 and height <= 480. It's advisable to keep both dimensions a multiple of 16, else the encoder will not compress as efficiently.

Black Screen or iPod Resets When Trying to Play Video

The mp4's that ffmpeg generates are slightly nonstandard. Firmware 1.1 iPods had severe issues playing them back, typically marked by audio suddenly disappearing 15 seconds into the video. Firmware 1.2 fixes these issues, so for the large part ffmpeg's mp4's work perfectly on the iPod. However, on short clips encoded in h.264, the iPod still may show a black screen, freeze, or reset when trying to play it.

The pypodconv script already performs this workaround listed below. If you are using the pypodconv script, you should not encounter this issue

The solution is to use MP4Box to repack the mp4. You will need gpac installed from Multiverse:

MP4Box -add original.mp4 fixed.mp4

This repacks original.mp4 into fixed.mp4. After this is done, you may remove original.mp4. You may have seen some guides suggesting to -add original directly to original, and that'll pack it "in place". This is WRONG. It will just give you a double-sized mp4 file that still won't play on the iPod!

Since for larger video files, the repacking procedure could be quite time consuming, it's a good practice not to do it except for the rare portion of files that fail without repacking.

iTunes complains about these files, but GtkPod transfers them and the iPod plays fine

2007-11-20: There is now a fix for this issue. Upgrade to the latest gpac in Hardy (0.4.4) or soon to be in Gutsy Backports, then download the newest pypodconv.ffmpegsvn branch linked in the instructions. This allows MP4Box to output the iPod MP4 header.

This phenomenon mostly happens with the 640x480 H.264 encodes. iTunes expects to find a QuickTime-specific MP4 header and rejects the results from any other encoder. However, when the MP4's are transferred onto the iPod with another program (i.e. GtkPod), the iPod plays them back without a hitch.

This is a known issue, and there's been some patches and discussion over at the ffmpeg mailing list. If you're interested in learning more about this, see: http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2006-September/045391.html

MythTV Recordings

You can export your MythTV recordings to h.264 or mpeg4 compatable video files using MythExport.

iPodVideoEncoding (last edited 2011-04-19 13:01:12 by teeks99)