# OGG Vorbis Output

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

Vorbis is a popular open-source audio compression format known for its excellent sound quality and efficiency. OGG is a container format that can hold Vorbis-encoded audio streams.

# Cross-platform MP3 output

VideoCaptureCoreX VideoEditCoreX MediaBlocksPipeline

The OGGVorbisOutput class in VisioForge SDK provides a simple way to create OGG Vorbis audio files in your .NET applications.

# Basic Implementation

// Create a new OGG Vorbis output instance
var oggOutput = new OGGVorbisOutput("output.ogg");

The constructor requires a filename parameter that specifies where the encoded audio file will be saved.

# Configuring Audio Settings

The OGGVorbisOutput class provides access to Vorbis encoder settings through its Audio property. This property is automatically initialized with default values when you create a new instance. You can customize these settings as follows:

// Access and modify Vorbis encoder settings
oggOutput.Audio.Quality = 0.8f;  // Set quality (0.0 to 1.0)
oggOutput.Audio.Channels = 2;    // Set number of channels

# Example Implementation

Here's a complete example showing how to set up MP3 output:

var core = new VideoCaptureCoreX();
core.Outputs_Add(oggOutput, true);

Set the output format for the Video Edit SDK core instance:

var core = new VideoEditCoreX();
core.Output_Format = oggOutput;

Create a Media Blocks MOV output instance:

var vorbisSettings = new VorbisEncoderSettings();
var oggOutputBlock = new OGGVorbisOutputBlock("output.ogg", vorbisSettings);

# Advanced Features

# Custom Audio Processing

The OGGVorbisOutput class supports custom audio processing through its CustomAudioProcessor property. This allows you to implement specialized audio processing before encoding:

// Add a custom audio processor
oggOutput.CustomAudioProcessor = new MyCustomAudioProcessor();

# Interface Implementation

The OGGVorbisOutput class implements several important interfaces:

  • IVideoEditXBaseOutput: Enables integration with video editing workflows
  • IVideoCaptureXBaseOutput: Supports video capture scenarios
  • IOutputAudioProcessor: Provides audio processing capabilities

# File Management

The class provides methods for managing output files:

// Get the current output filename
string currentFile = oggOutput.GetFilename();

// Change the output filename
oggOutput.SetFilename("new_output.ogg");

# Supported Encoders

While OGG Vorbis is primarily an audio format, the class maintains compatibility with VisioForge's video infrastructure. You can query available encoders:

// Get available audio encoders
var audioEncoders = oggOutput.GetAudioEncoders();

# Best Practices

When working with OGG Vorbis output:

  1. Always specify a valid output filename with the ".ogg" extension
  2. Consider your quality settings carefully - higher quality means larger file sizes
  3. Initialize custom audio processors before starting the encoding process
  4. Handle file paths appropriately to avoid access permission issues
  5. Test encoding with different quality settings to find the optimal balance for your use case

# Common Use Cases

The OGG Vorbis output is particularly useful for:

  • Creating high-quality audio archives with efficient compression
  • Streaming applications where bandwidth efficiency is important
  • Projects requiring open-source audio formats
  • Applications needing to balance audio quality with file size

# Windows-only output

VideoCaptureCore VideoEditCore

The OGGVorbisOutput class provides configuration and functionality for encoding audio using the Vorbis codec.

# Class Details

public sealed class OGGVorbisOutput : IVideoEditBaseOutput, IVideoCaptureBaseOutput

The class implements two interfaces:

  • IVideoEditBaseOutput: Enables use in video editing scenarios
  • IVideoCaptureBaseOutput: Enables use in video capture scenarios

# Bitrate Controls

When operating in Bitrate mode, these properties control the output bitrate constraints:

# AvgBitRate

  • Type: int
  • Default Value: 128 (Kbps)
  • Description: Specifies the target average bitrate for the encoded audio stream. This value represents the general quality level and file size trade-off.

# MaxBitRate

  • Type: int
  • Default Value: 192 (Kbps)
  • Description: Defines the maximum allowed bitrate during encoding. Useful for ensuring the encoded audio doesn't exceed bandwidth constraints.

# MinBitRate

  • Type: int
  • Default Value: 64 (Kbps)
  • Description: Sets the minimum allowed bitrate during encoding. Helps maintain a baseline quality level even during simple audio passages.

# Quality Controls

# Quality

  • Type: int
  • Default Value: 80
  • Valid Range: 10-100
  • Description: When operating in Quality mode, this value determines the encoding quality. Higher values result in better audio quality but larger file sizes.

# Mode

  • Type: VorbisMode (enum)
  • Default Value: VorbisMode.Bitrate
  • Options:
    • VorbisMode.Quality: Encoding focuses on maintaining a consistent quality level
    • VorbisMode.Bitrate: Encoding focuses on maintaining specified bitrate constraints

# Constructor

public OGGVorbisOutput()

Initializes a new instance with default values:

  • MinBitRate: 64 kbps
  • AvgBitRate: 128 kbps
  • MaxBitRate: 192 kbps
  • Quality: 80
  • Mode: VorbisMode.Bitrate

# Serialization Methods

# Save()

public string Save()

Serializes the current configuration to a JSON string, allowing settings to be saved and restored later.

# Load(string json)

public static OGGVorbisOutput Load(string json)

Creates a new instance with settings deserialized from the provided JSON string.

# Usage Examples

# Basic Usage with Default Settings

var oggOutput = new OGGVorbisOutput();
// Ready to use with default settings (Bitrate mode, 128kbps average)

# Quality-Based Encoding

var oggOutput = new OGGVorbisOutput
{
    Mode = VorbisMode.Quality,
    Quality = 90  // High quality setting
};

# Constrained Bitrate Encoding

var oggOutput = new OGGVorbisOutput
{
    Mode = VorbisMode.Bitrate,
    MinBitRate = 96,    // Minimum 96kbps
    AvgBitRate = 160,   // Target 160kbps
    MaxBitRate = 240    // Maximum 240kbps
};

# Saving and Loading Configuration

// Save configuration
var oggOutput = new OGGVorbisOutput();
string savedConfig = oggOutput.Save();
// Load configuration
var loadedOutput = OGGVorbisOutput.Load(savedConfig);

# Apply settings to core instances

var core = new VideoCaptureCore();
core.Output_Filename = "output.ogg";
core.Output_Format = oggOutput;
var core = new VideoEditCore();
core.Output_Filename = "output.ogg";
core.Output_Format = oggOutput;

# Best Practices

  1. Quality vs Bitrate Mode Selection

    • Use Quality mode when file size is not a primary concern
    • Use Bitrate mode when you need to target specific file sizes or streaming requirements
  2. Bitrate Configuration

    • Keep MinBitRate ≥ 50% of AvgBitRate for stable quality
    • Set MaxBitRate ≤ 200% of AvgBitRate to prevent excessive fluctuations
  3. Quality Settings

    • Values 70-85 provide a good balance of quality and file size
    • Values 90 and above offer diminishing returns in perceived quality
    • Values less than 60 may result in noticeable quality degradation

# Performance Considerations

  • Higher quality settings and bitrates will increase encoding time
  • Bitrate mode may use more CPU resources than Quality mode
  • Consider using lower quality settings for real-time encoding scenarios