OPUS encoder
SDK contains the royalty-free OPUS encoder, that encodes audio into the Opus format, which is often encapsulated in containers like Ogg, Matroska, WebM, or RTP streams. Opus is a highly versatile, supporting speech and music at a wide range of bitrates, frame sizes, and complexities.
Cross-platform OPUS output (X-engines: VideoCaptureCoreX, VideoEditCoreX, Media Blocks)
Key OPUS encoder properties include:
- Bitrate: Target bitrate in Kbps.
- Rate control mode: Variable Bitrate, Constant Bitrate, and Constrained VBR.
- Complexity: Encoding complexity (0-10), with higher yielding better quality at the cost of CPU usage.
OPUS is an audio codec that provides high-quality audio compression and is suitable for a wide range of applications.
In cross-platform X-engines you can use OPUSEncoderSettings class to configure OPUS encoder settings.
Bitrate Control Modes
The bitrate-type property controls whether encoder uses VBR, CBR, or Constrained VBR. Note that Opus is naturally a VBR codec, so even "CBR" has some small fluctuation, but it`s generally close to constant.
- VBR: Fully variable bitrate.
- CBR: Targets a constant bitrate.
- CBVR: Constrained VBR, which tries to keep the bitrate around a target but allows some variability.
You can set a desired bitrate (in bps), typically in the range of 6000-510000 for mono and up to 256000 or more for stereo (Opus can go quite high, but typically 64-128 kbps for stereo speech/music is common).
Variable Bitrate (VBR)
VBR allows the encoder to adjust bits based on audio complexity, typically yielding the best quality per average bitrate.
// Create an instance of the OPUSEncoderSettings class.
var opus = new OPUSEncoderSettings();
// Set rate control mode to VBR
opus.RateControl = OPUSRateControl.VBR;
// Set audio bitrate for the codec (in Kbps)
opus.Bitrate = 128;
Constant Bitrate (CBR)
In CBR mode, encoder tries to keep the bitrate close to the target. This is useful in scenarios where consistent network bandwidth usage is needed, though some minor fluctuation can still occur.
// Create an instance of the OPUSEncoderSettings class.
var opus = new OPUSEncoderSettings();
// Set rate control mode to CBR
opus.RateControl = OPUSRateControl.CBR;
// Set audio bitrate for the codec (in Kbps)
opus.Bitrate = 128;
Constrained VBR (CVBR)
Constrained VBR is a hybrid approach where the encoder can vary the bitrate based on content complexity, but within constraints to avoid large spikes.
// Create an instance of the OPUSEncoderSettings class.
var opus = new OPUSEncoderSettings();
// Set rate control mode to Constrained VBR
opus.RateControl = OPUSRateControl.ConstrainedVBR;
// Set audio bitrate for the codec (in Kbps)
opus.Bitrate = 128;
Sample Code
Add the OPUS output to the Video Capture SDK core instance:
// Create a Video Capture SDK core instance
var core = new VideoCaptureCoreX();
// Create a OPUS output instance
var opusOutput = new OPUSOutput("output.opus");
// Set the bitrate
opusOutput.Audio.RateControl = OPUSRateControl.CBR;
opusOutput.Audio.Bitrate = 128;
// Add the OPUS output
core.Outputs_Add(opusOutput, true);
Set the output format for the Video Edit SDK core instance:
// Create a Video Edit SDK core instance
var core = new VideoEditCoreX();
// Create a OPUS output instance
var opusOutput = new OPUSOutput("output.opus");
// Set the bitrate
opusOutput.Audio.RateControl = OPUSRateControl.VBR;
opusOutput.Audio.Bitrate = 192;
// Set the output format
core.Output_Format = opusOutput;
Create a Media Blocks OPUS output instance:
// Create a OPUS encoder settings instance
var opusSettings = new OPUSEncoderSettings();
// Create a Ogg OPUS output instance
var opusOutput = new OGGOpusOutputBlock("output.ogg", opusSettings);