Aurigma Graphics Mill 5.5 for .NET
Converting to AVI
Media Processor Add-on can be used only to read different kinds of media files; it cannot write them or convert to other formats. But if you have AVI Processor Add-on installed, you may use a combination of Media Processor Add-on (for reading files) and AVI Processor Add-on (for writing files) to convert your video to the AVI format.
The function that will convert video to the AVI format should perform the following operations:
- Create a reader with Media Processor Add-on and open the source file.
- Create a writer with AVI Processor Add-on but do not open the target file.
- Initialize the writer parameters. Note that the codec you specify should be already installed.
- Open the target file with the writer. It is important to do that after writer initialization.
- Loop through all frames in the reader, adding them to the writer.
- Close both the reader and the writer.
Visual Basic
Public Sub ConvertToAvi(ByVal inputFilename As String, ByVal outputFilename As _
String)
Try
'Create the reader
Dim reader As IFormatReader = MediaFormatManager.CreateFormatReader _
(inputFilename)
'Create the writer and initialize its parameters
Dim writer As AviWriter = New AviWriter
writer.Width = reader.LoadFrame(0).Width
writer.Height = reader.LoadFrame(0).Height
writer.CompressorHandler = AviCompressor.DefaultCompressorHandler
'Open the output file. Note that this should be done after writer
'initialization
writer.Open(outputFilename)
'Copy frames from the reader to the writer
Dim frame As IFrame
For Each frame In reader
writer.AddFrame(frame)
Next
writer.Close()
reader.Close()
Catch ex As Exception
Console.WriteLine(ex)
End Try
End Sub
C#
public static void ConvertToAvi(string inputFilename, string outputFilename)
{
try
{
//Create the reader
IFormatReader reader = MediaFormatManager.CreateFormatReader(inputFilename);
//Create the writer and initialize its parameters
AviWriter writer = new AviWriter();
writer.Width = reader.LoadFrame(0).Width;
writer.Height = reader.LoadFrame(0).Height;
writer.CompressorHandler = AviCompressor.DefaultCompressorHandler;
//Open the output file. Note that this should be done after writer
//initialization
writer.Open(outputFilename);
//Copy frames from the reader to the writer
foreach (IFrame frame in reader)
writer.AddFrame(frame);
writer.Close();
reader.Close();
}
catch (System.Exception ex)
{
Console.WriteLine(ex);
}
}