Video Compression Basics
Understanding the fundamentals of video compression. Learn how algorithms work to reduce file sizes while maintaining quality.
What is Video Compression?
**Video compression** is the process of reducing the file size of a video by removing redundant or unnecessary data while trying to maintain visual quality. This is essential because uncompressed video files are enormous and impractical for storage or transmission.
Raw Video Reality
- • 1080p @ 30fps = ~3GB per minute
- • 4K @ 30fps = ~12GB per minute
- • Impossible to stream or share easily
- • Requires massive storage capacity
Compressed Video Benefits
- • 1080p @ 30fps = ~50MB per minute
- • 90-95% size reduction possible
- • Suitable for streaming and sharing
- • Maintains acceptable visual quality
How Video Compression Works
Types of Compression
🔄 Lossless Compression
- • **Perfect quality:** No data loss
- • **Moderate compression:** ~50% size reduction
- • **Use cases:** Professional editing, archival
- • **Examples:** FFV1, ProRes, DNxHD
📉 Lossy Compression
- • **Quality trade-off:** Some data permanently lost
- • **High compression:** 80-95% size reduction
- • **Use cases:** Streaming, web, social media
- • **Examples:** H.264, H.265, VP9, AV1
Compression Techniques
🖼️ Spatial Compression (Intraframe)
Reduces redundancy within individual frames, similar to JPEG compression for images.
- • Removes high-frequency details less visible to human eye
- • Uses mathematical transforms (DCT - Discrete Cosine Transform)
- • Quantizes color and brightness information
- • Each frame compressed independently
⏱️ Temporal Compression (Interframe)
Exploits similarities between consecutive frames to achieve higher compression.
- • **I-frames:** Complete frames (keyframes)
- • **P-frames:** Predicted frames (reference previous frames)
- • **B-frames:** Bidirectional frames (reference past and future)
- • Motion vectors track object movement between frames
Understanding Video Codecs
A **codec** (coder-decoder) is the algorithm that performs the compression and decompression. The choice of codec significantly impacts file size, quality, and compatibility.
Popular Video Codecs Comparison
Codec | Compression | Quality | Compatibility | Best For |
---|---|---|---|---|
H.264/AVC | Good | Very Good | Excellent | General purpose, streaming |
H.265/HEVC | Excellent | Excellent | Good | 4K content, modern devices |
VP9 | Very Good | Very Good | Good | YouTube, web streaming |
AV1 | Excellent | Excellent | Limited | Future-proofing, Netflix |
Key Compression Parameters
Bitrate (Most Important)
**Bitrate** determines how much data is used per second of video. Higher bitrate = better quality but larger file size.
Bitrate Types
- • **CBR (Constant):** Fixed bitrate throughout
- • **VBR (Variable):** Adjusts based on content complexity
- • **ABR (Average):** Targets average bitrate
Typical Bitrates
- • **4K:** 35-45 Mbps
- • **1080p:** 8-12 Mbps
- • **720p:** 5-8 Mbps
- • **480p:** 2.5-4 Mbps
Quality Settings (CRF/QP)
**CRF (Constant Rate Factor)** provides better quality control than bitrate by maintaining consistent perceived quality.
High Quality
- • CRF 17-20
- • Professional use
- • Large file sizes
- • Minimal quality loss
Balanced
- • CRF 21-25
- • General purpose
- • Good quality/size ratio
- • Most common choice
High Compression
- • CRF 26-32
- • Small file sizes
- • Visible quality loss
- • Web/mobile optimized
Resolution and Frame Rate Impact
Resolution Effects
- • **4K (2160p):** 4x the pixels of 1080p
- • **1080p:** Sweet spot for most content
- • **720p:** 50% reduction in file size vs 1080p
- • **480p:** 75% reduction, mobile-friendly
Frame Rate Considerations
- • **60fps:** Smooth motion, ~40% larger files
- • **30fps:** Standard for most content
- • **24fps:** Cinematic look, smaller files
- • **15fps:** Significant compression, choppy motion
Advanced Compression Concepts
GOP Structure (Group of Pictures)
GOP defines the pattern of I, P, and B frames, affecting compression efficiency and seek performance.
- • **GOP Size:** Number of frames between I-frames (keyframes)
- • **Shorter GOP:** Better seek performance, larger files
- • **Longer GOP:** Better compression, harder to seek
- • **Typical:** GOP of 60-120 frames for streaming
B-Frame Configuration
B-frames provide the best compression but require more processing power and introduce encoding delay.
- • **No B-frames:** Fastest encoding, larger files
- • **2-3 B-frames:** Good balance of compression and speed
- • **4+ B-frames:** Maximum compression, slower encoding
Psychovisual Optimization
Human Visual System Considerations
Modern codecs use psychovisual models to optimize compression based on how humans perceive video:
What We Notice Less
- • High frequency details in motion
- • Color differences in dark areas
- • Slight blurring in background areas
- • Compression artifacts in complex textures
What We Notice More
- • Blocking artifacts in smooth areas
- • Facial detail degradation
- • Text and graphics quality
- • Color banding in gradients
Compression Artifacts
🚫 Common Artifacts
- • **Blocking:** Visible 8×8 pixel blocks
- • **Ringing:** Oscillations around sharp edges
- • **Mosquito noise:** Flickering around objects
- • **Color banding:** Smooth gradients become stepped
- • **Motion blur:** Fast movement becomes smeared
✅ Prevention Tips
- • **Appropriate bitrate:** Don't over-compress
- • **Deblocking filters:** Enable in encoder settings
- • **Two-pass encoding:** Better bit allocation
- • **Proper preprocessing:** Noise reduction before encoding
- • **Test different presets:** Find optimal settings
Encoding Presets
Understanding Encoder Presets (Speed vs Quality)
Preset | Speed | Compression | Quality | Use Case |
---|---|---|---|---|
ultrafast | ⚡⚡⚡ | ⭐ | ⭐ | Live streaming |
fast | ⚡⚡ | ⭐⭐ | ⭐⭐ | Real-time encoding |
medium | ⚡ | ⭐⭐⭐ | ⭐⭐⭐ | General purpose |
slow | 🐌 | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | High quality archival |
placebo | 🐌🐌 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | Maximum quality |
🧠 Key Takeaways
For Beginners
- • Use CRF 23 for most content
- • H.264 codec for best compatibility
- • Medium preset balances speed and quality
- • Test settings on short clips first
For Advanced Users
- • Two-pass encoding for target bitrates
- • Optimize GOP structure for use case
- • Consider psychovisual optimizations
- • Profile and benchmark your workflows