#
MP3 encoder
Video Capture SDK .Net Video Edit SDK .Net Media Blocks SDK .Net
SDK contains MP3 audio encoder that can be used to encode audio streams to MP3 format using the LAME library. MP3 is a lossy audio compression format that is widely used in audio streaming and storage.
You can use MP3 encode to encode audio in MP4, AVI, MKV, and other containers.
#
Cross-platform MP3 output
VideoCaptureCoreX VideoEditCoreX MediaBlocksPipeline
The MP3EncoderSettings class provides a straightforward way to configure MP3 encoding with support for different rate controls and quality settings.
#
Supported Formats and Specifications
- Input Format: S16LE (Signed 16-bit Little Endian)
- Sample Rates: 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 Hz
- Channels: Mono (1) or Stereo (2)
#
Rate Control Modes
The encoder supports three rate control modes:
CBR (Constant Bit Rate)
- Fixed bitrate throughout the entire encoding process
- Supported bitrates: 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 Kbit/s
- Best for streaming and when consistent file size is important
ABR (Average Bit Rate)
- Maintains an average bitrate while allowing some variation
- More efficient than CBR while still maintaining predictable file sizes
- Useful for streaming services that need approximate file size estimates
Quality-based VBR
- Variable Bit Rate based on sound complexity
- Quality setting ranges from 0 (best) to 10
- Most efficient for storage and best quality-to-size ratio
#
Sample Usage
Create basic MP3 encoder settings with CBR.
var mp3Settings = new MP3EncoderSettings
{
RateControl = MP3EncoderRateControl.CBR,
Bitrate = 192,
EncodingEngineQuality = MP3EncodingQuality.Standard,
ForceMono = false
};
Quality-based VBR configuration.
var vbrSettings = new MP3EncoderSettings
{
RateControl = MP3EncoderRateControl.Quality,
Quality = 2.0f, // High quality VBR
EncodingEngineQuality = MP3EncodingQuality.High
};
Add the MP3 output to the Video Capture SDK core instance:
// Create a Video Capture SDK core instance
var core = new VideoCaptureCoreX();
// Create a MP3 output instance
var mp3Output = new MP3Output("output.mp3");
// Set the bitrate
mp3Output.Audio.RateControl = MP3EncoderRateControl.CBR;
mp3Output.Audio.Bitrate = 128;
// Add the MP3 output
core.Outputs_Add(mp3Output, 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 MP3 output instance
var mp3Output = new MP3Output("output.mp3");
// Set the quality
mp3Output.Audio.RateControl = MP3EncoderRateControl.Quality;
mp3Output.Audio.Quality = 5.0f;
// Set the output format
core.Output_Format = mp3Output;
Create a Media Blocks MP3 output instance:
// Create a MP3 encoder settings instance
var mp3Settings = new MP3EncoderSettings();
// Create a MP3 output instance
var mp3Output = new MP3OutputBlock("output.mp3", mp3Settings);
Check if MP3 encoding is available.
if (!MP3EncoderSettings.IsAvailable())
{
// Handle error
}
#
Encoding Quality Levels
The encoder supports three quality presets that affect the encoding speed and CPU usage:
Fast
: Quickest encoding, lower CPU usageStandard
: Balanced speed and quality (default)High
: Best quality, higher CPU usage
#
Common Scenarios
#
High-Quality Music Encoding
var highQualitySettings = new MP3EncoderSettings
{
RateControl = MP3EncoderRateControl.Quality,
Quality = 0.0f,
EncodingEngineQuality = MP3EncodingQuality.High
};
#
Streaming Audio
var streamingSettings = new MP3EncoderSettings
{
RateControl = MP3EncoderRateControl.CBR,
Bitrate = 128,
EncodingEngineQuality = MP3EncodingQuality.Fast
};
#
Windows-only MP3 output
VideoCaptureCore VideoEditCore
The MP3 file output class provides advanced configuration options for MP3 encoding in video capture and editing scenarios.
#
Key Features
- Flexible channel mode selection
- VBR and CBR encoding support
- Advanced encoding parameters
- Quality control settings
#
Channel Modes
The MP3Output supports four channel modes:
Standard Stereo
- Independent channel encoding
- Best for tracks with significant stereo separation
Joint Stereo
- Uses mid/side stereo coding
- Efficient for most stereo content
- Default for VBR below quality level 4 or CBR below 160kbps
Dual Stereo
- Independent encoding with equal bitrate allocation
- Useful for dual-language content
Mono
- Single channel output
- 6dB attenuated downmix for stereo inputs
#
Sample Usage
Basic settings.
var mp3Output = new MP3Output
{
CBR_Bitrate = 192,
SampleRate = 44100,
ChannelsMode = MP3ChannelsMode.JointStereo,
};
core.Output_Format = mp3Output; // Core is VideoCaptureCore or VideoEditCore
VBR configuration.
var mp3Output = new MP3Output
{
VBR_Mode = true,
VBR_MinBitrate = 96,
VBR_MaxBitrate = 192,
VBR_Quality = 6,
};
core.Output_Format = mp3Output; // Core is VideoCaptureCore or VideoEditCore
Advanced options.
var mp3Output = new MP3Output
{
EncodingQuality = 6,
EnableXingVBRTag = true,
Copyright = false,
Original = true
};
core.Output_Format = mp3Output; // Core is VideoCaptureCore or VideoEditCore
#
Advanced Settings
- CRC Protection: Adds error detection capability at the cost of 16 bits per frame
- Short Blocks: Can be disabled to potentially increase quality at very low bitrates
- Frequency Range: Option to keep all frequencies (disables automatic lowpass filtering)
- Voice Mode: Experimental mode optimized for voice content
#
Best Practices
Choosing Rate Control
- Use CBR for streaming and real-time applications
- Use Quality-based VBR for archival and highest quality
- Use ABR when you need a balance between consistent size and quality
Quality Settings
- For archival: Use VBR with quality 0-2
- For general use: VBR with quality 3-5 or CBR 192-256kbps
- For voice: Consider using voice encoding mode with lower bitrates
Channel Mode Selection
- Use Joint Stereo for most music content
- Use Standard Stereo for critical listening and complex stereo mixes
- Use Mono for voice recordings or when bandwidth is critical
Performance Optimization
- Use Fast encoding quality for real-time applications
- Use Standard quality for general purpose encoding
- Use High quality only for archival purposes where encoding time is not critical