Skip to main content

AVI file output

Products: Video Capture SDK .Net, Video Edit SDK .Net

AVI (Audio Video Interleave) was developed by Microsoft in 1992. AVI is a multimedia container format that stores both audio and video data in a single file. It supports synchronous audio-with-video playback. AVI files can contain both compressed and uncompressed data, offering flexibility but often resulting in large file sizes.

Cross-platform AVI output (X-engines: VideoCaptureCoreX, VideoEditCoreX, Media Blocks)

The AVIOutput class in VisioForge SDK provides a flexible way to configure and generate AVI video files with various video and audio encoding options. This guide will walk you through the setup and configuration of AVI output in your applications.

Basic Setup

To begin using AVI output, you'll first need to create an instance of the AVIOutput class by providing a target filename:

var aviOutput = new AVIOutput("output_video.avi");

The constructor automatically initializes default encoders:

  • Video: OpenH264 encoder
  • Audio: MP3 encoder

Video Encoding Configuration

The Video property allows you to configure video encoding settings. VisioForge supports multiple video encoders, each optimized for different use cases:

Available Video Encoders

  • OpenH264 - Open-source H.264 encoder, good for general use:
aviOutput.Video = new OpenH264EncoderSettings();
  • NVENC H.264/HEVC (NVIDIA GPU acceleration)
aviOutput.Video = new NVENCH264EncoderSettings();  // For H.264
// or
aviOutput.Video = new NVENCHEVCEncoderSettings(); // For HEVC
  • QSV H.264/HEVC (Intel Quick Sync acceleration)
aviOutput.Video = new QSVH264EncoderSettings();   // For H.264
// or
aviOutput.Video = new QSVHEVCEncoderSettings(); // For HEVC
  • AMF H.264/HEVC (AMD GPU acceleration)
aviOutput.Video = new AMFH264EncoderSettings();   // For H.264
// or
aviOutput.Video = new AMFHEVCEncoderSettings(); // For HEVC
  • MJPEG - Motion JPEG, suitable for high-quality, frame-by-frame encoding:
aviOutput.Video = new MJPEGEncoderSettings();

Audio Encoding Configuration

The Audio property lets you specify audio encoding settings. VisioForge.Core supports several audio encoders:

Available Audio Encoders

  • MP3 - Standard MP3 encoding:
aviOutput.Audio = new MP3EncoderSettings();
  • VO-AAC
aviOutput.Audio = new VOAACEncoderSettings();
  • AVENC AAC
aviOutput.Audio = new AVENCAACEncoderSettings();
  • MF AAC (Windows only)
aviOutput.Audio = new MFAACEncoderSettings();

Sample code

After configuring the AVI output, you can attach it to the VideoCaptureCoreX, VideoEditCoreX, or Media Blocks instance to start capturing video or editing media files:

Add the AVI output to the Video Capture SDK core instance:

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

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

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

Create a Media Blocks AVI output instance:

var aac = new VOAACEncoderSettings();
var h264 = new OpenH264EncoderSettings();
var aviSinkSettings = new AVISinkSettings("output.avi");
var aviOutput = new AVIOutputBlock(aviSinkSettings, h264, aac);

Advanced Features

File Management

You can get or set the output filename after initialization:

// Get current filename
string currentFile = aviOutput.GetFilename();

// Set new filename
aviOutput.SetFilename("new_output.avi");

Implementation Example

Here's a complete example showing how to configure AVI output with hardware acceleration and high-quality audio:

// Create AVI output with specified filename
var aviOutput = new AVIOutput("high_quality_output.avi");

// Configure hardware-accelerated NVIDIA H.264 encoding
aviOutput.Video = new NVENCH264EncoderSettings();

// Configure AAC audio encoding
aviOutput.Audio = new VOAACEncoderSettings();

Platform Considerations

Some encoders are platform-specific:

  • MF HEVC and MF AAC encoders are only available on Windows platforms
  • Hardware-accelerated encoders require appropriate GPU/hardware support

When developing cross-platform applications, ensure you check for encoder availability using the GetVideoEncoders() and GetAudioEncoders() methods to get the list of supported encoders for the current platform.

Best Practices

  1. Choose the Right Encoder:

    • For general use, OpenH264 provides good compatibility and quality
    • For performance-critical applications, use hardware-accelerated encoders when available
    • For maximum quality, consider using HEVC encoders
  2. Audio Encoding:

    • MP3 provides good compatibility and reasonable quality
    • AAC offers better quality at similar bitrates
    • Choose based on your target platform and quality requirements
  3. Error Handling:

    • Always verify encoder availability before use
    • Implement fallback options for platform-specific encoders

By following these guidelines and understanding the available options, you can effectively implement AVI output in your applications while maintaining high quality and performance.

Windows-only AVI output (VideoCaptureCore and VideoEditCore engines)

The same sample code can be used for Video Edit SDK .Net. Use the VideoEditCore class instead of VideoCaptureCore.

Create AVIOutput object

var aviOutput = new AVIOutput();

Set AVI settings using the settings dialog

var aviSettingsDialog = new AVISettingsDialog(
VideoCapture1.Video_Codecs.ToArray(),
VideoCapture1.Audio_Codecs.ToArray());

aviSettingsDialog.ShowDialog(this);

aviSettingsDialog.SaveSettings(ref aviOutput);

Or

Set AVI settings without using the settings dialog

Get lists of audio and video codecs, fill combo boxes

foreach (string codec in VideoCapture1.Video_Codecs)
{
cbVideoCodecs.Items.Add(codec);
}

foreach (string codec in VideoCapture1.Audio_Codecs)
{
cbAudioCodecs.Items.Add(codec);
}

Set video settings

aviOutput.Video_Codec = cbVideoCodecs.Text;

Set audio settings

aviOutput.ACM.Name = cbAudioCodecs.Text;
aviOutput.ACM.Channels = 2;
aviOutput.ACM.BPS = 16;
aviOutput.ACM.SampleRate = 44100;
aviOutput.ACM.UseCompression = true;

Apply settings

Set AVI format settings for output

VideoCapture1.Output_Format = aviOutput;

Set video capture mode

VideoCapture1.Mode = VideoCaptureMode.VideoCapture;

Set file name (be sure that you have to write access rights)

VideoCapture1.Output_Filename = "output.avi";

Start capture (sync or async)

await VideoCapture1.StartAsync();

Required redists

  • Video Capture SDK redist x86 x64
  • Video Edit SDK redist x86 x64

Visit our GitHub page to get more code samples.