View Full Version : Set Video Format

October 14, 2003, 08:15:24

I encounter a System.NullReference Error when I code following:

DShowLib::Grabber::tVidCapDevListPtr pVidCapDevList = grabber->getAvailableVideoCaptureDevices();
However, it works when I just set:
grabber->openDev( "Sony 1394 Camera" );

I encounter the same NullReference Error when I code the following:
Grabber::tVidFmtListPtr pVidFmtList = grabber->getAvailableVideoFormats();

1. Can I set a fixed video format e.g. 1280x960... as I fixed the Device name as above?

2. Why there is a Null Reference Error?

Any Idea ? Thanks a lot!!!

Stefan Geissler
October 14, 2003, 09:16:29

The video formats (and other camera properties) are only available, after the video capture device (camera) has been opened by a call to openDev(). The reason is, that IC Imaging Control ask the video capture device what video formats and properties are supported.
If you want to set a video format, you should make sure, that the desired video format is supported by your video capture device.
This is a function to set the video format by only setting the video formats name as literal.

/*! Set the video format. If video formats are not supported or an illegal video
format is specified, the function will return false. On success, the function
returns true.
\param pGrabber Pointer to a grabber instance, that must have an
valid device open. If this pointer is NULL or there
is no valid device open, the function will return false.
\param szFormat Name of the desired video format, for example "PAL_B".

\return bool true, if the video format could be set, otherwise false.
bool SetVideoFormat( DShowLib::Grabber* pGrabber, std::string szFormat)
bool bResult = false;
if( pGrabber == NULL ) return bResult;
if( !pGrabber->isDevValid() ) return bResult;
DShowLib::Grabber::tVidFmtListPtr pVidFmtList = pGrabber->getAvailableVideoFormats();
if ( pVidFmtList!=0 )
DShowLib::Grabber::tVidFmtListPtr::value_type::ite rator itfmt =
std::find( pVidFmtList->begin(), pVidFmtList->end(), szFormat );
if ( !(itfmt==pVidFmtList->end()) )
pGrabber->setVideoFormat( *itfmt );
bResult = true;
pGrabber->setVideoFormat( pVidFmtList->at(pVidFmtList->size() - 1) );

return bResult;


bool bFormatSet = SetVideoFormat( &m_cGrabber, Y800 (640*480));

(This sample shows how to set a video format for a DMK 21F04. )

Also you should install the original Sony driver, that is available at:
(The driver is used for all Sony DCam models.)