OpenCV  5.0.0-pre
Open Source Computer Vision
Classes | Enumerations | Functions
Video Encoding/Decoding

Classes

class  cv::cudacodec::EncoderCallBack
 Callbacks for CUDA video encoder. More...
 
struct  cv::cudacodec::EncoderParams
 Different parameters for CUDA video encoder. More...
 
struct  cv::cudacodec::FormatInfo
 Struct providing information about video file format. : More...
 
class  cv::cudacodec::RawVideoSource
 Interface for video demultiplexing. : More...
 
class  cv::cudacodec::VideoReader
 Video reader interface. More...
 
class  cv::cudacodec::VideoWriter
 Video writer interface. More...
 

Enumerations

enum  cv::cudacodec::ChromaFormat {
  cv::cudacodec::Monochrome = 0,
  cv::cudacodec::YUV420,
  cv::cudacodec::YUV422,
  cv::cudacodec::YUV444,
  cv::cudacodec::NumFormats
}
 Chroma formats supported by cudacodec::VideoReader. More...
 
enum  cv::cudacodec::Codec {
  cv::cudacodec::MPEG1 = 0,
  cv::cudacodec::MPEG2,
  cv::cudacodec::MPEG4,
  cv::cudacodec::VC1,
  cv::cudacodec::H264,
  cv::cudacodec::JPEG,
  cv::cudacodec::H264_SVC,
  cv::cudacodec::H264_MVC,
  cv::cudacodec::HEVC,
  cv::cudacodec::VP8,
  cv::cudacodec::VP9,
  cv::cudacodec::AV1,
  cv::cudacodec::NumCodecs,
  cv::cudacodec::Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')),
  cv::cudacodec::Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')),
  cv::cudacodec::Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')),
  cv::cudacodec::Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')),
  cv::cudacodec::Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y'))
}
 Video codecs supported by cudacodec::VideoReader . More...
 
enum  cv::cudacodec::ColorFormat {
  cv::cudacodec::ColorFormat::BGRA = 1,
  cv::cudacodec::ColorFormat::BGR = 2,
  cv::cudacodec::ColorFormat::GRAY = 3
}
 ColorFormat for the frame returned by the decoder. More...
 
enum  cv::cudacodec::DeinterlaceMode {
  cv::cudacodec::Weave = 0,
  cv::cudacodec::Bob = 1,
  cv::cudacodec::Adaptive = 2
}
 Deinterlacing mode used by decoder. More...
 
enum  cv::cudacodec::SurfaceFormat {
  cv::cudacodec::SF_UYVY = 0,
  cv::cudacodec::SF_YUY2,
  cv::cudacodec::SF_YV12,
  cv::cudacodec::SF_NV12,
  cv::cudacodec::SF_IYUV,
  cv::cudacodec::SF_BGR,
  cv::cudacodec::SF_GRAY = SF_BGR
}
 
enum  cv::cudacodec::VideoReaderProps {
  cv::cudacodec::VideoReaderProps::PROP_DECODED_FRAME_IDX = 0,
  cv::cudacodec::VideoReaderProps::PROP_EXTRA_DATA_INDEX = 1,
  cv::cudacodec::VideoReaderProps::PROP_RAW_PACKAGES_BASE_INDEX = 2,
  cv::cudacodec::VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB = 3,
  cv::cudacodec::VideoReaderProps::PROP_RAW_MODE = 4,
  cv::cudacodec::VideoReaderProps::PROP_LRF_HAS_KEY_FRAME = 5,
  cv::cudacodec::VideoReaderProps::PROP_COLOR_FORMAT = 6
}
 cv::cudacodec::VideoReader generic properties identifier. More...
 

Functions

Ptr< VideoReadercv::cudacodec::createVideoReader (const String &filename, const std::vector< int > &params={}, const bool rawMode=false, const int minNumDecodeSurfaces=0)
 Creates video reader. More...
 
Ptr< VideoReadercv::cudacodec::createVideoReader (const Ptr< RawVideoSource > &source, const bool rawMode=false, const int minNumDecodeSurfaces=0)
 
Ptr< cudacodec::VideoWritercv::cudacodec::createVideoWriter (const String &fileName, Size frameSize, double fps, SurfaceFormat format=SF_BGR)
 Creates video writer. More...
 
Ptr< cudacodec::VideoWritercv::cudacodec::createVideoWriter (const String &fileName, Size frameSize, double fps, const EncoderParams &params, SurfaceFormat format=SF_BGR)
 
Ptr< cudacodec::VideoWritercv::cudacodec::createVideoWriter (const Ptr< EncoderCallBack > &encoderCallback, Size frameSize, double fps, SurfaceFormat format=SF_BGR)
 
Ptr< cudacodec::VideoWritercv::cudacodec::createVideoWriter (const Ptr< EncoderCallBack > &encoderCallback, Size frameSize, double fps, const EncoderParams &params, SurfaceFormat format=SF_BGR)
 

Detailed Description

Enumeration Type Documentation

◆ ChromaFormat

#include <opencv2/cudacodec.hpp>

Chroma formats supported by cudacodec::VideoReader.

Enumerator
Monochrome 
YUV420 
YUV422 
YUV444 
NumFormats 

◆ Codec

#include <opencv2/cudacodec.hpp>

Video codecs supported by cudacodec::VideoReader .

Enumerator
MPEG1 
MPEG2 
MPEG4 
VC1 
H264 
JPEG 
H264_SVC 
H264_MVC 
HEVC 
VP8 
VP9 
AV1 
NumCodecs 
Uncompressed_YUV420 

Y,U,V (4:2:0)

Uncompressed_YV12 

Y,V,U (4:2:0)

Uncompressed_NV12 

Y,UV (4:2:0)

Uncompressed_YUYV 

YUYV/YUY2 (4:2:2)

Uncompressed_UYVY 

UYVY (4:2:2)

◆ ColorFormat

#include <opencv2/cudacodec.hpp>

ColorFormat for the frame returned by the decoder.

Enumerator
BGRA 
BGR 
GRAY 

◆ DeinterlaceMode

#include <opencv2/cudacodec.hpp>

Deinterlacing mode used by decoder.

Parameters
WeaveWeave both fields (no deinterlacing). For progressive content and for content that doesn't need deinterlacing. Bob Drop one field.
AdaptiveAdaptive deinterlacing needs more video memory than other deinterlacing modes.
Enumerator
Weave 
Bob 
Adaptive 

◆ SurfaceFormat

#include <opencv2/cudacodec.hpp>

Enumerator
SF_UYVY 
SF_YUY2 
SF_YV12 
SF_NV12 
SF_IYUV 
SF_BGR 
SF_GRAY 

◆ VideoReaderProps

#include <opencv2/cudacodec.hpp>

cv::cudacodec::VideoReader generic properties identifier.

Enumerator
PROP_DECODED_FRAME_IDX 

Index for retrieving the decoded frame using retrieve().

PROP_EXTRA_DATA_INDEX 

Index for retrieving the extra data associated with a video source using retrieve().

PROP_RAW_PACKAGES_BASE_INDEX 

Base index for retrieving raw encoded data using retrieve().

PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB 

Number of raw packages recieved since the last call to grab().

PROP_RAW_MODE 

Status of raw mode.

PROP_LRF_HAS_KEY_FRAME 

FFmpeg source only - Indicates whether the Last Raw Frame (LRF), output from VideoReader::retrieve() when VideoReader is initialized in raw mode, contains encoded data for a key frame.

PROP_COLOR_FORMAT 

Set the ColorFormat of the decoded frame. This can be changed before every call to nextFrame() and retrieve().

Function Documentation

◆ createVideoReader() [1/2]

Ptr<VideoReader> cv::cudacodec::createVideoReader ( const String filename,
const std::vector< int > &  params = {},
const bool  rawMode = false,
const int  minNumDecodeSurfaces = 0 
)

#include <opencv2/cudacodec.hpp>

Creates video reader.

Parameters
filenameName of the input video file.
paramsPass through parameters for VideoCapure. VideoCapture with the FFMpeg back end (CAP_FFMPEG) is used to parse the video input. The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties e.g. when streaming from an RTSP source CAP_PROP_OPEN_TIMEOUT_MSEC may need to be set.
rawModeAllow the raw encoded data which has been read up until the last call to grab() to be retrieved by calling retrieve(rawData,RAW_DATA_IDX).
minNumDecodeSurfacesMinimum number of internal decode surfaces used by the hardware decoder. NVDEC will automatically determine the minimum number of surfaces it requires for correct functionality and optimal video memory usage but not necessarily for best performance, which depends on the design of the overall application. The optimal number of decode surfaces (in terms of performance and memory utilization) should be decided by experimentation for each application, but it cannot go below the number determined by NVDEC.

FFMPEG is used to read videos. User can implement own demultiplexing with cudacodec::RawVideoSource

◆ createVideoReader() [2/2]

Ptr<VideoReader> cv::cudacodec::createVideoReader ( const Ptr< RawVideoSource > &  source,
const bool  rawMode = false,
const int  minNumDecodeSurfaces = 0 
)

#include <opencv2/cudacodec.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
sourceRAW video source implemented by user.
rawModeAllow the raw encoded data which has been read up until the last call to grab() to be retrieved by calling retrieve(rawData,RAW_DATA_IDX).
minNumDecodeSurfacesMinimum number of internal decode surfaces used by the hardware decoder. NVDEC will automatically determine the minimum number of surfaces it requires for correct functionality and optimal video memory usage but not necessarily for best performance, which depends on the design of the overall application. The optimal number of decode surfaces (in terms of performance and memory utilization) should be decided by experimentation for each application, but it cannot go below the number determined by NVDEC.

◆ createVideoWriter() [1/4]

Ptr<cudacodec::VideoWriter> cv::cudacodec::createVideoWriter ( const String fileName,
Size  frameSize,
double  fps,
SurfaceFormat  format = SF_BGR 
)

#include <opencv2/cudacodec.hpp>

Creates video writer.

Parameters
fileNameName of the output video file. Only AVI file format is supported.
frameSizeSize of the input video frames.
fpsFramerate of the created video stream.
formatSurface format of input frames ( SF_UYVY , SF_YUY2 , SF_YV12 , SF_NV12 , SF_IYUV , SF_BGR or SF_GRAY). BGR or gray frames will be converted to YV12 format before encoding, frames with other formats will be used as is.

The constructors initialize video writer. FFMPEG is used to write videos. User can implement own multiplexing with cudacodec::EncoderCallBack .

◆ createVideoWriter() [2/4]

Ptr<cudacodec::VideoWriter> cv::cudacodec::createVideoWriter ( const String fileName,
Size  frameSize,
double  fps,
const EncoderParams params,
SurfaceFormat  format = SF_BGR 
)

#include <opencv2/cudacodec.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
fileNameName of the output video file. Only AVI file format is supported.
frameSizeSize of the input video frames.
fpsFramerate of the created video stream.
paramsEncoder parameters. See cudacodec::EncoderParams .
formatSurface format of input frames ( SF_UYVY , SF_YUY2 , SF_YV12 , SF_NV12 , SF_IYUV , SF_BGR or SF_GRAY). BGR or gray frames will be converted to YV12 format before encoding, frames with other formats will be used as is.

◆ createVideoWriter() [3/4]

Ptr<cudacodec::VideoWriter> cv::cudacodec::createVideoWriter ( const Ptr< EncoderCallBack > &  encoderCallback,
Size  frameSize,
double  fps,
SurfaceFormat  format = SF_BGR 
)

#include <opencv2/cudacodec.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
encoderCallbackCallbacks for video encoder. See cudacodec::EncoderCallBack . Use it if you want to work with raw video stream.
frameSizeSize of the input video frames.
fpsFramerate of the created video stream.
formatSurface format of input frames ( SF_UYVY , SF_YUY2 , SF_YV12 , SF_NV12 , SF_IYUV , SF_BGR or SF_GRAY). BGR or gray frames will be converted to YV12 format before encoding, frames with other formats will be used as is.

◆ createVideoWriter() [4/4]

Ptr<cudacodec::VideoWriter> cv::cudacodec::createVideoWriter ( const Ptr< EncoderCallBack > &  encoderCallback,
Size  frameSize,
double  fps,
const EncoderParams params,
SurfaceFormat  format = SF_BGR 
)

#include <opencv2/cudacodec.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
encoderCallbackCallbacks for video encoder. See cudacodec::EncoderCallBack . Use it if you want to work with raw video stream.
frameSizeSize of the input video frames.
fpsFramerate of the created video stream.
paramsEncoder parameters. See cudacodec::EncoderParams.
formatSurface format of input frames ( SF_UYVY , SF_YUY2 , SF_YV12 , SF_NV12 , SF_IYUV , SF_BGR or SF_GRAY). BGR or gray frames will be converted to YV12 format before encoding, frames with other formats will be used as is.