středa 17. září 2008

Create H.264 video for Flash 9 video players using ffmpeg

First of all I have to confess I'm no video guru. I admire people with deep look into secrets of video encoding and I have to thank everyone involved in ffmpeg/x264 library creation. But let's rock ...

New Adobe Flash Player has a great feature as it can play H.264 coded video. Why H.264? Simple answer a high quality video can be produced at amazingly low bitrates.
I wanted to publis some short videoclips and Flash player seems to be a good choice. I have tried JW Player which looks good to me for now.

As a tool for H.264 encoding I have chosen ffmpeg. As I'm lazy I have not compiled the binaries for windows platform myself. Instead I have downloaded them from ASP.NET Cafe.

And the magic is here. After some elaboration with commandline parameters this worked for me (two pass encoding):

ffmpeg.exe -i input.avi -pass 1 -acodec libfaac -f mp4 -vcodec libx264 -vb 512k -r 30  output.mp4
ffmpeg.exe -i input.avi -pass 2 -acodec libfaac -f mp4 -vcodec libx264 -vb 512k -r 30 output.mp4


It worked and played in JW Player. Just a short summary of options. MP4 container file format is used (-f mp4), which is a must for Flash9. FAAC is a codec selected for sound. It seems to me that only some codec combinations are allowed for ffmepg to work or maybe in MPEG4 spec.

And that's all folks ...

Enjoy a high quality low bitrate videos.