OpenCV  4.7.0
Open Source Computer Vision
Public Member Functions | List of all members
cv::cudacodec::VideoReader Class Referenceabstract

Video reader interface. More...

#include <opencv2/cudacodec.hpp>

Public Member Functions

virtual ~VideoReader ()
 
virtual FormatInfo format () const =0
 Returns information about video file format. More...
 
virtual bool get (const VideoReaderProps propertyId, double &propertyVal) const =0
 Returns the specified VideoReader property. More...
 
virtual bool get (const int propertyId, double &propertyVal) const =0
 Retrieves the specified property used by the VideoSource. More...
 
virtual bool getVideoReaderProps (const VideoReaderProps propertyId, double &propertyValOut, double propertyValIn=0) const =0
 
virtual bool grab (Stream &stream=Stream::Null())=0
 Grabs the next frame from the video source. More...
 
virtual bool nextFrame (GpuMat &frame, Stream &stream=Stream::Null())=0
 Grabs, decodes and returns the next video frame. More...
 
virtual bool retrieve (OutputArray frame, const size_t idx=static_cast< size_t >(VideoReaderProps::PROP_DECODED_FRAME_IDX)) const =0
 Returns previously grabbed video data. More...
 
bool retrieve (Mat &frame, const size_t idx) const
 Returns previously grabbed encoded video data. More...
 
bool retrieve (GpuMat &frame) const
 Returns the next video frame. More...
 
virtual bool set (const VideoReaderProps propertyId, const double propertyVal)=0
 Sets a property in the VideoReader. More...
 
virtual bool set (const ColorFormat colorFormat)=0
 Set the desired ColorFormat for the frame returned by nextFrame()/retrieve(). More...
 
bool setVideoReaderProps (const VideoReaderProps propertyId, double propertyVal)
 

Detailed Description

Video reader interface.

Available when built with WITH_NVCUVID=ON while Nvidia's Video Codec SDK is installed.

Decoding support is dependent on the GPU, refer to the Nvidia Video Codec SDK Video Encode and Decode GPU Support Matrix for details.

Note
  • An example on how to use the videoReader class can be found at opencv_source_code/samples/gpu/video_reader.cpp

Constructor & Destructor Documentation

◆ ~VideoReader()

virtual cv::cudacodec::VideoReader::~VideoReader ( )
inlinevirtual

Member Function Documentation

◆ format()

virtual FormatInfo cv::cudacodec::VideoReader::format ( ) const
pure virtual

Returns information about video file format.

◆ get() [1/2]

virtual bool cv::cudacodec::VideoReader::get ( const VideoReaderProps  propertyId,
double &  propertyVal 
) const
pure virtual

Returns the specified VideoReader property.

Parameters
propertyIdProperty identifier from cv::cudacodec::VideoReaderProps (eg. cv::cudacodec::VideoReaderProps::PROP_DECODED_FRAME_IDX, cv::cudacodec::VideoReaderProps::PROP_EXTRA_DATA_INDEX, ...).
propertyVal
Returns
true unless the property is not supported.

◆ get() [2/2]

virtual bool cv::cudacodec::VideoReader::get ( const int  propertyId,
double &  propertyVal 
) const
pure virtual

Retrieves the specified property used by the VideoSource.

Parameters
propertyIdProperty identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from Additional flags for video I/O API backends.
propertyValValue for the specified property.
Returns
true unless the property is unset set or not supported.

◆ getVideoReaderProps()

virtual bool cv::cudacodec::VideoReader::getVideoReaderProps ( const VideoReaderProps  propertyId,
double &  propertyValOut,
double  propertyValIn = 0 
) const
pure virtual

◆ grab()

virtual bool cv::cudacodec::VideoReader::grab ( Stream stream = Stream::Null())
pure virtual

Grabs the next frame from the video source.

Parameters
streamStream for the asynchronous version.
Returns
true (non-zero) in the case of success.

The method/function grabs the next frame from video file or camera and returns true (non-zero) in the case of success.

The primary use of the function is for reading both the encoded and decoded video data when rawMode is enabled. With rawMode enabled retrieve() can be called following grab() to retrieve all the data associated with the current video source since the last call to grab() or the creation of the VideoReader.

◆ nextFrame()

virtual bool cv::cudacodec::VideoReader::nextFrame ( GpuMat frame,
Stream stream = Stream::Null() 
)
pure virtual

Grabs, decodes and returns the next video frame.

Parameters
[out]frameThe video frame.
streamStream for the asynchronous version.
Returns
false if no frames have been grabbed.

If no frames have been grabbed (there are no more frames in video file), the methods return false. The method throws an Exception if error occurs.

◆ retrieve() [1/3]

virtual bool cv::cudacodec::VideoReader::retrieve ( OutputArray  frame,
const size_t  idx = static_cast< size_t >(VideoReaderProps::PROP_DECODED_FRAME_IDX) 
) const
pure virtual

Returns previously grabbed video data.

Parameters
[out]frameThe returned data which depends on the provided idx.
idxDetermines the returned data inside image. The returned data can be the:
  • Decoded frame, idx = get(PROP_DECODED_FRAME_IDX).
  • Extra data if available, idx = get(PROP_EXTRA_DATA_INDEX).
  • Raw encoded data package. To retrieve package i, idx = get(PROP_RAW_PACKAGES_BASE_INDEX) + i with i < get(PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB)
Returns
false if no frames have been grabbed

The method returns data associated with the current video source since the last call to grab() or the creation of the VideoReader. If no data is present the method returns false and the function returns an empty image.

◆ retrieve() [2/3]

bool cv::cudacodec::VideoReader::retrieve ( Mat frame,
const size_t  idx 
) const
inline

Returns previously grabbed encoded video data.

Parameters
[out]frameThe encoded video data.
idxDetermines the returned data inside image. The returned data can be the:
  • Extra data if available, idx = get(PROP_EXTRA_DATA_INDEX).
  • Raw encoded data package. To retrieve package i, idx = get(PROP_RAW_PACKAGES_BASE_INDEX) + i with i < get(PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB)
Returns
false if no frames have been grabbed

The method returns data associated with the current video source since the last call to grab() or the creation of the VideoReader. If no data is present the method returns false and the function returns an empty image.

◆ retrieve() [3/3]

bool cv::cudacodec::VideoReader::retrieve ( GpuMat frame) const
inline

Returns the next video frame.

Parameters
[out]frameThe video frame. If grab() has not been called then this will be empty().
Returns
false if no frames have been grabbed

The method returns data associated with the current video source since the last call to grab(). If no data is present the method returns false and the function returns an empty image.

◆ set() [1/2]

virtual bool cv::cudacodec::VideoReader::set ( const VideoReaderProps  propertyId,
const double  propertyVal 
)
pure virtual

Sets a property in the VideoReader.

Parameters
propertyIdProperty identifier from cv::cudacodec::VideoReaderProps (eg. cv::cudacodec::VideoReaderProps::PROP_DECODED_FRAME_IDX, cv::cudacodec::VideoReaderProps::PROP_EXTRA_DATA_INDEX, ...).
propertyValValue of the property.
Returns
true if the property has been set.

◆ set() [2/2]

virtual bool cv::cudacodec::VideoReader::set ( const ColorFormat  colorFormat)
pure virtual

Set the desired ColorFormat for the frame returned by nextFrame()/retrieve().

Parameters
colorFormatValue of the ColorFormat.
Returns
true unless the colorFormat is not supported.

◆ setVideoReaderProps()

bool cv::cudacodec::VideoReader::setVideoReaderProps ( const VideoReaderProps  propertyId,
double  propertyVal 
)
inline

The documentation for this class was generated from the following file: