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

Putting Logo on AVI File

It is often needed to place your logo on AVI file. For example, you want to inform customers that the video was produced by your company. AVI Processor Add-on for Graphics Mill can make a great help for this purpose. This article describes how to implement it.

The simplest method is to place a static transparent picture onto your video file. You just need to fulfill several steps:

  1. Create the reader and writer objects for reading/writing AVI files.

  2. Load necessary logo to the watermark object returned from the writer.

  3. Copy frames from reader to writer. The logo will be automatically drawn on each frame.

  4. Close reader and writer objects.

The code snippet below demonstrates how to put logo onto AVI file:

Visual Basic
Public Shared Sub PutLogo(ByVal inputFilename As String, _
    ByVal outputFilename As String, _
    ByVal logoFilename As String)

    ' Create the reader and the writer objects that
    ' are used to read and write AVI files.
    Dim reader As New Aurigma.GraphicsMill.Codecs.AviReader(inputFilename)
    Dim writer As New Aurigma.GraphicsMill.Codecs.AviWriter

    ' Copy settings from the reader to the writer.
    writer.FramesPerSecond = reader.FramesPerSecond
    writer.CompressorHandler = reader.CompressorHandler
    writer.Quality = reader.Quality

    ' Open the reader and the writer to be able to read/write data 
    ' from files.
    writer.Open(outputFilename)

    ' Enable the bitmap watermark and load the necassary logo 
    writer.Watermark.BitmapVisible = True
    writer.Watermark.Bitmap = New Aurigma.GraphicsMill.Bitmap("C:\Temp\Bitmap_Logo.gif")

    ' Now during each AddFrame method call the logo will be
    ' automatically drawn on the frame. 
    Dim frame As Aurigma.GraphicsMill.Codecs.IFrame
    For Each frame In reader
        writer.AddFrame(frame)
    Next

    ' Cleanup
    writer.Close()
    reader.Close()

End Sub
C#
public static void PutLogo(string inputFilename, 
    string outputFilename, 
    string logoFilename)
{
    // Create the reader and the writer objects that
    // are used to read and write AVI files.
    Aurigma.GraphicsMill.Codecs.AviReader reader = 
        new Aurigma.GraphicsMill.Codecs.AviReader(inputFilename);
    Aurigma.GraphicsMill.Codecs.AviWriter writer = 
        new Aurigma.GraphicsMill.Codecs.AviWriter();
    
    // Copy settings from the reader to the writer.
    writer.FramesPerSecond = reader.FramesPerSecond;
    writer.CompressorHandler = reader.CompressorHandler;
    writer.Quality = reader.Quality;

    // Open the reader and the writer to be able to read/write data 
    // from files.
    writer.Open(outputFilename);
    reader.Open(inputFilename);

    // Enable the bitmap watermark and load the necassary logo 
    writer.Watermark.BitmapVisible = true;
    writer.Watermark.Bitmap = new Aurigma.GraphicsMill.Bitmap(@"C:\Temp\Bitmap_Logo.gif");

    // Now during each AddFrame method call the logo will be
    // automatically drawn on the frame. 
    foreach (Aurigma.GraphicsMill.Codecs.IFrame frame in reader)
    {
        writer.AddFrame(frame);
    }

    // Cleanup
    writer.Close();
    reader.Close();
}                                            

Let's consider more complicated example. Assume that you want to put animated GIF logo on AVI file. The idea is the same as for static picture but in addition you need to change frames of the animated logo and synchronize them with the frames of the video file.

Follow these steps to put an animated logo on AVI file:

  1. Create the reader and writer objects for reading/writing AVI files.

  2. Create the GIF reader for reading your logo.

  3. Copy frames from reader to writer. For each frame do the following:

    1. Determine what a logo frame corresponds to the current video frame and load it.

    2. Get the bitmap from the logo frame.

    3. Put the logo bitmap into the watermark object of the writer.

  4. Close the reader and writer objects.

Keep in mind that the animated logo should be synchronized with the AVI file. In order to define what logo frame corresponds to the current video frame we should take into account the logo frame delay stored in the GIF file. For this purpose we compare the current time of the video frame to the logo frame delay. In case the current time of the video frame exceeds the latter increase the time counter by the delay and change the logo frame to the next one.

The code snippet below shows how to put the animated GIF logo onto the AVI file:

Visual Basic
Public Shared Sub PutAnimatedLogo(ByVal inputFilename As String, _
    ByVal outputFilename As String, _
    ByVal logoFilename As String)

    ' Create the reader and the writer objects that
    ' are used to read and write AVI files.
    Dim reader As New Aurigma.GraphicsMill.Codecs.AviReader(inputFilename)
    Dim writer As New Aurigma.GraphicsMill.Codecs.AviWriter

    ' Create the reader that will be used for reading animated Gif.
    Dim logoReader As New Aurigma.GraphicsMill.Codecs.GifReader(logoFilename)

    ' Copy settings from the reader to the writer.
    writer.FramesPerSecond = reader.FramesPerSecond
    writer.CompressorHandler = reader.CompressorHandler
    writer.Quality = reader.Quality

    ' Open the the writer to be able to write data from files.
    writer.Open(outputFilename)

    Dim logoFrame As Aurigma.GraphicsMill.Codecs.GifFrame
    writer.Watermark.Bitmap = New Aurigma.GraphicsMill.Bitmap
    writer.Watermark.BitmapVisible = True

    ' To synchronize the speed of the animated Gif on the video movie
    ' use time counter (t), which will be used to determine whether to
    ' switch the frame index of the logo (logoIndex).
    Dim I As Integer
    Dim t As Integer = 0
    Dim logoIndex As Integer = 0

    ' This code gets the bitmap from the frame of the logo GIF file and 
    ' uses it as watermark (through the Watermark property of the writer).
    Dim frame As Aurigma.GraphicsMill.Codecs.IFrame
    For Each frame In reader

        ' Compare the current time of the video frame to 
        ' the logo frame time counter. If the current time
        ' exceeds the time counter, it means that it is a time to 
        ' change the logo frame to the next one.
        If t <= writer.FrameIndexToTime(frame.Index) Then

            ' Load the logo frame and use it as watermark.
            logoFrame = logoReader.LoadFrame(logoIndex)
            logoFrame.GetBitmap(writer.Watermark.Bitmap)

            ' Increase the time counter by the logo frame delay
            ' and switch the logo frame to the next one. 
            t += logoFrame.Delay
            logoIndex = logoIndex + 1

            ' When the last frame of the animated logo have been displayed
            ' start displaying frames from the beginning. 
            If (logoIndex = logoReader.FrameCount) Then

                logoIndex = 0

            End If
        End If

        ' Add the frame from the reader to the writer.
        writer.AddFrame(frame)
    Next

    ' Add the audio track from the reader to the writer.
    For I = 0 To reader.AudioManager.AudioStreamCount - 1

        writer.AudioManager.AddAudioStream(reader.AudioManager, I, False)

    Next

    ' Cleanup
    writer.Close()
    reader.Close()
    logoReader.Close()

End Sub
C#
public static void PutAnimatedLogo(string inputFilename, 
    string outputFilename, 
    string logoFilename)
{
    // Create the reader and the writer objects that
    // are used to read and write AVI files.
    Aurigma.GraphicsMill.Codecs.AviReader reader = 
        new Aurigma.GraphicsMill.Codecs.AviReader(inputFilename);
    Aurigma.GraphicsMill.Codecs.AviWriter writer = 
        new Aurigma.GraphicsMill.Codecs.AviWriter();

    // Create the reader that will be used for reading animated Gif.
    Aurigma.GraphicsMill.Codecs.GifReader logoReader = 
        new Aurigma.GraphicsMill.Codecs.GifReader(logoFilename);

    // Copy settings from the reader to the writer.
    writer.FramesPerSecond = reader.FramesPerSecond;
    writer.CompressorHandler = reader.CompressorHandler;
    writer.Quality = reader.Quality;
    
    // Open the reader and the writer to be able to read/write data 
    // from files.
    writer.Open(outputFilename);
    reader.Open(inputFilename);

    Aurigma.GraphicsMill.Codecs.GifFrame logoFrame;
    writer.Watermark.Bitmap = new Aurigma.GraphicsMill.Bitmap();
    writer.Watermark.BitmapVisible = true;

    // To synchronize the speed of the animated Gif on the video movie
    // use time counter (t), which will be used to determine whether to
    // switch the frame index of the logo (logoIndex).
    int t = 0;
    int logoIndex = 0;

    // This code gets the bitmap from the frame of the logo GIF file and 
    // uses it as watermark (through the Watermark property of the writer).
    foreach (Aurigma.GraphicsMill.Codecs.IFrame frame in reader) 
    {        
        // Compare the current time of the video frame to 
        // the logo frame time counter. If the current time
        // exceeds the time counter, it means that it is a time to 
        // change the logo frame to the next one.
        if (t <= writer.FrameIndexToTime(frame.Index))
        {
            // Load the logo frame and use it as watermark.
            logoFrame = (Aurigma.GraphicsMill.Codecs.GifFrame)
                logoReader.LoadFrame(logoIndex);
            logoFrame.GetBitmap(writer.Watermark.Bitmap);

            // Increase the time counter by the logo frame delay
            // and switch the logo frame to the next one. 
            t += logoFrame.Delay;
            logoIndex++;
            
            // When the last frame of the animated logo have been displayed
            // start displaying frames from the beginning. 
            if (logoIndex == logoReader.FrameCount)
            {
                logoIndex = 0;
            }
        }
        
        // Add the frame from the reader to the writer.
        writer.AddFrame(frame);
    }

    // Add the audio track from the reader to the writer.
    for (int i=0;i<reader.AudioManager.AudioStreamCount;i++)
    {
        writer.AudioManager.AddAudioStream(reader.AudioManager, i, false);
    }
    
    // Cleanup
    writer.Close();
    reader.Close();
    logoReader.Close();            
}

See Also

Manual