Complete Guide to Video Compression: From Principles to FFmpeg Practice
In-depth analysis of video compression principles, I/P/B frames in H.264/H.265, CRF, bitrate, GOP structure, and practical FFmpeg compression commands.
Read More βComprehensive comparison of three major video codecs to help you choose the best encoding solution
H.264, also known as AVC (Advanced Video Coding), was jointly developed by MPEG and VCEG and officially released in 2003. It is currently the most widely used video coding standard, with native support in almost all devices and browsers.
H.264 uses technologies such as intra prediction, inter prediction, transform coding, and entropy coding, saving about 50% bitrate compared to the previous generation MPEG-2 while maintaining the same visual quality.
H.265, also known as HEVC (High Efficiency Video Coding), is the successor to H.264, released in 2013. It introduces more advanced technologies on top of H.264, such as larger coding tree units (CTU), more flexible prediction modes, and SAO filtering.
At the same quality level, H.265 saves about 50% more bitrate than H.264, meaning higher-definition video can be transmitted with the same bandwidth.
AV1 (AOMedia Video 1) is an open-source, royalty-free video coding standard developed by the Alliance for Open Media (AOMedia), officially released in 2018. Companies involved in development include Google, Mozilla, Netflix, Amazon, Microsoft, and others.
AV1 aims to save about 30% more bitrate than H.265 at the same quality level, and it's completely free with no patent licensing issues.
Compression efficiency is one of the most important metrics for video codecs. Below is a comparison of relative bitrates among the three at the same visual quality (similar PSNR):
| Codec | Relative Bitrate | Savings (vs H.264) |
|---|---|---|
| H.264 | 100% | Baseline |
| H.265 | ~50% | ~50% |
| AV1 | ~35% | ~65% |
As the data shows, AV1 has the highest compression efficiency, followed by H.265, with H.264 being the lowest. Note that actual compression efficiency varies depending on video content, encoding parameters, quality assessment methods, and other factors.
Encoding speed is another important factor to consider when choosing a codec. Generally speaking, the higher the compression efficiency, the slower the encoding speed.
| Codec | Relative Speed | Real-Time Encoding |
|---|---|---|
| H.264 (x264) | Fast (baseline) | β Easily supported |
| H.265 (x265) | Medium (~0.3-0.5x) | β³ Requires high-end config |
| AV1 (libaom) | Slow (~0.05-0.1x) | β Currently difficult |
H.264 patents are managed by MPEG LA and require royalty payments. For free internet video services, H.264 is royalty-free; however, for paid content and hardware devices, licensing fees apply.
The patent situation for H.265 is complex, with multiple patent pools (MPEG LA, HEVC Advance, Velos Media), high licensing fees, and some patent holders not joining any pool. This is one of the main reasons H.265 has been slow to adopt in browsers.
AV1 is completely open-source and royalty-free, with the AOMedia alliance pledging that its members will not assert their patents against AV1 users. This is a huge advantage for commercial applications.
Using libx264 encoder, CRF mode (recommended):
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output_h264.mp4
Parameter explanation:
-crf 23: Constant Rate Factor, range 0-51, default 23, lower values = higher quality-preset medium: Encoding speed preset, options from ultrafast to veryslowUsing libx265 encoder:
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium -c:a aac -b:a 128k output_h265.mp4
The default CRF value for H.265 is 28, which provides roughly the same visual quality as H.264 at CRF 23.
Using libaom-av1 encoder (slower):
ffmpeg -i input.mp4 -c:v libaom-av1 -crf 30 -b:v 0 -cpu-used 4 -c:a libopus -b:a 128k output_av1.mkv
Parameter explanation:
-cpu-used 4: Encoding speed control, 0 = slowest best quality, 8 = fastest worst quality-b:v 0: Used with CRF, indicates no bitrate limitUsing SVT-AV1 encoder (faster, recommended):
ffmpeg -i input.mp4 -c:v libsvtav1 -crf 30 -preset 4 -c:a libopus -b:a 128k output_av1.mp4
Choosing a video codec requires considering multiple factors such as compression efficiency, encoding speed, compatibility, and patent licensing.
Recommended strategy:
If you don't want to remember these complex commands, you can use our Video Compressor Tool to easily complete video encoding conversions right in your browser.
More great articles and useful tools
In-depth analysis of video compression principles, I/P/B frames in H.264/H.265, CRF, bitrate, GOP structure, and practical FFmpeg compression commands.
Read More βComprehensive comparison of RTMP, SRT, and WebRTC live streaming protocols, OBS setup tutorial, Nginx-RTMP server deployment, and FFmpeg command-line streaming methods.
Read More βDetailed explanation of mainstream audio format characteristics, bitrate selection, use cases, and practical FFmpeg audio conversion commands.
Read More βUse our online Video Compressor Tool β no software installation needed, complete H.264/H.265 encoding conversion right in your browser
Try It Now β‘