Save a Time-Limited AVI File Short source code snippet that illustrates how to save an image data stream as a time-limited AVI file.
Language: | .NET C#/Visual Basic
Version: | 3.3
Author: | IC Imaging Control Support Department
Requirements: |
Software: | IC Imaging Control 3.3, Visual Studio™ 2010
Hardware: | Camera, converter or grabber with WDM Stream Class drivers.
Download C# sample | Save AVI with timed stop - C#

The window of the resulting application looks as follows:

The program starts by opening a built-in dialog that allows the end user to select a video capture device (.ShowDeviceSettingsDialog). Then, this live image data stream from the video capture device is displayed, using .LiveStart:

    C#

    private void Form1_Load(object sender, System.EventArgs e)
    {
        icImagingControl1.ShowDeviceSettingsDialog();

        if( !icImagingControl1.DeviceValid )
        {
            Close();
            return;
        }

        icImagingControl1.LiveStart();
    }

When the user clicks "Start Capture", the program stops the image data stream (.LiveStop) and starts recording the AVI file and a timer (.AviStartCapture, Timer1.Enabled = True):

    C#

    private void btnStartCapture_Click(object sender, System.EventArgs e)
    {
        icImagingControl1.LiveStop();
        icImagingControl1.AviStartCapture( "video.avi", "DV Video Encoder" );
        btnStartCapture.Enabled = false;

        recordedTime = 0;
        recordTimer.Start();
    }

The AVI recording is controlled by a timer. The event handler Timer1_Timer() is polled periodically, by the timer Timer1. Its actions are as follows:

- Read the recording time, as defined by the user (txtStop.Text)
- Indicate the expired time (lblRecorded.Text)
- Terminate the recording after the expiration of the defined time (.AviStopCapture)
- Restart the live image data stream (.LiveStart)

    C#

    int recordedTime = 0;

    private void recordTimer_Tick(object sender, System.EventArgs e)
    {
        recordedTime += 1;
        lblRecordedTime.Text = recordedTime.ToString() + "s";

        if( recordedTime >= int.Parse( txtStopTime.Text ) )
        {
            recordTimer.Stop();

            icImagingControl1.AviStopCapture();
            icImagingControl1.LiveStart();
            btnStartCapture.Enabled = true;
        }
    }