M4A (AAC) Output
The M4A output functionality in VisioForge SDKs allows you to create M4A audio files with AAC encoding. This guide explains how to configure and use the M4AOutput class effectively.
Cross-platform M4A (AAC) output (X-engines: VideoCaptureCoreX, VideoEditCoreX, Media Blocks)
Basic Usage
To create an M4A output, you'll need to instantiate the M4AOutput class with a filename:
var output = new M4AOutput("output.m4a");
Audio Encoder Settings
The M4AOutput class supports three different AAC encoders:
- VO-AAC
- AVENC AAC
- MF AAC (Windows only)
You can get more information about these encoders in the AAC Encoders guide.
By default, the following encoder will be selected:
- On Windows: MF AAC
- Other platforms: VO-AAC
Changing the Audio Encoder
You can change the audio encoder by setting the Audio
property:
// Using VO-AAC encoder
output.Audio = new VOAACEncoderSettings();
// Using AVENC AAC encoder
output.Audio = new AVENCAACEncoderSettings();
// Using MF AAC encoder (Windows only)
#if NET_WINDOWS
output.Audio = new MFAACEncoderSettings();
#endif
Sink Settings
The M4AOutput uses MP4 sink settings for file output configuration. You can access and modify these settings through the Sink
property:
// Access sink settings
output.Sink.Filename = "new_output.m4a";
Custom Audio Processing
If you need to apply custom audio processing, you can set up a custom audio processor:
output.CustomAudioProcessor = new MyCustomAudioProcessor(); // Implement your custom MediaBlock
Interface Implementation
The M4AOutput class implements several interfaces:
IVideoEditXBaseOutput
IVideoCaptureXBaseOutput
IOutputAudioProcessor
This makes it suitable for use in both video editing and video capture scenarios.
Available Methods
File Management
// Get current filename
string currentFile = output.GetFilename();
// Set new filename
output.SetFilename("new_file.m4a");
Encoder Information
// Get available video encoders (returns empty array as M4A is audio-only)
var videoEncoders = output.GetVideoEncoders();
// Get available audio encoders
var audioEncoders = output.GetAudioEncoders();
Best Practices
- Always dispose of resources properly when you're done with the output
- Choose the appropriate encoder based on your platform and quality requirements
- Consider using custom audio processing only when necessary, as it may impact performance
- Ensure proper file permissions when setting output locations
Example Implementation
Here's a complete example showing how to set up M4A output:
Add the M4A output to the Video Capture SDK core instance:
var core = new VideoCaptureCoreX();
core.Outputs_Add(output, true);
Set the output format for the Video Edit SDK core instance:
var core = new VideoEditCoreX();
core.Output_Format = output;
Create a Media Blocks M4A output instance:
var aac = new VOAACEncoderSettings();
var sinkSettings = new MP4SinkSettings("output.m4a");
var m4aOutput = new M4AOutputBlock(sinkSettings, aac);
Windows-only engines (VideoCaptureCore/VideoEditCore)
The M4AOutput class serves as the main configuration point for M4A/AAC audio encoding.
Properties
-
Version
Controls the MPEG version used for encoding. Can be either MPEG-4 (default) or MPEG-2. -
Object
Determines the AAC object type/profile used during encoding. Default value is Low. -
Output
Specifies the output container format. Can be either RAW (default) or ADTS. -
Bitrate
Sets the encoding bitrate in kbps. Default value is 128 kbps.
Constructor
The default constructor initializes the object with these settings:
- MPEG-4 version
- Low complexity object type
- 128 kbps bitrate
- RAW output format
Methods
-
GetInternalTypeVC()
Returns the internal video capture output format as VideoCaptureOutputFormat.M4A -
GetInternalTypeVE()
Returns the internal video edit output format as VideoEditOutputFormat.M4A -
Save()
Serializes the configuration to JSON format for storage or transmission -
Load(string json)
Static method that deserializes M4AOutput settings from a JSON string
Supporting Enumerations
AACVersion
Defines the MPEG version for the AAC stream:
MPEG4
(0): MPEG-4 AAC encodingMPEG2
(1): MPEG-2 AAC encoding
AACObject
Specifies the AAC encoder profile:
Undefined
(0): Reserved, should not be usedMain
(1): Main profile, highest complexityLow
(2): Low Complexity profile, good quality/complexity trade-offSSR
(3): Scalable Sample Rate profileLTP
(4): Long Term Prediction profile
AACOutput
Determines the output container format:
RAW
(0): Raw AAC bitstreamADTS
(1): Audio Data Transport Stream format
Usage Examples
Basic Configuration
var core = new VideoCaptureCore();
core.Mode = VideoCaptureMode.VideoCapture; // or VideoCaptureMode.ScreenCapture, VideoCaptureMode.IPCapture
core.Output_Filename = "output.m4a";
var output = new VisioForge.Core.Types.Output.M4AOutput
{
Bitrate = 192,
Version = AACVersion.MPEG4,
Object = AACObject.Low,
Output = AACOutput.ADTS
};
core.Output_Format = output;
Serialization Example
// Save configuration
string jsonConfig = output.Save();
// Load configuration
M4AOutput loadedOutput = M4AOutput.Load(jsonConfig);
Best Practices
-
Bitrate Selection
- For voice: 64-96 kbps is usually sufficient
- For music: 128-192 kbps provides good quality
- For high-quality music: Consider 256-320 kbps
-
Profile Selection
- Use
AACObject.Low
for most general-purpose encoding AACObject.Main
should be reserved for specific high-quality needs- Avoid
AACObject.Undefined
as it's not a valid encoding option
- Use
-
Container Format
- Use
AACOutput.ADTS
when compatibility with various players is needed - Use
AACOutput.RAW
when the AAC stream will be embedded in another container
- Use