Acquire Video Format Information

This example demonstrates how to acquire information about the available video formats.

The program can be found in the %TOPLEVEL%\Samples\VC71\VideoNormFormat directory. A VC6 version can be found in the directory %TOPLEVEL%\Samples\VC6. In order to run the program, open the solution file VidNormFormat.sln in this directory and select Build -> Build VideoNormFormat in the menu. Then the program can be executed by selecting Debug -> Start.

Opening a Device

The program will generate a list of all available video capture devices and prompt the user for the device to open.

Grabber::tVidCapDevListPtr pVidCapDevList = grabber.getAvailableVideoCaptureDevices();
if( pVidCapDevList == 0 || pVidCapDevList->empty() )
{
    return -1; // No device available.
}
 
int choice = presentUserChoice( toStringArrayPtr( pVidCapDevList ) );
// Open the selected video capture device.
if( choice == -1 )
{
    return -1;
}
grabber.openDev( pVidCapDevList->at( choice ) );

First, Grabber::getAvailableVideoCaptureDevices is called to retrieve a list with the video capture devices connected to the computer. The helper function presentUserChoice from %TOPLEVEL%\Samples\VC71\Common\CmdHelper.h is called to output the available devices to the console and let the user input a number.

The selected video capture device is opened by calling Grabber::openDev.

Selecting a Video Norm

If the selected device supports multiple video norms, all available video norms will be printed to the screen and the user will be asked for a norm. If the user selects a norm, all video formats available for the selected norm are printed on the screen and the user is again prompted for a video norm until he terminates the program by pressing "q".

// Check whether video norms are available with the current video capture device.
if( grabber.isVideoNormAvailableWithCurDev() )
{
    // Query for all available video norms.
    Grabber::tVidNrmListPtr pVidNrmList = grabber.getAvailableVideoNorms();
 
    if( pVidNrmList == 0 )
    {
        std::cerr << "Error: " << grabber.getLastError().toString() << std::endl;
        return -1;
    }
    while ( true )
    {
        std::cout << "Video Norms available for " << grabber.getDev().toString() << std::endl;
 
        int choice = presentUserChoice( *pVidNrmList );
        if( choice != -1 )
        {
            // Set the selected video norm before
            // retrieving the according video formats.
            grabber.setVideoNorm( pVidNrmList->at( choice ) );

Grabber::isVideoNormAvailableWithCurDev is called to check whether the opened video capture device supports video norms. In this case, a list with the available video norms is retrieved by calling Grabber::getAvailableVideoNorms.

After the user selected one of the video norms in presentUserChoice, Grabber::setVideoNorm is used to set the selected norm.

Displaying the Available Video Formats

When a video norm was selected, or video norms are not supported, the available video formats are printed to the screen:

Grabber::tVidFmtListPtr pVidFmtList = grabber.getAvailableVideoFormats();
 
if( pVidFmtList == 0 ) // No video formats available?
{
    std::cerr << "Error : " << grabber.getLastError().toString() << std::endl;
}
else
{
    unsigned int counter = 0;
    // List the available video formats.
    for( Grabber::tVidFmtList::iterator it = pVidFmtList->begin(); 
        it != pVidFmtList->end(); 
        ++it )
    {
        std::cout << "\t[" << counter++ << "] " << it->toString() << std::endl;
    }
}

Grabber::getAvailableVideoFormats returns a list containing the available video formats. In a loop, the names of the formats are displayed. You can get the name of a video format by calling VideoFormatItem::toString.

<< Programmer's Guide

This site is part of The Imaging Source Network. Other sites include Company Portal, Image Processing, Astronomy Cameras, Astronomy Cameras Blog, Blog caméras d'astronomie, Astronomy Cameras Competition, TX Text Control, TX Text Control Blog and Forums.