IC Imaging Control C++

MediaStreamSink::create Method

MediaStreamSink::create Method

Creates a new MediaStreamSink.
Syntax:
static tMediaStreamSinkPtr create( const tMediaStreamContainerPtr& pCont,
                                   IFrameFilter* pFilter = 0 );
static tMediaStreamSinkPtr create( const tMediaStreamContainerPtr& pCont,
                                   const tFrameFilterList& lst );
 
static tMediaStreamSinkPtr create( const tMediaStreamContainerPtr& pCont,
                                   const smart_ptr<Codec>& pCodec,
                                   IFrameFilter* pFilter = 0 );
static tMediaStreamSinkPtr create( const tMediaStreamContainerPtr& pCont,
                                   const smart_ptr<Codec>& pCodec,
                                   const tFrameFilterList& lst );
 
static tMediaStreamSinkPtr create( const tMediaStreamContainerPtr& pCont,
                                   const GUID& subtype,
                                   IFrameFilter* pFilter = 0 );
static tMediaStreamSinkPtr create( const tMediaStreamContainerPtr& pCont,
                                   const GUID& subtype,
                                   const tFrameFilterList& lst );
 
static tMediaStreamSinkPtr create( const GUID& containerID,
                                   IFrameFilter* pFilter = 0 );
static tMediaStreamSinkPtr create( const GUID& containerID,
                                   const tFrameFilterList& lst );
 
static tMediaStreamSinkPtr create( const GUID& containerID,
                                   const smart_ptr<Codec>& pCodec,
                                   IFrameFilter* pFilter = 0 );
static tMediaStreamSinkPtr create( const GUID& containerID,
                                   const smart_ptr<Codec>& pCodec,
                                   const tFrameFilterList& lst );
 
static tMediaStreamSinkPtr create( const GUID& containerID,
                                   const GUID& subtype,
                                   IFrameFilter* pFilter = 0 );
static tMediaStreamSinkPtr create( const GUID& containerID,
                                   const GUID& subtype,
                                   const tFrameFilterList& lst );
 
static tMediaStreamSinkPtr create( const tCreateData& create_data );
Parameter Description
pCont

Pointer to a MediaStreamContainer. You can obtain a list with available Codec objects by calling MediaStreamContainer::getAvailableMediaStreamContainers, or directly by creating MediaStreamContainer objects by specifying a GUID to MediaStreamContainer::create.

containerID

GUID of a MediaStreamContainer or one of the Standard MediaStreamContainer GUIDs.

pFilter

The frame filter that can analyze or transform the image data before it is written to the video file.

lst

A tFrameFilterList of frame filters. The filters in this list are connected in a filter chain to transform the image data.

pCodec

Pointer to a MediaStreamContainer. You can obtain a list with available Codec objects, by calling Codec::getAvailableCodecs.

subtype

The subtype specifies the image format of uncompressed video.

create_data

To duplicate a MediaStreamSink, you can call MediaStreamSink::getCreateData to access the parameters with which it was created. You can use this tCreateData structure to initialize another MediaStreamSink.

Return Value:

A pointer to the new MediaStreamSink, or 0, if an error occurred.

Remarks:

Some media stream containers do not work with certain codecs. On the other hand, some media stream containers do not accept uncompressed video formats. In this case, Grabber::startLive will fail and you will have to try a different container/codec combination.

Examples:

To record an AVI file, you have to create an AVI media stream container that is identified by MSC_AviContainer. Select a codec from the list returned by Codec::getAvailableCodecs and create the MediaStreamSink. After the sink has been created, you have to set a video filename, by calling MediaStreamSink::setFilename:

// Create an AVI Media Stream Container.
tMediaStreamContainerPtr pAVIContainer = MediaStreamContainer::create( MSC_AviContainer );
 
// Obtain a list of available codecs.
tCodecListPtr pAvailableCodecList = Codec::getAvailableCodecs();
 
// Select the first codec. You would usually allow the user to make this choice
// or hard code the search for a codec name.
tCodecPtr pCodec = pAvailableCodecList->at( 0 );
 
// Create the media stream sink from these parameters.
tMediaStreamSinkPtr pSink = MediaStreamSink::create( pAVIContainer, pCodec );
 
// Set a target filename.
pSink->setFilename( "test.avi" );
 
// Set the sink.
m_Grabber.setSinkType( pSink );

To get a list of the available MediaStreamContainers, use MediaStreamContainer::getAvailableMediaStreamContainers. You can find out whether a MediaStreamContainer supports codecs or uncompressed formats by calling MediaStreamContainer::isCustomCodecSupported. In this case, you can create the sink as seen above. When no custom codecs are supported, you are not allowed to specify a codec in MediaStreamSink::create. To set a matching video filename, you can call MediaStreamContainer::getPreferredFileExtension to get the default file extension for that video file format.

// Get a list of the available media stream containers.
tMediaStreamContainerListPtr pAvailableContainers =
    MediaStreamContainer::getAvailableMediaStreamContainers();
 
// Select the first container. You would usually allow the user to make this choice
// or hard code the search for a container name.
tMediaStreamContainerPtr pContainer = pAvailableContainers->at( 0 );
 
// Sink object to be created.
tMediaStreamSinkPtr pSink;
 
// If the container supports codecs, select one.
if( pContainer->isCustomCodecSupported() )
{
    // Obtain a list of available codecs.
    tCodecListPtr pAvailableCodecList = Codec::getAvailableCodecs();
 
    // Select the first codec. You would usually allow the user to make this choice
    // or hard code the search for a codec name.
    tCodecPtr pCodec = pAvailableCodecList->at( 0 );
 
    // Create the media stream sink from these parameters.
    pSink = MediaStreamSink::create( pContainer, pCodec );
}
else
{
    // No codec support; just create the sink.
    pSink = MediaStreamSink::create( pContainer );
}
 
// Create a file name from a name and the preferred extension of the container.
std::string filename = "test.";
filename += pContainer->getPreferredFileExtension();
pSink->setFilename( filename );
 
// Set the sink.
m_Grabber.setSinkType( pSink );

To save uncompressed AVI, use the subtype of the desired uncompressed format as second parameter to MediaStreamSink::create.

// Create an AVI Media Stream Container.
tMediaStreamContainerPtr pAVIContainer = MediaStreamContainer::create( MSC_AviContainer );
 
// Create the media stream sink from these parameters.
tMediaStreamSinkPtr pSink = MediaStreamSink::create( pAVIContainer, MEDIASUBTYPE_RGB24 );
 
// Set a target filename.
pSink->setFilename( "test.avi" );
 
// Set the sink.
m_Grabber.setSinkType( pSink );
See also: MediaStreamSink, MediaStreamContainer, IFrameFilter

<< MediaStreamSink

Get in touch with us


About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

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

Automated Imaging Association ISO 9001:2015 certified

Contact us