H.264 vs H.265 vs AV1: In-Depth Video Codec Comparison
Comprehensive comparison of three major video codecs in compression efficiency, encoding speed, browser support, and patent licensing to help you choose the best encoding solution.
Read More βMaster core video compression principles and easily achieve high-quality, small-sized videos
Video compression is possible because there is a large amount of redundant information in video data. The essence of video compression is to remove this redundancy and represent the same visual content with less data.
Spatial redundancy refers to the correlation between adjacent pixels within the same frame. For example, pixels in a blue sky are very similar and can be represented more concisely.
Spatial redundancy is mainly eliminated through intra prediction, transform coding (DCT/DST), and quantization.
Temporal redundancy refers to the correlation between adjacent frames. In most videos, content changes little between adjacent frames, and many regions are almost identical.
Temporal redundancy is mainly eliminated through inter prediction (motion estimation and motion compensation), which is the main reason video compression ratios are much higher than image compression.
Visual redundancy refers to information that the human visual system cannot perceive. The human eye is more sensitive to brightness than color, and less sensitive to high-frequency details than low-frequency content.
Visual redundancy is exploited through techniques like chroma subsampling (e.g., 4:2:0), quantization matrices, and psychovisual models.
Coding redundancy refers to using more bits to represent data than the theoretical minimum. Entropy coding (e.g., Huffman coding, arithmetic coding, CABAC) can further compress data.
In modern video coding standards (such as H.264, H.265), video is divided into different types of frames, each coded differently and playing different roles in compression efficiency and error recovery.
An I frame (Intra-coded Picture) is an intra-coded frame, also called a keyframe. It does not reference other frames and is coded independently, similar to a static image.
A P frame (Predictive-coded Picture) is a forward predictive frame that references previous I or P frames for predictive coding, only encoding the prediction error.
A B frame (Bidirectionally predictive-coded Picture) is a bidirectional predictive frame that references both previous and future frames for prediction, achieving the highest compression efficiency.
Rate control is one of the most important parameters in video compression β it determines how bits are allocated to ensure video quality. Common rate control methods include CRF, CBR, VBR, and others.
CRF (Constant Rate Factor) is a constant quality mode that aims to maintain consistent visual quality throughout the video, with bitrate dynamically changing based on video complexity.
CRF value range:
CBR (Constant Bitrate) is a constant bitrate mode where the bitrate remains unchanged throughout the video, regardless of whether the content is complex or simple.
VBR (Variable Bitrate) is a variable bitrate mode that dynamically adjusts bitrate based on video content complexity β allocating more bitrate to complex scenes and less to simple scenes.
ABR (Average Bitrate) is an average bitrate mode that allows the bitrate to fluctuate within a certain range while ensuring the average bitrate reaches the target value.
GOP (Group of Pictures) refers to a group of consecutive frames between two I frames. The GOP structure determines the interval between I frames and has important implications for video compression efficiency, random accessibility, and fault tolerance.
GOP length is the number of frames between two adjacent I frames. For example, GOP=30 means one I frame every 30 frames.
A typical GOP structure is IBBPBBPBBP..., where an I frame is followed by a combination of multiple B frames and P frames.
| Scenario | GOP Length (30fps) | Notes |
|---|---|---|
| Video storage / VOD | 60-300 frames (2-10 sec) | Pursue compression efficiency |
| Live streaming | 30-60 frames (1-2 sec) | Balance latency and efficiency |
| Video conferencing | 10-30 frames (0.3-1 sec) | Low latency, fast recovery |
| Surveillance video | 150-600 frames (5-20 sec) | Maximize compression ratio |
| Name | Resolution | Recommended Bitrate Range |
|---|---|---|
| 360p | 640Γ360 | 400-800 kbps |
| 480p | 854Γ480 | 800-1500 kbps |
| 720p | 1280Γ720 | 1500-4000 kbps |
| 1080p | 1920Γ1080 | 3000-8000 kbps |
| 4K | 3840Γ2160 | 10000-30000 kbps |
Using H.264 encoder with CRF mode, recommended for most scenarios:
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4
If you need precise control over file size, use two-pass encoding:
# First pass: analyze video
ffmpeg -i input.mp4 -c:v libx264 -b:v 1000k -pass 1 -an -f null /dev/null
# Second pass: actual encoding
ffmpeg -i input.mp4 -c:v libx264 -b:v 1000k -pass 2 -c:a aac -b:a 128k output.mp4
Windows users should replace /dev/null with NUL.
# Scale to 720p
ffmpeg -i input.mp4 -vf scale=1280:720 -c:v libx264 -crf 23 -c:a aac -b:a 128k output_720p.mp4
# Proportionally scale to width 1280
ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -crf 23 -c:a copy output.mp4
# Reduce to 24fps
ffmpeg -i input.mp4 -r 24 -c:v libx264 -crf 23 -c:a copy output_24fps.mp4
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium -c:a aac -b:a 128k output_h265.mp4
ffmpeg -i input.mp4 \
-c:v libx264 -crf 23 -preset medium \
-c:a aac -b:a 128k \
-movflags +faststart \
output_web.mp4
-movflags +faststart moves metadata to the beginning of the file, enabling progressive download for web playback.
ffmpeg -i input.mp4 \
-vf scale=720:-1 -r 25 \
-c:v libx264 -crf 28 -preset slow \
-c:a aac -b:a 96k \
output_short.mp4
ffmpeg -i input.mp4 \
-c:v libx265 -crf 22 -preset veryslow \
-c:a copy \
output_archive.mkv
ffmpeg -i input.mp4 \
-c:v libx264 -b:v 2500k -maxrate 2500k -bufsize 5000k \
-g 60 -keyint_min 60 -sc_threshold 0 \
-c:a aac -b:a 128k \
-f flv rtmp://server/live/stream
Parameter explanation:
-g 60: GOP size of 60 frames (2 seconds @ 30fps)-keyint_min 60: Minimum keyframe interval-sc_threshold 0: Disable scene change detection to ensure stable GOPThe preset parameter controls the balance between encoding speed and compression ratio. Available values:
Recommendation: Use slow when time is ample, use fast for speed, and default medium is fine for most cases.
Recommended CRF starting values:
-vf nlmeans)Video compression is an art of balance β finding the optimal point among quality, file size, encoding speed, and compatibility.
Quick start recommendations:
If you don't want to remember these complex parameters, you can use our online Video Compressor Tool to complete video compression in just a few simple steps.
More great articles and useful tools
Comprehensive comparison of three major video codecs in compression efficiency, encoding speed, browser support, and patent licensing to help you choose the best encoding solution.
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 FFmpeg installation needed, easily compress videos right in your browser
Try It Now β‘