IC Imaging Control ActiveX

Capturing an AVI File

Capturing an AVI File

This chapter shows you how to save a video stream as a compressed AVI file.

To see how to save video streams in different file formats, see the Capturing a Video File example.

The source code for this sample program can be found in the samples\VB6\Capturing an AVI File directory.

Setting up the Project

Create a new project and add IC Imaging Control to the form. Before you run the program, select the video capture device, input and video format as shown in the FirstSteps chapter. Alternatively, run the program without selecting a device. In this case, the program shows the device selection dialog provided by IC Imaging Control. If you close this dialog without having first made a selection, the program will display an error message and terminate.

Now add 3 buttons to the form and label them Start Live, Stop Live and Capture AVI. Name the buttons cmdStartLive, cmdStopLive and cmdCaptureVideo respectively.

Add calls to IC Imaging Control's LiveStart and LiveStop methods:

Private Sub cmdStartLive_Click()
    ICImagingControl1.LiveStart
End Sub
Private Sub cmdStopLive_Click()
    ICImagingControl1.LiveStop
End Sub

Run the program. You can now start and stop the live image by clicking on the respective buttons. This does not yet create an AVI file, but is required to create a preview for the live video stream. This is usually required to set up the camera before actually starting to record.

image

The AVI Recording Dialog

Now add another form to your project. Name it frmWriteAVI. Add a combo box for the available video codecs, a text box for the AVI filename, and buttons to start and stop AVI capture. (You may want to load the sample project instead of creating the form manually).

image

In the FormLoad event, the selection list is filled with the names of all video codecs installed on your computer. These can be used as an AVI compressor.

Private Sub Form_Load()
    Dim Codec As AviCompressor

    ' Fill the combobox "cboVideoCodec" with the available
    ' avi compressors (codecs).
    For Each Codec In ImagingControl.AviCompressors
        cboVideoCodec.AddItem Codec.Name
    Next
    cboVideoCodec.ListIndex = 0
    If ImagingControl.LiveCapturePause = True Then
        chkPause.Value = 1
    Else
        chkPause.Value = 0
    End If

End Sub

The Click event of the Start Capture button calls IC Imaging Control's AviStartCapture method, with the filename and the name of the video codec as a parameter. There is also some code to disable the Close button and enable the Stop Capture button and to check whether the user has selected a codec and a filename:

Private Sub cmdStartCapture_Click()
    If cboVideoCodec.Text = "" Then
        MsgBox "Please select a video codec first.", vbExclamation + vbOKOnly
    ElseIf txtFilename.Text = "" Then
        MsgBox "Please select an AVI filename first.", vbExclamation + vbOKOnly
    End If

    If cboVideoCodec.Text <> "" And txtFilename.Text <> "" Then
        ImagingControl.AviStartCapture txtFilename, cboVideoCodec.Text
        cmdStartCapture.Enabled = False
        cmdStopCapture.Enabled = True
        cmdClose.Enabled = False
    End If
End Sub

The Pause button is a check box with a graphical style. It is used to set and reset the LiveCapturePause property of IC Imaging Control. If the LiveCapturePause property is set to True, AVI capture is paused. This means, that only the sink path of the image stream is paused. The live video is still displayed, but the video is not saved to the video file. If the LiveCapturePause property is set to False, IC Imaging Control immediately continues AVI capture. A previously started AVI file will be continued.

Private Sub chkPause_Click()
    If chkPause.Value = 1 Then
        ImagingControl.LiveCapturePause = True
    Else
        ImagingControl.LiveCapturePause = False
    End If
End Sub

The AVI capture can be started by a call to AviStartCapture, even if the LiveCapturePause property is set to True. In this case, the image stream is initialized and started and the live video is displayed. The images are not saved to the AVI file because the sink path is paused. As soon as the LiveCapturePause property is set to False, the sink path is started and images are written to the AVI file. The advantage of this is that the AVI capturing can be started, paused and restarted immediately on an event.

Finished. You can now run the program, select a codec, and create an AVI file. Note that compressing a video stream is a highly CPU intensive operation and not all codecs will be able to work at full image resolution and full frame rate.

<< Programmer's Guide

Get in touch with us


About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us