title: H264 Encoders for .NET: Hardware and Software Options description: Implement H264 video encoding with software and hardware acceleration, rate control options, and cross-platform support in .NET SDKs. tags: - Video Capture SDK - Media Blocks SDK - Video Edit SDK - .NET - MediaBlocksPipeline - VideoCaptureCoreX - VideoEditCoreX - Windows - macOS - Linux - Android - iOS - Capture - Streaming - Encoding - Editing - H.264 - C# primary_api_classes: - H264EncoderBlock - AndroidH264EncoderSettings - OpenH264EncoderSettings - AMFH264EncoderSettings - NVENCH264EncoderSettings
H264 Encoders¶
Video Capture SDK .Net Video Edit SDK .Net Media Blocks SDK .Net
VideoCaptureCoreX VideoEditCoreX MediaBlocksPipeline
This document provides detailed information about available H264 encoders, their features, rate control options, and usage examples.
For Windows-only engines check the MP4 output page.
Overview¶
The following H264 encoders are available:
- AMD AMF H264 Encoder (GPU-accelerated)
- NVIDIA NVENC H264 Encoder (GPU-accelerated)
- Intel QSV H264 Encoder (GPU-accelerated)
- OpenH264 Encoder (Software)
- Apple Media H264 Encoder (Hardware-accelerated for Apple devices)
- VAAPI H264 Encoder (Linux hardware acceleration)
- Android Hardware H264 Encoder (MediaCodec, auto-selects best SoC encoder)
AMD AMF H264 Encoder¶
AMD's Advanced Media Framework (AMF) provides hardware-accelerated encoding on AMD GPUs.
Key Features¶
- Hardware-accelerated encoding
- Multiple preset options (Balanced, Speed, Quality)
- Configurable GOP size
- CABAC entropy coding support
- Various rate control methods
Rate Control Options¶
public enum AMFH264EncoderRateControl
{
Default = -1, // Default, depends on usage
CQP = 0, // Constant QP
CBR = 1, // Constant bitrate
VBR = 2, // Peak constrained VBR
LCVBR = 3 // Latency Constrained VBR
}
Sample Usage¶
var settings = new AMFH264EncoderSettings
{
Bitrate = 5000, // 5 Mbps
CABAC = true,
RateControl = AMFH264EncoderRateControl.CBR,
Preset = AMFH264EncoderPreset.Quality,
Profile = AMFH264EncoderProfile.Main,
Level = AMFH264EncoderLevel.Level4_2,
GOPSize = 30
};
var encoder = new H264EncoderBlock(settings);
NVIDIA NVENC H264 Encoder¶
NVIDIA's hardware-based video encoder provides efficient H264 encoding on NVIDIA GPUs.
Key Features¶
- Hardware-accelerated encoding
- B-frame support
- Adaptive quantization
- Multiple reference frames
- Weighted prediction
- Look-ahead support
Rate Control Options¶
Inherited from NVENCBaseEncoderSettings with additional H264-specific options:
- Constant Bitrate (CBR)
- Variable Bitrate (VBR)
- Constant QP (CQP)
- Quality-based VBR
Sample Usage¶
var settings = new NVENCH264EncoderSettings
{
Bitrate = 5000,
MaxBitrate = 8000,
RCLookahead = 20,
BFrames = 2,
Profile = NVENCH264Profile.High,
Level = NVENCH264Level.Level4_2,
TemporalAQ = true
};
var encoder = new H264EncoderBlock(settings);
Intel Quick Sync Video (QSV) H264 Encoder¶
Intel's hardware-based video encoder available on Intel processors with integrated graphics.
Key Features¶
- Hardware-accelerated encoding
- Low latency mode
- Multiple rate control methods
- B-frame support
- Intelligent rate control options
Rate Control Options¶
public enum QSVH264EncRateControl
{
CBR = 1, // Constant Bitrate
VBR = 2, // Variable Bitrate
CQP = 3, // Constant Quantizer
AVBR = 4, // Average Variable Bitrate
LA_VBR = 8, // Look Ahead VBR
ICQ = 9, // Intelligent CQP
VCM = 10, // Video Conferencing Mode
LA_ICQ = 11, // Look Ahead ICQ
LA_HRD = 13, // HRD compliant LA
QVBR = 14 // Quality-defined VBR
}
Sample Usage¶
var settings = new QSVH264EncoderSettings
{
Bitrate = 5000,
MaxBitrate = 8000,
RateControl = QSVH264EncRateControl.VBR,
Profile = QSVH264EncProfile.High,
Level = QSVH264EncLevel.Level4_2,
LowLatency = true,
BFrames = 2
};
var encoder = new H264EncoderBlock(settings);
OpenH264 Encoder¶
Cisco's open-source H264 software encoder.
Key Features¶
- Software-based encoding
- Multiple complexity levels
- Scene change detection
- Adaptive quantization
- Denoising support
Rate Control Options¶
public enum OpenH264RCMode
{
Quality = 0, // Quality mode
Bitrate = 1, // Bitrate mode
Buffer = 2, // Buffer based
Off = -1 // Rate control off
}
Sample Usage¶
var settings = new OpenH264EncoderSettings
{
Bitrate = 5000,
RateControl = OpenH264RCMode.Bitrate,
Profile = OpenH264Profile.Main,
Level = OpenH264Level.Level4_2,
Complexity = OpenH264Complexity.Medium,
EnableDenoise = true,
SceneChangeDetection = true
};
var encoder = new H264EncoderBlock(settings);
Apple Media H264 Encoder¶
Hardware-accelerated encoder for Apple platforms.
Key Features¶
- Hardware acceleration on Apple devices
- Real-time encoding support
- Frame reordering options
- Quality-based encoding
Sample Usage¶
var settings = new AppleMediaH264EncoderSettings
{
Bitrate = 5000,
AllowFrameReordering = true,
Quality = 0.8,
Realtime = true
};
var encoder = new H264EncoderBlock(settings);
VAAPI H264 Encoder¶
Video Acceleration API encoder for Linux systems.
Key Features¶
- Hardware acceleration on Linux
- Multiple profile support
- Trellis quantization
- B-frame support
- Various rate control methods
Rate Control Options¶
public enum VAAPIH264RateControl
{
CQP = 1, // Constant QP
CBR = 2, // Constant bitrate
VBR = 4, // Variable bitrate
VBRConstrained = 5, // Constrained VBR
ICQ = 7, // Intelligent CQP
QVBR = 8 // Quality-defined VBR
}
Sample Usage¶
var settings = new VAAPIH264EncoderSettings
{
Bitrate = 5000,
RateControl = VAAPIH264RateControl.CBR,
Profile = VAAPIH264EncoderProfile.Main,
MaxBFrames = 2,
Trellis = true,
CABAC = true
};
var encoder = new H264EncoderBlock(settings);
Android Hardware H264 Encoder¶
On Android (API 21+), use AndroidH264EncoderSettings. It wraps the Android MediaCodec API via GStreamer's amcvidenc-* element family, auto-detecting the best hardware encoder on the device (Qualcomm, Exynos, MediaTek, etc.) — so a single settings class covers every Android SoC.
Sample usage¶
// Build is Android-only (this type is gated by the __ANDROID__ preprocessor).
var settings = new AndroidH264EncoderSettings
{
Bitrate = 8_000, // kbit/s (so 8000 = 8 Mbps)
IFrameInterval = TimeSpan.FromSeconds(2), // Keyframe cadence
ParseStream = true, // Leave true unless you are piping raw frames into SRT
};
// Optional: pin a specific encoder element name, bypassing auto-detection.
// settings.CodecName = "amcvidenc-c2qtiavcencoder"; // Qualcomm Codec2 path, for example
var encoder = new H264EncoderBlock(settings);
Key characteristics¶
- Single settings class for every Android SoC — no per-vendor types
Bitratein kbit/s (the GStreamer element receives bits/sec internally)IFrameIntervalis aTimeSpan— on Android 25+ fractional seconds work (i-frame-interval-float); older versions truncate to whole secondsCodecNameoverrides auto-detection when you know whichamcvidenc-*element you want
Properties bag¶
Only CustomH264EncoderSettings and AndroidH264EncoderSettings expose a Properties dictionary for forwarding raw GStreamer element properties that don't have first-class C# wrappers. The standard implementations (OpenH264, NVENCH264, QSVH264, AMFH264, AppleMediaH264, VAAPIH264) do not — their tuning knobs are exposed as typed C# properties on the settings class.
// Custom or Android settings only
var settings = new CustomH264EncoderSettings("x264enc");
settings.Properties["bitrate-mode"] = "constant";
settings.Properties["complexity"] = "max";
Best Practices¶
- Encoder Selection
- Use hardware encoders (AMD, NVIDIA, Intel) when available for better performance
- Fall back to OpenH264 when hardware encoding is not available
-
Use platform-specific encoders (Apple Media, VAAPI, Android hardware) when targeting specific platforms
-
Rate Control Selection
- Use CBR for streaming applications where consistent bitrate is important
- Use VBR for offline encoding where quality is more important than bitrate consistency
- Use CQP for highest quality when bitrate is not a concern
-
Consider using look-ahead options for better quality when latency is not critical
-
Performance Optimization
- Adjust GOP size based on content type (smaller for high motion, larger for static content)
- Enable CABAC for better compression efficiency when latency is not critical
- Use appropriate profile and level for target devices
-
Consider B-frames for better compression but be aware of latency impact
-
Platform Detection — use the
IsAvailable()static on each settings class to pick a concrete encoder at runtime:
if (NVENCH264EncoderSettings.IsAvailable())
{
encoder = new H264EncoderBlock(new NVENCH264EncoderSettings { Bitrate = 6_000 });
}
else if (QSVH264EncoderSettings.IsAvailable())
{
encoder = new H264EncoderBlock(new QSVH264EncoderSettings { Bitrate = 6_000 });
}
else if (AMFH264EncoderSettings.IsAvailable())
{
encoder = new H264EncoderBlock(new AMFH264EncoderSettings { Bitrate = 6_000 });
}
else
{
// Software fallback
encoder = new H264EncoderBlock(new OpenH264EncoderSettings { Bitrate = 6_000 });
}