This documentation is for the old version. Go to the latest Graphics Mill docs

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:

  1. Create a reader with Media Processor Add-on and open the source file.
  2. Create a writer with AVI Processor Add-on but do not open the target file.
  3. Initialize the writer parameters. Note that the codec you specify should be already installed.
  4. Open the target file with the writer. It is important to do that after writer initialization.
  5. Loop through all frames in the reader, adding them to the writer.
  6. 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);
    }
}

See Also

Samples

Reference

Manual