Enum X264Mode
- Namespace
- VisioForge.Core.Types.FFMPEGEXE
- Assembly
- VisioForge.Core.dll
Specifies the rate control mode for x264 encoding operations.
public enum X264ModeFields
CRF = 0-
Constant Rate Factor (CRF) - quality-based encoding.
CRF mode targets a constant quality level throughout the video by varying the bitrate. Simple scenes use fewer bits, complex scenes use more bits, resulting in consistent perceptual quality.
How it works: - CRF value: 0 (lossless) to 51 (worst), default 23 - Lower CRF = higher quality, larger files - Higher CRF = lower quality, smaller files - Recommended range: 18-28
Advantages: - Consistent visual quality across entire video - Simple to use - single quality parameter - Optimal quality-to-size ratio - No need to calculate target bitrate - Efficient bit allocation
Disadvantages: - Unpredictable final file size - Variable bitrate unsuitable for some streaming - Bitrate spikes in complex scenes
Use cases: - Local playback and archival - VOD content preparation - High-quality masters - When quality matters more than size
FFMPEG: -c:v libx264 -crf 23 Recommended CRF values: - 18: Visually lossless - 23: Default, good quality - 28: Acceptable for web content
CRFLimitedBitrate = 1-
Constant Rate Factor with maximum bitrate constraint.
Combines CRF quality targeting with a maximum bitrate cap. The encoder maintains CRF quality until hitting the bitrate limit, then reduces quality as needed to stay under the cap.
How it works: - Encodes like CRF mode normally - Enforces maximum bitrate ceiling - Requires buffer size specification - Quality reduced only when needed
Advantages: - Quality consistency of CRF - Bitrate safety for streaming - Prevents bandwidth spikes - Good for adaptive streaming preparation
Configuration: - CRF value for target quality - MaxBitrate for upper limit - Buffer size (typically 1-2x maxrate)
Use cases: - HLS/DASH adaptive streaming - Streaming with bandwidth limits - Quality-focused with safety net - Network-constrained delivery
FFMPEG: -c:v libx264 -crf 23 -maxrate 2M -bufsize 4M Note: Buffer size should be 1-2 seconds of maxrate
CBR = 2-
Constant Bitrate (CBR) - fixed bitrate encoding.
CBR maintains a constant bitrate throughout the video by adjusting quality dynamically. Simple scenes may use higher quality, complex scenes lower quality to maintain the bitrate target.
How it works: - Target bitrate specified explicitly - Quality varies to maintain bitrate - Uses padding for simple scenes - Rate control buffer prevents spikes
Advantages: - Perfectly predictable file size - Ideal for streaming bandwidth management - Consistent network utilization - Required by some streaming protocols - Easy capacity planning
Disadvantages: - Variable quality across scenes - Inefficient - wastes bits on simple scenes - Complex scenes may show artifacts - Overall lower quality than CRF/ABR
Use cases: - Live streaming and broadcasting - Satellite and cable distribution - Fixed-bandwidth networks - Real-time video conferencing - IPTV applications
FFMPEG: -c:v libx264 -b:v 2M -minrate 2M -maxrate 2M -bufsize 2M Note: Set minrate = maxrate = target for true CBR
ABR = 3-
Average Bitrate (ABR) - target average bitrate encoding.
ABR targets an average bitrate over the entire video while allowing short-term variations. Complex scenes can exceed the target, simple scenes use less, averaging out to the target bitrate.
How it works: - Target average bitrate specified - Bitrate can vary ±20-30% short-term - Averages to target over full video - More flexible than CBR
Advantages: - Predictable file size (within 5%) - Better quality than CBR at same bitrate - Good for most streaming scenarios - Balance of quality and size - Widely compatible
Disadvantages: - Less consistent quality than CRF - Requires accurate bitrate calculation - Short-term bitrate spikes possible - May undershoot/overshoot target slightly
Use cases: - General-purpose encoding - VOD streaming services - File size constraints - YouTube, Vimeo uploads - Multi-platform distribution
FFMPEG: -c:v libx264 -b:v 2M Optionally add -maxrate and -bufsize for safety: -c:v libx264 -b:v 2M -maxrate 2.5M -bufsize 5M
Lossless = 4-
Lossless encoding - mathematically perfect quality.
Lossless mode preserves every pixel of the source video perfectly. The encoded video, when decoded, is bit-for-bit identical to the original source. Uses H.264 High 4:4:4 Predictive Profile.
How it works: - CRF 0 with lossless entropy coding - No quantization applied - Prediction and transform still used - Typical compression: 30-50% of original
Advantages: - Perfect quality preservation - Smaller than uncompressed - Suitable for editing workflows - No generation loss - Maintains full color resolution
Disadvantages: - Very large file sizes (5-20x lossy) - High encoding/decoding complexity - Limited hardware decoder support - Not suitable for streaming/distribution - CPU-intensive encoding
Use cases: - Video editing intermediate files - Screen recording and capture - Archival masters - When quality loss is unacceptable - Professional post-production
FFMPEG: -c:v libx264 -qp 0 -preset ultrafast Note: Use ultrafast preset as lossless doesn't benefit from slower presets Alternative: Consider FFV1, Ut Video, or other lossless codecs
Remarks
The x264 rate control mode determines how the encoder allocates bits across the video sequence. Each mode offers different trade-offs between quality consistency, file size predictability, and encoding complexity.
Mode selection affects: - Quality consistency across scenes - File size predictability - Encoding speed and complexity - Suitability for streaming vs storage - Bitrate allocation strategy