Understanding and Configuring SRT streaming
SRT (Secure Reliable Transport) is a powerful streaming protocol designed for high-quality, low-latency video delivery across unpredictable networks. The SRT output configuration allows you to stream media content using the SRT protocol, supporting various video and audio encoders. The implementation provides flexibility in choosing encoders based on your platform and requirements while maintaining optimal streaming performance.
Cross-platform SRT output (X-engines: VideoCaptureCoreX, VideoEditCoreX, Media Blocks)
Basic Configuration
To initialize SRT output, you'll need to provide a URL that specifies the streaming destination.
Add SRT output to the Video Capture SDK .Net engine:
// Create SRT output
var srtOutput = new SRTOutput("srt://streaming-server:1234");
// Add SRT output to the capture engine
videoCapture.Outputs_Add(srtOutput, true); // videoCapture is an instance of VideoCaptureCoreX
Usage in Media Blocks SDK .Net:
// Create SRT sink block
var srtSink = new SRTMPEGTSSinkBlock(new SRTSinkSettings() { Uri = "srt://:8888" });
// Disable parsing for SRT for H264 and HEVC encoders
h264Encoder.Settings.ParseStream = false; // h264Encoder is an instance of H264EncoderBlock
// Connect video encoder output to SRT sink
pipeline.Connect(h264Encoder.Output, srtSink.CreateNewInput(MediaBlockPadMediaType.Video));
// Connect audio encoder output to SRT sink
pipeline.Connect(aacEncoder.Output, srtSink.CreateNewInput(MediaBlockPadMediaType.Audio));
The URL should follow the SRT protocol format and include the appropriate host and port information.
Video Encoding Options
The SRT output supports multiple video encoders, offering different performance characteristics and hardware acceleration options. The supported video encoders include:
Software Encoders
- OpenH264: The default software encoder, offering good compatibility across platforms
Hardware-Accelerated Encoders
- NVENC H264/HEVC: NVIDIA GPU acceleration
- QSV H264/HEVC: Intel Quick Sync Video acceleration
- AMF H264/H265: AMD GPU acceleration
- MF HEVC: Microsoft Media Foundation HEVC encoder (Windows only)
Example configuration for NVIDIA hardware acceleration:
srtOutput.Video = new NVENCH264EncoderSettings();
Audio Encoding Configuration
Audio encoding options include:
- VO-AAC: Cross-platform AAC encoder
- AVENC AAC: FFmpeg-based AAC encoder
- MF AAC: Microsoft Media Foundation AAC encoder (Windows only)
The default audio configuration varies by platform:
- Windows: Uses MF AAC encoder
- Other platforms: Uses VO AAC encoder
Platform-Specific Considerations
Windows
On Windows systems, you have access to additional encoders through the Media Foundation framework:
- MF AAC for audio encoding
- MF HEVC for video encoding
macOS
On macOS, the system automatically uses:
- Apple Media H264 encoder for video
- VO AAC encoder for audio
Advanced Features
Custom Processing
The SRT output supports custom video and audio processing through media blocks:
srtOutput.CustomVideoProcessor = new MediaBlock();
srtOutput.CustomAudioProcessor = new MediaBlock();
These custom processors allow you to implement additional processing steps before the media is encoded and transmitted.
Sink Settings
The SRTSinkSettings class provides additional configuration options for the SRT connection:
srtOutput.Sink.Uri = "srt://new-server:5678";
Best Practices
-
Encoder Selection: Choose hardware-accelerated encoders when available for better performance. The code automatically falls back to software encoding if hardware acceleration is unavailable.
-
Platform Compatibility: Consider your target platform when selecting encoders. Some encoders are platform-specific and may not be available across all systems.
-
Performance Optimization: For live streaming scenarios, configure your encoders with appropriate bitrates and quality settings to balance quality and latency.
-
Error Handling: Always verify encoder availability before using hardware-accelerated options:
if (NVENCH264EncoderSettings.IsAvailable())
{
srtOutput.Video = new NVENCH264EncoderSettings();
}
else
{
srtOutput.Video = new OpenH264EncoderSettings();
}
Troubleshooting
Common issues and their solutions:
-
Encoder Initialization Failures: Ensure the selected encoder is supported on your platform and required hardware/drivers are installed.
-
Streaming Issues: Verify the SRT URL format and network connectivity. Check if the specified ports are open and accessible.
-
Performance Problems: Monitor CPU and GPU usage. Consider switching to hardware-accelerated encoders if experiencing high CPU usage.
Additional Resources
For more information about specific encoders or advanced configuration options, refer to the following:
- VisioForge documentation for encoder-specific settings
- SRT protocol documentation for network configuration
- Platform-specific documentation for hardware acceleration features