Convert video to iPhone/iPod Touch using ffmpeg

If you search for this topic you will find some examples of using ffmpeg to convert movies to a format that will work with the iPhone. I am a Linux user so I did not had much usage for this because there is no iTunes in linux 🙂 Until I needed to stream videos to the iPhone. Right now I’m using wowza for the actual streaming that involves creating a special playlist that will tell the iPhone how to get the file from the server. But that is another story.

So the actual ffmpeg command I’m using is:

ffmpeg -threads 2 -i INPUT_FILE -r 20  -vcodec libx264 -s 320x240 -flags +loop \
-cmp +chroma -deblockalpha 0 -deblockbeta 0 -crf 24  -bt 256k -refs 1 -coder 0 \ 
-me_range 16 -subq 5 -partitions +parti4x4+parti8x8+partp8x8 -g 250  \
-keyint_min 25 -level 30 -qmin 10 -qmax 51 -trellis 2 -sc_threshold 40 \
-i_qfactor 0.71 -acodec libfaac  -ab 128k -ar 48000 -ac 2 OUTPUT_FILE

So what does all this mean? I am no ffmpeg expert but I’ll try to give an explanation. If you can fill the gaps please post a reply.

  • -threads 2 Number of threads ffmpeg will use. This should be the number of cores in your system
  • -i INPUT_FILE The path to the file you want to convert
  • -r 20 The frame rate of the converted file. This should be the same as the input file. A lower value means a smaller file
  • -vcodec libx264 Codec of the output file. This means that output will be a H264 Mpeg4 file
  • -s 320×240 Resolution of the output. Should not exceed the input file. In any case remember that iPhone resolution is: 480×320
  • -acodec libfaac -ab 128k -ar 48000 -ac 2 Audio format. AAC audio with 128kbits bitrate, with 48000Hz sample rate and 2 channels. Lower values will give smaller files and less quality.

If you know what the others do anf how do they affect the quality/size please post.