FLAC Output
The FLACOutput
class provides functionality for configuring FLAC (Free Lossless Audio Codec) output in the VisioForge SDKs.
Cross-platform MP3 output (X-engines: VideoCaptureCoreX, VideoEditCoreX, Media Blocks)
// Create a new FLAC output instance
var flacOutput = new FLACOutput("output.flac");
// Configure FLAC encoder settings
flacOutput.Audio.CompressionLevel = 5; // Example setting
Filename
- Set the output filename during initialization or using the property
- Can also be accessed/modified using
GetFilename()
andSetFilename()
methods
// Set during initialization
var flacOutput = new FLACOutput("audio_output.flac");
// Or using the property
flacOutput.Filename = "new_output.flac";
Audio Settings
The Audio
property provides access to FLAC-specific encoding settings through the FLACEncoderSettings
class:
flacOutput.Audio = new FLACEncoderSettings();
// Configure specific FLAC encoding parameters here
Custom Audio Processing
You can set a custom audio processor using the CustomAudioProcessor
property:
flacOutput.CustomAudioProcessor = new CustomMediaBlock();
Implementation Notes
- The class implements multiple interfaces:
IVideoEditXBaseOutput
IVideoCaptureXBaseOutput
IOutputAudioProcessor
- Only FLAC audio encoding is supported (no video encoding capabilities)
- Default FLAC encoder settings are automatically created during initialization
Best Practices
- Always specify a valid output filename with the
.flac
extension - Configure any specific FLAC encoding settings before starting the encoding process
- If using custom audio processing, ensure the processor is properly configured before encoding
Example Implementation
Usage in Video Capture SDK:
var core = new VideoCaptureCoreX();
core.Outputs_Add(flacOutput, true);
Set the output format for the Video Edit SDK core instance:
var core = new VideoEditCoreX();
core.Output_Format = flacOutput;
Create a Media Blocks FLAC output instance:
var flacSettings = new FLACEncoderSettings();
var flacOutputBlock = new FLACOutputBlock("output.flac", flacSettings);
Windows-only engines (VideoCaptureCore/VideoEditCore)
The FLAC (Free Lossless Audio Codec) output settings class provides configuration options for FLAC audio encoding. These settings allow fine-tuning of the compression process to balance between compression ratio, encoding speed, and CPU usage.
Default Configuration
When instantiated, the FLACOutput class uses these default values:
- Level: 5
- Rice Min/Max: 3
- LPC Order: 8
- Block Size: 4608
Compression Level
public int Level { get; set; }
Default Value: 5
Valid Range: 0-8
- 0: Fastest compression
- 8: Highest compression This setting provides a simple way to control the trade-off between encoding speed and compression ratio.
Block Size
public int BlockSize { get; set; }
Default Value: 4608
Valid Values for Subset Streams:
- For sample rates ≤ 48kHz: 192, 256, 512, 576, 1024, 1152, 2048, 2304, 4096, 4608
- For sample rates > 48kHz: Additionally supports 8192, 16384
Specifies the size of each processing block in samples. The encoder uses the same block size throughout the entire stream. Larger block sizes can improve compression but require more memory and processing time.
Mid-Side Coding
public bool MidSideCoding { get; set; }
Default Value: false
Enables mid-side coding for stereo streams. This feature typically increases compression by a few percent by encoding:
- A mid channel (average of left and right)
- A side channel (difference between left and right)
The encoder will encode both the standard stereo pair and mid-side versions, using whichever produces the smaller frame.
Adaptive Mid-Side Coding
public bool AdaptiveMidSideCoding { get; set; }
Default Value: false
A faster alternative to full mid-side coding for stereo streams. The encoder dynamically switches between:
- Independent channel coding
- Mid-side coding
While faster than full mid-side coding, it typically achieves less compression.
LPC Order
public int LPCOrder { get; set; }
Default Value: 8
Constraints:
- Maximum value: 32
- For subset streams ≤ 48kHz: Maximum value is 12
Specifies the maximum Linear Predictive Coding order. Higher orders can achieve better compression but require more processing time. Setting to 0 disables generic linear prediction, using only fixed predictors, which:
- Increases encoding speed
- Typically results in 5-10% larger files
Exhaustive Model Search
public bool ExhaustiveModelSearch { get; set; }
Default Value: false
Enables comprehensive testing of all possible encoding models:
- Generates subframes for every order
- Uses the smallest resulting frame
- Can improve compression by ~0.5%
- Significantly increases encoding time with high LPC orders
Rice Parameters
public int RiceMin { get; set; }
public int RiceMax { get; set; }
Default Values: 3 (both)
Controls residual partition order for Rice coding:
- Residual is partitioned into 2^min to 2^max pieces
- Each piece gets its own Rice parameter
- Higher max values give diminishing returns
- Optimal results often achieved with min=2, max=2
- Typically improves compression by ~1.5%
- Peak efficiency occurs when blocksize/(2^n)≈128
- Use min=0, max=15 for maximum optimization
Serialization
The class supports JSON serialization and deserialization:
// Save settings to JSON
string jsonSettings = flacOutput.Save();
// Load settings from JSON
FLACOutput loadedSettings = FLACOutput.Load(jsonString);
Apply settings to core instances
var core = new VideoCaptureCore();
var flacOutput = new FLACOutput();
core.Output_Filename = "output.flac";
core.Output_Format = flacOutput;
var core = new VideoEditCore();
var flacOutput = new FLACOutput();
core.Output_Filename = "output.flac";
core.Output_Format = flacOutput;
Best Practices
-
Start with default settings for general use
-
For maximum compression:
- Set Level to 8
- Enable ExhaustiveModelSearch
- Enable MidSideCoding for stereo
- Increase LPCOrder (consider performance impact)
-
For faster encoding:
- Lower Level (0-3)
- Use AdaptiveMidSideCoding instead of MidSideCoding
- Keep LPCOrder at default or lower
- Disable ExhaustiveModelSearch
-
For subset streams:
- Ensure BlockSize matches allowed values
- Keep LPCOrder ≤ 12 for sample rates ≤ 48kHz