CGJU
CGJU
June 28, 2026 Β· 8 min read
πŸ’‘ Key Points: Starting from the basic principles of video compression, this article explains core concepts like I/P/B frames, CRF, CBR, and GOP, and provides practical FFmpeg commands and compression templates for different scenarios.

1. Basic Principles of Video Compression

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.

1.1 Spatial Redundancy

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.

1.2 Temporal Redundancy

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.

1.3 Visual Redundancy

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.

1.4 Coding Redundancy

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.

2. I/P/B Frame Concepts Explained

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.

2.1 I Frame (Keyframe)

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.

  • Characteristics: Independently decodable, best quality, largest size
  • Purpose: Serves as random access point for video fast forward/rewind and error recovery
  • Compression ratio: Relatively low, about 1:10 ~ 1:20

2.2 P Frame (Predictive Frame)

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.

  • Characteristics: Depends on previous frames, cannot be decoded independently, smaller size
  • Purpose: Exploits temporal redundancy to greatly improve compression efficiency
  • Compression ratio: Relatively high, about 1:50 ~ 1:100

2.3 B Frame (Bidirectional Predictive Frame)

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.

  • Characteristics: Depends on previous and next frames, highest compression ratio, higher decoding latency
  • Purpose: Further improves compression efficiency, suitable for storage scenarios
  • Compression ratio: Highest, about 1:100 ~ 1:200
⚠️ Note: B frames are typically not used in live streaming scenarios because they require referencing future frames, which increases latency. I+P frame structure is recommended for real-time live streaming.

3. CRF vs CBR: Rate Control Comparison

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.

3.1 CRF (Constant Quality)

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.

  • Pros: Stable quality, no need to worry about quality degradation in complex scenes
  • Cons: File size cannot be precisely predicted
  • Use cases: Video storage, video websites, most common scenarios

CRF value range:

  • H.264: 0-51, default 23, recommended 18-28
  • H.265: 0-51, default 28, recommended 22-32
  • Lower values = higher quality, larger files

3.2 CBR (Constant Bitrate)

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.

  • Pros: Stable bitrate, predictable file size, suitable for live streaming
  • Cons: Complex scenes may have insufficient quality, simple scenes waste bitrate
  • Use cases: Live streaming, video conferencing, limited bandwidth streaming

3.3 VBR (Variable Bitrate)

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.

  • Pros: Higher overall quality, more efficient bitrate utilization
  • Cons: Larger bitrate fluctuations, not suitable for real-time streaming
  • Use cases: Video storage, local playback

3.4 ABR (Average Bitrate)

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.

  • Pros: Controllable file size, better quality than pure CBR
  • Cons: Quality not as stable as CRF
  • Use cases: Scenarios requiring file size control

4. GOP Structure Explained

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.

4.1 GOP Length

GOP length is the number of frames between two adjacent I frames. For example, GOP=30 means one I frame every 30 frames.

  • Larger GOP: Higher compression efficiency, but slower random access and larger error propagation range
  • Smaller GOP: Faster random access, better fault tolerance, but lower compression efficiency

4.2 Common GOP Structures

A typical GOP structure is IBBPBBPBBP..., where an I frame is followed by a combination of multiple B frames and P frames.

4.3 GOP Recommendations by Scenario

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

5. Resolution and Frame Rate Selection

5.1 Common Resolutions

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

5.2 Frame Rate Selection

  • 24fps: Film standard, cinematic look, suitable for movies and short videos
  • 25fps: PAL television standard, commonly used in China
  • 30fps: NTSC standard, commonly used for online video, good smoothness
  • 60fps: High frame rate, suitable for fast motion like gaming and sports

6. FFmpeg Compression Commands in Practice

6.1 Basic Compression Command (CRF Mode)

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

6.2 Target File Size Compression (Two-Pass Encoding)

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.

6.3 Adjust Resolution Compression

# 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

6.4 Adjust Frame Rate Compression

# Reduce to 24fps
ffmpeg -i input.mp4 -r 24 -c:v libx264 -crf 23 -c:a copy output_24fps.mp4

6.5 H.265 High Efficiency Compression

ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium -c:a aac -b:a 128k output_h265.mp4

7. Compression Templates for Different Scenarios

7.1 Web Publishing (Balanced Quality and Size)

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.

7.2 Short Video / Social Media (Small Size Priority)

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

7.3 Video Archiving (High Quality Storage)

ffmpeg -i input.mp4 \
  -c:v libx265 -crf 22 -preset veryslow \
  -c:a copy \
  output_archive.mkv

7.4 Live Streaming (CBR Mode)

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 GOP

8. Compression Quality Optimization Tips

8.1 Choose the Right Preset

The preset parameter controls the balance between encoding speed and compression ratio. Available values:

  • ultrafast: Fastest, lowest compression ratio
  • superfast / veryfast / faster / fast: Faster
  • medium: Default, balanced choice
  • slow / slower / veryslow: Slower, higher compression ratio

Recommendation: Use slow when time is ample, use fast for speed, and default medium is fine for most cases.

8.2 Use Appropriate CRF Values

Recommended CRF starting values:

  • H.264: CRF 23 (default), use 20 for quality, use 28 for smaller size
  • H.265: CRF 28 (default), use 25 for quality, use 32 for smaller size

8.3 Audio Optimization

  • Speech content: 64-96 kbps AAC is sufficient
  • Music content: 128-192 kbps AAC
  • High-quality music: 256-320 kbps AAC or use FLAC lossless

8.4 Other Optimizations

  • Remove unnecessary audio tracks and subtitle tracks
  • Use YUV420P pixel format (best compatibility)
  • Video denoising can improve compression efficiency (-vf nlmeans)

Summary

Video compression is an art of balance β€” finding the optimal point among quality, file size, encoding speed, and compatibility.

Quick start recommendations:

  • Beginners: Just use CRF 23 + medium preset
  • Want smaller size: Increase CRF value (e.g., 26-28)
  • Want better quality: Decrease CRF value (e.g., 20)
  • Plenty of time: Use slow preset for better compression ratio
  • Advanced users: Adjust resolution, frame rate, GOP, and other parameters based on specific scenarios

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.

Related Recommendations

More great articles and useful tools

Want to compress videos quickly?

Use our online Video Compressor Tool β€” no FFmpeg installation needed, easily compress videos right in your browser

Try It Now ➑