Class X264Settings
- Namespace
- VisioForge.Core.Types.FFMPEGEXE
- Assembly
- VisioForge.Core.dll
Provides configuration settings for x264 H.264/AVC video encoding through FFMPEG.
public class X264Settings : BasicVideoSettingsInheritance
Inherited Members
Remarks
x264 is the premier open-source H.264/AVC encoder, providing the best quality-to-bitrate ratio among all H.264 encoders. It is widely considered the reference implementation for H.264 encoding and is used by major streaming platforms, content providers, and professional video production workflows.
Key features of x264: - Best-in-class H.264 encoding quality - Extensive tuning options and presets - Constant Rate Factor (CRF) for quality-based encoding - Advanced rate control algorithms - Psychovisual optimizations - Multi-threading support - Multiple encoding passes
IMPORTANT: The FFMPEG executables provided with some SDKs may not include x264 due to licensing restrictions (x264 is GPL-licensed). You may need to build FFMPEG with --enable-libx264 or obtain a pre-built version that includes x264.
FFMPEG usage: ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 23 -profile:v high -level 4.1 output.mp4
Constructors
X264Settings()
Initializes a new instance of the VisioForge.Core.Types.FFMPEGEXE.X264Settings class with recommended defaults.
public X264Settings()Remarks
Default configuration provides excellent quality with good compression efficiency: - Encoder: x264 (libx264) - Profile: Main (broad compatibility) - Level: 4.0 (supports 1080p@30fps) - Preset: Medium (good balance) - Mode: CRF (constant quality) - Quantizer (CRF): 23 (high quality) - QuickTime Compatibility: Enabled - Zero-Latency: Disabled
This configuration is suitable for: - General-purpose video encoding - Web streaming and VOD - High-quality archival - Multi-platform distribution
Adjust settings after initialization based on specific requirements: - Live streaming: Enable ZeroTolerance, use CBR or ABR mode - Maximum quality: Lower Quantizer to 18-20, use slower Preset - Faster encoding: Use faster Preset (Fast, VeryFast) - Smaller files: Raise Quantizer to 26-28
Properties
BFrames
Gets or sets the maximum number of consecutive B-frames.
public int BFrames { get; set; }Property Value
Remarks
B-frames (bidirectional predictive frames) reference both past and future frames, providing excellent compression but adding complexity and latency. This parameter controls how many consecutive B-frames can appear between reference frames (I/P).
B-frame recommendations: - 0: No B-frames (lowest latency, larger files, baseline profile compatible) - 2: Standard (good balance, Main profile) - 3: x264 default (optimal for most content, High profile) - 4-8: Maximum compression (diminishing returns, higher latency) - 16: x264 maximum (rarely beneficial)
Trade-offs: - More B-frames: Better compression, higher latency, more CPU/memory - Fewer B-frames: Faster encoding, lower latency, larger files
FFMPEG usage: -bf 3
Note: B-frames are not supported in Baseline profile. For low-latency streaming, set to 0 or 1. For maximum quality archival, use x264's adaptive B-frame decision (default).
GOPSize
Gets or sets the Group of Pictures (GOP) size.
public int GOPSize { get; set; }Property Value
Remarks
GOP size determines how often I-frames (keyframes) appear in the video stream. A GOP starts with an I-frame and contains all subsequent frames until the next I-frame. Larger GOPs improve compression but reduce seek granularity and error recovery.
GOP size guidelines: - 1-30: Very short (frequent keyframes, larger files, fast seeking) - 60-120: Short (2-4 seconds @ 30fps, good for streaming) - 120-300: Standard (4-10 seconds, balanced) - 300-600: Long (10-20 seconds, best compression) - 600+: Very long (poor seeking, error propagation risk)
Typical values by use case: - Live streaming: 60-120 (2-4 seconds for adaptive bitrate switching) - VOD streaming: 120-300 (4-10 seconds) - Broadcasting: 12-15 (for NTSC) or 12-25 (for PAL) - File archival: 250-300 (maximum compression)
FFMPEG usage: -g 250
Considerations: - Shorter GOP: Better seek performance, larger files, faster error recovery - Longer GOP: Better compression, poor seeking, error propagation - For HLS/DASH: GOP should align with segment duration - For editing: Short GOP (60-90) for frame-accurate seeking
Default in x264: Approximately 10 seconds (300 frames at 30fps)
Level
Gets or sets the H.264 level.
public H264Level Level { get; set; }Property Value
Remarks
Defines maximum resolution, frame rate, and bitrate constraints. See VisioForge.Core.Types.FFMPEGEXE.H264Level for detailed information about each level.
Mode
Gets or sets the x264 rate control mode.
public X264Mode Mode { get; set; }Property Value
Remarks
Determines how x264 allocates bits across the video. Different modes offer trade-offs between quality consistency, file size predictability, and encoding efficiency.
Default: CRF (Constant Rate Factor) - provides the best quality-to-size ratio
See VisioForge.Core.Types.FFMPEGEXE.X264Mode for detailed information about each rate control mode.
Preset
Gets or sets the x264 encoding preset.
public X264Preset Preset { get; set; }Property Value
Remarks
Presets control the trade-off between encoding speed and compression efficiency. Slower presets produce smaller files with better quality at the same bitrate but take longer to encode.
Default: Medium (good balance for most use cases)
See VisioForge.Core.Types.FFMPEGEXE.X264Preset for detailed information about each preset and their encoding parameters.
PresetCustom
Gets or sets the custom preset string when using a custom preset.
public string PresetCustom { get; set; }Property Value
Remarks
Allows specification of a custom preset string that will be passed directly to x264. This provides access to advanced x264 options not exposed through the standard preset enumeration.
Set VisioForge.Core.Types.FFMPEGEXE.X264Settings.Preset to X264Preset.None or X264Preset.Custom before using this property.
Example custom presets: - "veryslow,tune=film": Maximum quality for film content - "ultrafast,tune=zerolatency": Ultra-low latency streaming - "slow,tune=animation": Optimized for animated content
FFMPEG usage: -preset [custom_string]
Profile
Gets or sets the H.264 profile.
public H264Profile Profile { get; set; }Property Value
Remarks
Determines the feature set and compatibility of the encoded video. See VisioForge.Core.Types.FFMPEGEXE.H264Profile for detailed information about each profile.
Quantizer
Gets or sets the Constant Rate Factor (CRF) quantizer value.
public int Quantizer { get; set; }Property Value
Remarks
The CRF (Constant Rate Factor) controls the quality level for CRF-based encoding modes. It provides a quality target that x264 will try to achieve consistently across the entire video, varying the bitrate as needed.
CRF Scale (0-51): - 0: Lossless (mathematically perfect, very large files) - 17-18: Visually lossless (indistinguishable from source to most viewers) - 20-23: High quality (23 is the default, excellent for most content) - 24-28: Good quality (suitable for web streaming) - 29-35: Acceptable quality (noticeable compression, smaller files) - 36-51: Poor to very poor quality (not recommended)
The scale is exponential: +6 CRF approximately halves the bitrate, -6 CRF approximately doubles the bitrate.
Default: 23 (recommended starting point) Recommended range: 18-28
FFMPEG usage: -crf 23
Tuning guidelines: - Start with default (23) - If quality is insufficient, lower by 1-2 (e.g., 21) - If files are too large, raise by 1-2 (e.g., 25) - Use 18 for near-perfect quality archival - Use 28 for acceptable web quality with small files
QuickTimeCompatibility
Gets or sets a value indicating whether Apple QuickTime compatibility is enabled.
public bool QuickTimeCompatibility { get; set; }Property Value
Remarks
When enabled, ensures the encoded video is compatible with Apple QuickTime Player and other Apple software/devices. QuickTime has strict requirements for H.264 video format, particularly regarding color space.
QuickTime H.264 requirements: - YUV planar color space with 4:2:0 chroma subsampling - No 4:4:4 or RGB color spaces - Specific pixel format (yuv420p) - Compliant MP4 container structure
FFMPEG enforces: -pix_fmt yuv420p
Impact when enabled: - Forces YUV 4:2:0 color space - May reduce quality for content with fine chroma detail - Ensures compatibility with iOS, macOS, Safari - Required for iTunes Store delivery
Disable when: - Targeting only non-Apple platforms - Need 4:4:4 or RGB encoding - Working with screen capture or graphics - QuickTime playback is not required
Default: true (recommended for maximum compatibility)
WebFastStart
Gets or sets a value indicating whether fast start mode is enabled for web playback.
public bool WebFastStart { get; set; }Property Value
Remarks
When enabled, moves the MP4 file's metadata (moov atom) to the beginning of the file. This allows web browsers and streaming players to start playback before the entire file is downloaded, enabling progressive download and smoother user experience.
Without fast start (moov at end): - Player must download entire file before playback - Seeking is unavailable during download - Poor user experience for web streaming
With fast start (moov at start): - Playback can begin immediately - Seeking works during progressive download - Essential for web video delivery - Required for HTTP pseudo-streaming
FFMPEG usage: -movflags +faststart
Note: Enabling this requires a post-processing step after encoding (file rewrite), which adds a small amount of time to the encoding process. Always enable this for files intended for web delivery.
ZeroTolerance
Gets or sets a value indicating whether zero-latency mode is enabled for streaming.
public bool ZeroTolerance { get; set; }Property Value
Remarks
Zero-latency mode optimizes x264 for real-time streaming by disabling features that require frame buffering and future frame lookahead. This is similar to x264's "tune=zerolatency" option.
Optimizations when enabled: - Disables frame lookahead (rc-lookahead 0) - Disables B-frames (or minimal B-frames) - Reduces VBV buffer size - Disables mbtree (macroblock tree) - Forces slice-based threading - Minimizes encoder buffering
Trade-offs: - Latency: Reduced from seconds to milliseconds - Quality: 10-20% loss in compression efficiency - File size: 10-20% larger at same quality - Speed: Slightly faster encoding
Essential for: - Live streaming (Twitch, YouTube Live) - Video conferencing - Real-time remote desktop - Interactive applications - Low-latency RTMP/RTSP streaming
Not needed for: - File-based encoding (VOD) - Delayed streaming with buffer - Archival and distribution
Default: false Set to true for live streaming applications requiring minimal latency.