SmartLogic Logo (443) 451-3001

The SmartLogic Blog

SmartLogic is a web and mobile product development studio based in Baltimore. Contact us for help building your product or visit our website to learn more about what we do.

Using FFMPEG to Encode Video for iPod, iPhone Streaming, and Flash 9

May 21st, 2008 by

Read on to learn how to encode videos in to H264 for use by Flash 9, and also to stream to an iPhone in Safari, and be able to sync them onto an iPod.

First, you need FFMPEG compiled with H264 support. This is the thread I followed for Ubuntu:

Next, you can use this command to encode the video:

ffmpeg -y -i INPUT -vcodec libx264 -acodec libfaac -ab 128k -ac 2 -b 640k -threads 4 -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -rc_eq \’blurCplx^(1-qComp)\’ -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 OUPUT

The -vcodec and -acodec options specify the h264 encoder with aac audio. -ab is audio bitrate, if you want to change that, and -b is the video bitrate. You can also specify a size with “-s widthxheight” for instance “-s 640×480″. The -threads option gives you multithreading, I run a quad-core so I have it at 4. All the other flags are h264 options for higher quality. I don’t understand many of them, but it looks nicer with them on.

If you want, you can add “-pass 1″ to the command and run it, and it will generate a log file. Then run it again with “-pass 2″ and it will use the log file for superior variable bitrate results. I highly suggest this.

Lastly, you should pack up the file for iPhone and iPod compatibility:

AtomicParsley OUTPUT -iPod-uuid 1200 –overWrite

Where OUTPUT is the file that you generated with FFMPEG.

  • Chris J

    Hey Nick I was looking at this code and im new to this type of programming I could use some help if your up for this. gonna need to compile ffmpeg to grab live encoded streams and convert to compatible IPhone specs and stream over rtsp. you think this could be done lets talk about it!.

  • Nick Gauthier

    Hey Chris,

    It’s been a while since I’ve worked with this :-/ but I’d be glad to help. Send me an email and I’ll give it a shot. My email is my first name at


  • Joshua Montgomery

    This code didn’t work for me.

    The “-b 640″ sets the bit rate at 640 bits per second (not kilobits per second). Here is a revised string that works well:

    ffmpeg -y -i INPUT -vcodec libx264 -acodec libfaac -ab 128k -ac 2 -b 640k -threads 4 -flags +loop -cmp +chroma -partitions 0 -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -qcomp 0.6 -qmin 2 -qmax 51 -qdiff 4 -level 30 OUPUT

  • Nick Gauthier

    Thanks Joshua. I’ve updated the post.