Converting Video for the iPhone with Linux

There are a few obstacles using the iPhone when it comes to Linux. Hopefully there will be workarounds for getting files onto an iPhone or iPod touch (version 2 or 3) using Linux. At this time, I haven't found a solution that puts data directly onto the iPod music/video sync area (unless you jailbreak it)

However, there is good news! A sweet application called Air Sharing from Avatron makes it possible to put files from almost any computer, including Linux.

Converters

There are a few converters on Linux and I'm sure there are ways to get them to work. For my purposes, I wanted to find a way that works. I have had good experiences with using ffmpeg and gstreamer in the past. It appears that both are being actively developed and improved, so using one of them would make sense. I started with gstreamer and couldn't figure out a nice script that would do the trick so I tried ffmpeg. It worked well and was relatively simple to use. All smiles from me.

The problem for me is that I have a Samsung camera that produces DivX video. This, of course, doesn't play directly on the iPhone or iPod touch. To convert the files to play, they have to be in Quicktime format using H264 and mp3 or aac audio.

So, with Fedora, you will need to install a couple of packages:
1) ffmpeg (video decoder/encoder)
2) x264 (video encoding)
3) lame (mp3 encoding
4) flac (aac encoder/decoder)

yum install ffmpeg x264 lame flac

Video Conversion

so to the command:
ffmpeg is the video command
-i specifies the input file to be converted, in this case "my_original_video.avi"
-f specifies the format to convert to, and in this case mov which is the quicktime format
-b specifies the bitrate to convert to, and in this case, I use 1800... there is a maximum and minimum that is acceptable for the iPod and iPhone. You can experiment with this, but I found this to be OK.
-maxrate specifies the maximum bit rate, which is set here to 2500.
-vcodec specifes the video encoding format for the quicktime container (.mov). For the iPhone and iPod, libxvid is required.
-qmin and -qmax indicates the quality of the encoding. I put a range between 3 and 5. Play with these to find something good enough for you. I found qmin of 1 to be too poor for my taste.
-ab specifies the audio bitrate, whic I set to be 128. It's really very good audio at 128, and the iPhone and iPod are fussy.

ffmpeg -i my_original_video.avi -f mov -b 1800 -maxrate 2500 -vcodec libxvid -qmin 3 -qmax 5 -ab 128 my_ipod_video.mov

Occasionally, there are a couple of other settings that can help make a conversion successful when the video is not very good.
-aspect specifies the aspect ratio of the video. A value of 1.333 is 4:3 or standard TV and a value of 1.777 is HD wide-screen. The iPod screen is in-between these, so picking one might help the conversion, but the video might be a bit squished or stretched. I haven't spent time getting that sorted out yet.
-s specifies the screen dimensions output. A value of 480x320 is the size of the screen on the iPhone and iPod. If you are converting something that has a higher resolution to be played on this device only, you might as well resize the output screen as it could save loads of memory - which is a premium on the iPhone (8GB fills up quickly).

script

I wrote a bash script to make conversion a little less trouble since I do it so infrequently - name it iconvert.sh for example

#!/bin/bash
echo usage -> iconvert.sh movie-in.avi movie-out.mov 
echo extra parameters follow like -s 480x320 or -aspect 1.333
echo $1 $2 $3 $4 $5 $6
ffmpeg -i "$1" -f mov -b 1800 -maxrate 2500 -vcodec libxvid -s 480x320 $3 $4 $5 $6 -qmin 3 -qmax 5 -ab 128 "$2"

Mac Software

ffmpegX is a front end and contains?!? the equivalent to what is on Linux. Get it here:
http://www.ffmpegx.com

Always be careful when downloading software from unknown sites. There is little reason for this to have an installer on a Mac. Copying this to your Applications should be sufficient...

Windows Software

Avanti is a front end and provides and install of ffmpeg too. Get it here:
http://avanti.arrozcru.com/

Always be careful when downloading software from unknown sites. I always advise checking the software with an antivirus program before and after installation.