Convert AVI into H.264 that works inside an HTML5 Video tag

ffmpegh.264video conversion

I would like to convert an existing black and white AVI into an H.264 video that works inside an HTML5 video tag.

I'm currently using this ffmpeg command:

ffmpeg -i file.avi -y -c:v libx264 file.h264

This command does not work for me. It does produce the H.264 file, but it does not play anywhere else other than VLC player.

Best Answer

.h264 is just a raw H.264 bytestream. That's just video content, which can be played back by sophisticated players, but usually you want to put everything into a container format, such as MPEG-4 Part 14 ("MP4").

So, run:

ffmpeg -i file.avi -c:v libx264 -pix_fmt yuv420p file.mp4

For HTML5 progressive download you may want to move the moov atom of the MP4 container to the beginning of the file, which allows instant playback:

ffmpeg -i file.avi -c:v libx264 -pix_fmt yuv420p -movflags faststart file.mp4

You may be interested in: What is a Codec (e.g. DivX?), and how does it differ from a File Format (e.g. MPG)?

Related Question