IC Imaging Control C++

Grabber::setSinkType Method

Grabber::setSinkType Method

Sets the format of the sink. A sink specifies the output target of an image stream. A sink may only be set, if the image stream is in neither live mode, nor prepared mode.
bool setSinkType( smart_ptr<GrabberSinkType> pNewSink );
Parameter Description

Specifies the new sink type.

Return value:
Description Description
true The sink type was changed successfully.
false An error occurred.

For more information about sink types, please refer to: FrameHandlerSink, MediaStreamSink, FrameNotificationSink, FrameQueueSink and FrameSnapSink


This example demonstrates how to set a MediaStreamSink:

Grabber grabber;
if( !setupDeviceFromFile( grabber ) )
    return -1;

tCodecListPtr pCodecs = Codec::getAvailableCodecs();
// Display all codec names on the screen.
int choice = presentUserChoice( toStringArrayPtrListPtr( pCodecs ) );
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 ), pCodecs->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!";
// 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!";
// 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.

See also: Grabber, Grabber::startLive, Grabber::getSinkTypePtr, MediaStreamSink, FrameHandlerSink

<< Grabber

Get in touch with us

About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, video converters and embedded vision components for factory automation, quality assurance, medicine, science, security and a variety of other markets.

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

ISO 9001:2015 certified MVTEC | Edge AI + Vision Alliance | EMVA

Contact us