Another nice feature of AVI Processor Add-on for Graphics Mill is a possibility to create new AVI files. Being highly integrated with Graphics Mill for .NET, AVI Processor Add-on can compose video data from instances of Aurigma.GraphicsMill.Bitmap class. This way you can use all power of Graphics Mill for .NET imaging features to create and pre-process video frames.
The main class you should use to create AVI files with AVI Processor Add-on is Aurigma.GraphicsMill.Codecs.AviWriter. Further, this class will be referred as AVI writer or merely - writer. It can be interpreted as a write-only collection: using the AddFrame(IFrame) method you put objects which implements the Aurigma.GraphicsMill.Codecs.IFrame interface (i.e. frames).
To add an audio data to the writer, an audio manager represented by the Aurigma.GraphicsMill.Codecs.AviAudioManager class is used. It enables you to add audio streams to the video movie. You can read about audio managers in the Working with Audio Track topic.
Also, the writer can use another handy class Aurigma.GraphicsMill.Codecs.AviWatermark which enables you to put watermarks on frames you add to the writer. You can access it through the Watermark property. Read more detailed about watermarks in the Working with Watermarks topic.
If you want to put transition effects between some frames, you should set the AviFrame.Transition property. Read more detailed about this in the Watermark property. Read more detailed about watermarks in the Working with Watermarks topic.
The writer object usage can be described with the following steps:
The order of actions listed above is important. E.g. if you open the writer object (using the Open method) before you initialize, say the compression type (using the CompressorHandler property), any attempts to change these settings will be disregarded.
Also, if you try to add audio data before you add all frames, you may get it truncated (depending on parameters). See the Working with Audio Track topic for more information about it.
Paragraphs below describe how to initialize parameters and add frames more detailed.
After you create an instance of the writer object, you should specify the parameters which will be used to create an AVI file. Each parameter is configured by an appropriate property of the writer object. In particular:
false
, frames are cropped to fit these dimensions.The code snippet below demonstrate how to initialize the writer:
Dim writer As New Aurigma.GraphicsMill.Codecs.AviWriter ' Specify dimensions and force all frames to be resized. writer.Width = 320 writer.Height = 200 writer.ResizeFrame = True ' Specify MPEG4 by XVID compression. Note, you should make sure that ' XVID is available on the machine where this code is running. writer.CompressorHandler = Aurigma.GraphicsMill.Codecs.AviCompressor.XvidMpeg4 ' Set MPEG4-related settings: writer.KeyFrameRate = 160 writer.BytesPerSecond = 128 writer.FramesPerSecond = 24 writer.Open("c:\temp\avioutput\temp.avi") ' ... all other code is skipped for brevity ...
Aurigma.GraphicsMill.Codecs.AviWriter writer = new Aurigma.GraphicsMill.Codecs.AviWriter(); // Specify dimensions and force all frames to be resized. writer.Width = 320; writer.Height = 200; writer.ResizeFrame = true; // Specify MPEG4 by XVID Compressor. Note, you should make sure that // XVID is available on the machine where this code is running. writer.CompressorHandler = Aurigma.GraphicsMill.Codecs.AviCompressor.XvidMpeg4; // Set MPEG4-related settings: writer.KeyFrameRate = 160; writer.BytesPerSecond = 128; writer.FramesPerSecond = 24; writer.Open(@"c:\temp\avioutput\temp.avi"); // ... all other code is skipped for brevity ...
You can have AVI Processor Add-on to open a dialog associated with a compressor so that the user could fill all parameters there. Use ShowOptionDialog and OptionsDialogParentHandle properties to do it. If you run this code:
Dim writer As New Aurigma.GraphicsMill.Codecs.AviWriter ' Settings which you will you set here are used as default ' values on the dialog writer.CompressorHandler = Aurigma.GraphicsMill.Codecs.AviCompressor.MsH263 writer.Quality = 8000 ' These two lines make AVI Processor to display the dialog ' If you do not initialize the parent handle, the dialog will be ' displayed as an independent window (it will be visible in Task Bar). writer.ShowOptionDialog = True writer.OptionsDialogParentHandle = Form1.Handle writer.Open("C:\Temp\writer.avi") writer.AddFrame(New Aurigma.GraphicsMill.Codecs.AviFrame( _ New Aurigma.GraphicsMill.Bitmap("c:\animated.gif"))) ' ... other frames are skipped for brevity ... writer.Close()
Aurigma.GraphicsMill.Codecs.AviWriter writer = new Aurigma.GraphicsMill.Codecs.AviWriter(); // Settings which you will set here are used as default // values on the dialog. writer.CompressorHandler = Aurigma.GraphicsMill.Codecs.AviCompressor.MSVideo1; writer.Quality = 9000; // These two lines make AVI Processor to display the dialog // If you do not initialize the parent handle, the dialog will be // displayed as an independent window (it will be visible in Task Bar). writer.ShowOptionDialog = true; writer.OptionsDialogParentHandle = form1.Handle; writer.Open(@"C:\Temp\writer.avi"); writer.AddFrame(new Aurigma.GraphicsMill.Codecs.AviFrame( new Aurigma.GraphicsMill.Bitmap(@"c:\animated.gif"))); // ... other frames are skipped for brevity ... writer.Close();
the following dialog will be opened:
As soon as you initialize the writer and call the Open method to get it opened, you can add frames. To do it, you should call the AddFrame(IFrame) method.
This method takes an object which implements Aurigma.GraphicsMill.Codecs.IFrame interface. You can get a frame in two ways:
Create new Aurigma.GraphicsMill.Codecs.AviFrame object and put the bitmap (an instance of Aurigma.GraphicsMill.Bitmap class) into it. You can do it in the following way:
' Load the image.jpg file and initialize a frame object with it. Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\image.jpg") Dim frame As New Aurigma.GraphicsMill.Codecs.AviFrame(bitmap) ' Put this frame to the writer object (it is assumed that the ' writer is properly initialized and opened). writer.AddFrame(frame)
// Load the image.jpg file and initialize a frame object with it. Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\image.jpg"); Aurigma.GraphicsMill.Codecs.AviFrame frame = new Aurigma.GraphicsMill.Codecs.AviFrame(bitmap); // Put this frame to the writer object (it is assumed that the // writer is properly initialized and opened). writer.AddFrame(frame);
Get a frame from a reader object. Note, it is not obligatory to use AVI reader. You can use a reader of any other format which is available in Graphics Mill for .NET. For example, you can open some multi-frame format file like animated GIF and convert it to AVI:
' Load the animated.gif file and copy its frames to AVI. Dim reader As Aurigma.GraphicsMill.Codecs.IFormatReader reader = Aurigma.GraphicsMill.Codecs.FormatManager.CreateFormatReader( _ "c:\animated.gif") Dim frame As Aurigma.GraphicsMill.Codecs.IFrame For Each frame In reader ' Put this frame to the writer object (it is assumed that the ' writer is properly initialized and opened). writer.AddFrame(frame) Next reader.Close()
// Load the animated.gif file and copy its frames to AVI. Aurigma.GraphicsMill.Codecs.IFormatReader reader; reader = Aurigma.GraphicsMill.Codecs.FormatManager.CreateFormatReader( @"c:\animated.gif"); foreach (Aurigma.GraphicsMill.Codecs.IFrame frame in reader) { // Put this frame to the writer object (it is assumed that the // writer is properly initialized and opened). writer.AddFrame(frame); } reader.Close();