This example demonstrates how to set a MediaStreamSink:
Grabber grabber;
if( !setupDeviceFromFile( grabber ) )
{
return -1;
}
tCodecList codecList = Codec::getAvailableCodecList();
// Display all codec names on the screen.
int choice = presentUserChoice( toStringArrayPtrList( codecList ) );
if( choice == -1 )
{
return -1;
}
// Create an MediaStreamSink to record an AVI file with the selected CoDec
tMediaStreamSinkPtr pSink = MediaStreamSink::create(
MediaStreamContainer::create( MSC_AviContainer ), codecList.at( choice ) );
// Set the filename.
pSink->setFilename( filename );
// The sink is initially paused, so that no video data is written to the file.
pSink->setSinkMode( GrabberSinkType::ePAUSE );
// Set pSink as the current sink.
grabber.setSinkType( pSink );
// Start the live mode. The live video will be displayed but no images will be written
// to the AVI file because pSink is in pause mode.
if( !grabber.startLive( true ) )
{
std::cerr << grabber.getLastError().toString() << std::endl;
return -1;
}
std::cout << "Press [enter] to start capturing!";
std::cin.get();
// Start the sink. The image stream is written to the AVI file.
pSink->setSinkMode(GrabberSinkType::eRUN );
std::cout << "Video recording started." << std::endl;
std::cout << "Press [enter] to stop capturing!";
std::cin.get();
// Pause the sink. This stops writing the image stream to the AVI file.
// A subsequent call to setSinkMode with GrabberSinkType::eRUN as the
// parameter would restart AVI recording.
pSink->setSinkMode(GrabberSinkType::ePAUSE );
std::cout << "Video recording stopped." << std::endl;
// Stop the live mode. This stops writing images to the AVI file if the mode is not
// GrabberSinkType::ePAUSE. The AVI file is closed.
grabber.stopLive();
|