How to: Encode video with the H.264 codec with FFmpeg

Perhaps you have an old AVI video file that won't play on some modern applications, or would like to ensure your media can be played on the web. The H.264 codec is widely supported across all major browsers, and on both Apple and Android devices. Let's take a look.

7 months ago   •   1 min read

By Tom O'Brien
💡
If you need help installing FFmpeg on your system, check out this earlier post which will walk you through the process.

A couple of things to note for the examples below:

  • your_video_file.mp4 refers to the file name of your video, so change this appropriately.
  • Each method will create a file called output_video.mp4. You can change this file name to whatever you like.

Encode video with H.264

This command will create a new video file from your existing media using the H.264 codec.

ffmpeg -i your_video_file.mp4 -c:v libx264 output_video.mp4

Encode video with compression

This command will give you good compression without any noticeable loss in picture quality.

ffmpeg -i your_video_file.mp4 -c:v libx264 -crf 27 output_video.mp4

Encode video with high quality

This command will sacrifice compression in order to produce the best picture quality.

ffmpeg -i your_video_file.mp4 -c:v libx264 -crf 18 -preset veryslow output_video.mp4

Need some help with online video delivery, storage and processing? Get in touch with us using the button below and we'll be happy to help you out.

Spread the word

Keep reading