# AAC encoder

Video Capture SDK .Net Video Edit SDK .Net Media Blocks SDK .Net

The VisioForge SDK provides several AAC encoder implementations, each with unique characteristics and use cases.

# Cross-platform M4A (AAC) output

VideoCaptureCoreX VideoEditCoreX MediaBlocksPipeline

This guide will explore the four primary AAC encoder types:

  1. AVENC AAC Encoder
  2. VO-AAC Encoder
  3. Media Foundation AAC Encoder (used in Windows-only engines)

# AVENC AAC Encoder

The AVENC AAC Encoder offers the most comprehensive configuration options for audio encoding. It provides advanced settings for stereo coding, prediction, and noise shaping.

# Key Features

  • Multiple coder strategies
  • Configurable stereo coding
  • Advanced noise and prediction techniques

# Coder Strategies

The AVENC AAC Encoder supports three coder strategies:

  • ANMR: Advanced noise modeling and reduction method
  • TwoLoop: Two-loop searching method for optimization
  • Fast: Default fast search algorithm (recommended for most use cases)

# Sample Configuration

var aacSettings = new AVENCAACEncoderSettings
{
    Coder = AVENCAACEncoderCoder.Fast,
    Bitrate = 192,
    IntensityStereo = true,
    ForceMS = true,
    TNS = true
};

# Supported Parameters

  • Bitrates: 0, 32, 64, 96, 128, 160, 192, 224, 256, 320 kbps
  • Sample Rates: 7350 to 96000 Hz
  • Channels: 1 to 6 channels

# VO-AAC Encoder

The VO-AAC Encoder is a more streamlined encoder with simpler configuration options.

# Key Features

  • Simplified configuration
  • Straightforward bitrate and sample rate controls
  • Limited to stereo audio

# Sample Configuration

var aacSettings = new VOAACEncoderSettings
{
    Bitrate = 128
};

# Supported Parameters

  • Bitrates: 32, 64, 96, 128, 160, 192, 224, 256, 320 kbps
  • Sample Rates: 8000 to 96000 Hz
  • Channels: 1-2 channels

# Media Foundation AAC Encoder (Windows Only)

This encoder is specific to Windows platforms and offers a limited but performance-optimized encoding solution.

# Key Features

  • Windows-specific implementation
  • Predefined bitrate options
  • Limited sample rate support

# Supported Parameters

  • Bitrates: 0 (Auto), 96, 128, 160, 192, 576, 768, 960, 1152 kbps
  • Sample Rates: 44100, 48000 Hz
  • Channels: 1, 2, 6 channels

# Encoder Availability and Selection

Each encoder provides a static IsAvailable() method to check if the encoder can be used in the current environment. This is useful for runtime compatibility checks.

if (AVENCAACEncoderSettings.IsAvailable())
{
    // Use AVENC AAC Encoder
}
else if (VOAACEncoderSettings.IsAvailable())
{
    // Fallback to VO-AAC Encoder
}

# Rate Control Considerations

  1. AVENC AAC Encoder:

    • Most flexible rate control
    • Supports constant bitrate (CBR)
    • Multiple encoding strategies affect quality and performance
  2. VO-AAC Encoder:

    • Simple constant bitrate control
    • Recommend for straightforward encoding needs
    • Limited advanced configuration
  3. Media Foundation Encoder:

    • Limited to predefined bitrates
    • Good for quick Windows-based encoding
    • Auto bitrate option available

# Recommendations

  • For advanced audio encoding with maximum control, use AVENC AAC Encoder
  • For simple, cross-platform encoding, use VO-AAC Encoder
  • For Windows-specific, optimized encoding, use Media Foundation Encoder

# Performance and Quality Considerations

  • Higher bitrates generally mean better audio quality
  • Choose sample rates matching your source audio
  • Consider your target platform and audience when selecting an encoder

# Sample Code

# Windows-only AAC output

VideoCaptureCore VideoEditCore

M4AOutput is the primary class for configuring M4A (AAC) output settings. It implements both IVideoEditBaseOutput and IVideoCaptureBaseOutput interfaces.

# Properties

Property Type Description Default Value
Version AACVersion Specifies the AAC version (MPEG-2 or MPEG-4) MPEG4
Object AACObject Defines the AAC object type Low
Output AACOutput Sets the AAC output mode RAW
Bitrate int Specifies the AAC bitrate in kbps 128

# Methods

# GetInternalTypeVC()

  • Returns: VideoCaptureOutputFormat.M4A
  • Purpose: Gets the internal output format for video capture

# GetInternalTypeVE()

  • Returns: VideoEditOutputFormat.M4A
  • Purpose: Gets the internal output format for video editing

# Save()

  • Returns: JSON string representation of the M4AOutput object
  • Purpose: Serializes the current configuration to JSON

# Load(string json)

  • Parameters: JSON string containing M4AOutput configuration
  • Returns: New M4AOutput instance
  • Purpose: Creates a new M4AOutput instance from JSON configuration

# Supporting Enums

# AACVersion

Defines the version of AAC to be used:

Value Description
MPEG4 MPEG-4 AAC (default)
MPEG2 MPEG-2 AAC

# AACObject

Specifies the AAC encoder stream object type:

Value Description
Undefined Not to be used
Main Main profile
Low Low Complexity profile (default)
SSR Scalable Sample Rate profile
LTP Long Term Prediction profile

# AACOutput

Determines the AAC encoder stream output type:

Value Description
RAW Raw AAC stream (default)
ADTS Audio Data Transport Stream format

# Usage Example

// Create new M4A output configuration
var m4aOutput = new M4AOutput
{
    Version = AACVersion.MPEG4,
    Object = AACObject.Low,
    Output = AACOutput.RAW,
    Bitrate = 192
};

core.Output_Format = m4aOutput; // core is an instance of VideoCaptureCore or VideoEditCore

# Best Practices

  1. Bitrate Selection

    • Choose appropriate bitrate based on quality requirements
    • Standard bitrates: 96-320 kbps
    • Default: 128 kbps (good balance of quality and file size)
  2. AAC Object Type

    • Use Low (LC) profile for most applications
    • Main profile for higher quality requirements
    • Avoid Undefined
  3. Version Selection

    • MPEG4 recommended for better compatibility
    • Use MPEG2 only for legacy system requirements
  4. Output Format

    • RAW: For system-level integration
    • ADTS: Better for streaming and compatibility