OpenCV  4.10.0
Open Source Computer Vision
Loading...
Searching...
No Matches
Classes | Enumerations | Functions
Video Encoding/Decoding

Detailed Description

Classes

struct  cv::cudacodec::EncodeQp
 
class  cv::cudacodec::EncoderCallback
 Interface for encoder callbacks. 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, see createVideoReader(). More...
 
struct  cv::cudacodec::VideoReaderInitParams
 VideoReader initialization parameters. More...
 
class  cv::cudacodec::VideoWriter
 Video writer interface, see createVideoWriter(). 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 and cudacodec::VideoWriter. More...
 
enum class  cv::cudacodec::ColorFormat {
  cv::cudacodec::ColorFormat::UNDEFINED = 0 ,
  cv::cudacodec::ColorFormat::BGRA = 1 ,
  cv::cudacodec::ColorFormat::BGR = 2 ,
  cv::cudacodec::ColorFormat::GRAY = 3 ,
  cv::cudacodec::ColorFormat::NV_NV12 = 4 ,
  cv::cudacodec::ColorFormat::RGB = 5 ,
  cv::cudacodec::ColorFormat::RGBA = 6 ,
  cv::cudacodec::ColorFormat::NV_YV12 = 8 ,
  cv::cudacodec::ColorFormat::NV_IYUV = 9 ,
  cv::cudacodec::ColorFormat::NV_YUV444 = 10 ,
  cv::cudacodec::ColorFormat::NV_AYUV = 11
}
 ColorFormat for the frame returned by VideoReader::nextFrame() and VideoReader::retrieve() or used to initialize a VideoWriter. 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::EncodeMultiPass {
  cv::cudacodec::ENC_MULTI_PASS_DISABLED = 0x0 ,
  cv::cudacodec::ENC_TWO_PASS_QUARTER_RESOLUTION = 0x1 ,
  cv::cudacodec::ENC_TWO_PASS_FULL_RESOLUTION = 0x2
}
 Multi Pass Encoding. More...
 
enum  cv::cudacodec::EncodeParamsRcMode {
  cv::cudacodec::ENC_PARAMS_RC_CONSTQP = 0x0 ,
  cv::cudacodec::ENC_PARAMS_RC_VBR = 0x1 ,
  cv::cudacodec::ENC_PARAMS_RC_CBR = 0x2
}
 Rate Control Modes. More...
 
enum  cv::cudacodec::EncodePreset {
  cv::cudacodec::ENC_PRESET_P1 = 1 ,
  cv::cudacodec::ENC_PRESET_P2 = 2 ,
  cv::cudacodec::ENC_PRESET_P3 = 3 ,
  cv::cudacodec::ENC_PRESET_P4 = 4 ,
  cv::cudacodec::ENC_PRESET_P5 = 5 ,
  cv::cudacodec::ENC_PRESET_P6 = 6 ,
  cv::cudacodec::ENC_PRESET_P7 = 7
}
 Nvidia Encoding Presets. Performance degrades and quality improves as we move from P1 to P7. More...
 
enum  cv::cudacodec::EncodeProfile {
  cv::cudacodec::ENC_CODEC_PROFILE_AUTOSELECT = 0 ,
  cv::cudacodec::ENC_H264_PROFILE_BASELINE = 1 ,
  cv::cudacodec::ENC_H264_PROFILE_MAIN = 2 ,
  cv::cudacodec::ENC_H264_PROFILE_HIGH = 3 ,
  cv::cudacodec::ENC_H264_PROFILE_HIGH_444 = 4 ,
  cv::cudacodec::ENC_H264_PROFILE_STEREO = 5 ,
  cv::cudacodec::ENC_H264_PROFILE_PROGRESSIVE_HIGH = 6 ,
  cv::cudacodec::ENC_H264_PROFILE_CONSTRAINED_HIGH = 7 ,
  cv::cudacodec::ENC_HEVC_PROFILE_MAIN = 8 ,
  cv::cudacodec::ENC_HEVC_PROFILE_MAIN10 = 9 ,
  cv::cudacodec::ENC_HEVC_PROFILE_FREXT = 10
}
 Supported Encoder Profiles. More...
 
enum  cv::cudacodec::EncodeTuningInfo {
  cv::cudacodec::ENC_TUNING_INFO_UNDEFINED = 0 ,
  cv::cudacodec::ENC_TUNING_INFO_HIGH_QUALITY = 1 ,
  cv::cudacodec::ENC_TUNING_INFO_LOW_LATENCY = 2 ,
  cv::cudacodec::ENC_TUNING_INFO_ULTRA_LOW_LATENCY = 3 ,
  cv::cudacodec::ENC_TUNING_INFO_LOSSLESS = 4 ,
  cv::cudacodec::ENC_TUNING_INFO_COUNT
}
 Tuning information. More...
 
enum class  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::VideoReaderProps::PROP_UDP_SOURCE = 7 ,
  cv::cudacodec::VideoReaderProps::PROP_ALLOW_FRAME_DROP = 8
}
 cv::cudacodec::VideoReader generic properties identifier. More...
 

Functions

Ptr< VideoReadercv::cudacodec::createVideoReader (const Ptr< RawVideoSource > &source, const VideoReaderInitParams params=VideoReaderInitParams())
 
Ptr< VideoReadercv::cudacodec::createVideoReader (const String &filename, const std::vector< int > &sourceParams={}, const VideoReaderInitParams params=VideoReaderInitParams())
 Creates video reader.
 
Ptr< cudacodec::VideoWritercv::cudacodec::createVideoWriter (const String &fileName, const Size frameSize, const Codec codec, const double fps, const ColorFormat colorFormat, const EncoderParams &params, Ptr< EncoderCallback > encoderCallback=0, const cuda::Stream &stream=cuda::Stream::Null())
 Creates video writer.
 
Ptr< cudacodec::VideoWritercv::cudacodec::createVideoWriter (const String &fileName, const Size frameSize, const Codec codec=Codec::H264, const double fps=25.0, const ColorFormat colorFormat=ColorFormat::BGR, Ptr< EncoderCallback > encoderCallback=0, const cuda::Stream &stream=cuda::Stream::Null())
 Creates video writer.
 
void cv::cudacodec::MapHist (const cuda::GpuMat &hist, Mat &histFull)
 Utility function demonstrating how to map the luma histogram when FormatInfo::videoFullRangeFlag == false.
 
bool cv::cudacodec::operator== (const EncoderParams &lhs, const EncoderParams &rhs)
 

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 and cudacodec::VideoWriter.

Note
  • Support will depend on your hardware, refer to the Nvidia Video Codec SDK Video Encode and Decode GPU Support Matrix for details.
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

enum class cv::cudacodec::ColorFormat
strong

#include <opencv2/cudacodec.hpp>

ColorFormat for the frame returned by VideoReader::nextFrame() and VideoReader::retrieve() or used to initialize a VideoWriter.

Enumerator
UNDEFINED 
BGRA 

OpenCV color format, can be used with both VideoReader and VideoWriter.

BGR 

OpenCV color format, can be used with both VideoReader and VideoWriter.

GRAY 

OpenCV color format, can be used with both VideoReader and VideoWriter.

NV_NV12 

Nvidia color format - equivalent to YUV - Semi-Planar YUV [Y plane followed by interleaved UV plane], can be used with both VideoReader and VideoWriter.

RGB 

OpenCV color format, can only be used with VideoWriter.

RGBA 

OpenCV color format, can only be used with VideoWriter.

NV_YV12 

Nvidia Buffer Format - Planar YUV [Y plane followed by V and U planes], use with VideoReader, can only be used with VideoWriter.

NV_IYUV 

Nvidia Buffer Format - Planar YUV [Y plane followed by U and V planes], use with VideoReader, can only be used with VideoWriter.

NV_YUV444 

Nvidia Buffer Format - Planar YUV [Y plane followed by U and V planes], use with VideoReader, can only be used with VideoWriter.

NV_AYUV 

Nvidia Buffer Format - 8 bit Packed A8Y8U8V8. This is a word-ordered format where a pixel is represented by a 32-bit word with V in the lowest 8 bits, U in the next 8 bits, Y in the 8 bits after that and A in the highest 8 bits, can only be used with VideoWriter.

◆ 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.
BobDrop one field.
AdaptiveAdaptive deinterlacing needs more video memory than other deinterlacing modes.
Enumerator
Weave 
Bob 
Adaptive 

◆ EncodeMultiPass

#include <opencv2/cudacodec.hpp>

Multi Pass Encoding.

Enumerator
ENC_MULTI_PASS_DISABLED 

Single Pass.

ENC_TWO_PASS_QUARTER_RESOLUTION 

Two Pass encoding is enabled where first Pass is quarter resolution.

ENC_TWO_PASS_FULL_RESOLUTION 

Two Pass encoding is enabled where first Pass is full resolution.

◆ EncodeParamsRcMode

#include <opencv2/cudacodec.hpp>

Rate Control Modes.

Enumerator
ENC_PARAMS_RC_CONSTQP 

Constant QP mode.

ENC_PARAMS_RC_VBR 

Variable bitrate mode.

ENC_PARAMS_RC_CBR 

Constant bitrate mode.

◆ EncodePreset

#include <opencv2/cudacodec.hpp>

Nvidia Encoding Presets. Performance degrades and quality improves as we move from P1 to P7.

Enumerator
ENC_PRESET_P1 
ENC_PRESET_P2 
ENC_PRESET_P3 
ENC_PRESET_P4 
ENC_PRESET_P5 
ENC_PRESET_P6 
ENC_PRESET_P7 

◆ EncodeProfile

#include <opencv2/cudacodec.hpp>

Supported Encoder Profiles.

Enumerator
ENC_CODEC_PROFILE_AUTOSELECT 
ENC_H264_PROFILE_BASELINE 
ENC_H264_PROFILE_MAIN 
ENC_H264_PROFILE_HIGH 
ENC_H264_PROFILE_HIGH_444 
ENC_H264_PROFILE_STEREO 
ENC_H264_PROFILE_PROGRESSIVE_HIGH 
ENC_H264_PROFILE_CONSTRAINED_HIGH 
ENC_HEVC_PROFILE_MAIN 
ENC_HEVC_PROFILE_MAIN10 
ENC_HEVC_PROFILE_FREXT 

◆ EncodeTuningInfo

#include <opencv2/cudacodec.hpp>

Tuning information.

Enumerator
ENC_TUNING_INFO_UNDEFINED 

Undefined tuningInfo. Invalid value for encoding.

ENC_TUNING_INFO_HIGH_QUALITY 

Tune presets for latency tolerant encoding.

ENC_TUNING_INFO_LOW_LATENCY 

Tune presets for low latency streaming.

ENC_TUNING_INFO_ULTRA_LOW_LATENCY 

Tune presets for ultra low latency streaming.

ENC_TUNING_INFO_LOSSLESS 

Tune presets for lossless encoding.

ENC_TUNING_INFO_COUNT 

◆ 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().

PROP_UDP_SOURCE 

Status of VideoReaderInitParams::udpSource initialization.

PROP_ALLOW_FRAME_DROP 

Status of VideoReaderInitParams::allowFrameDrop initialization.

Function Documentation

◆ createVideoReader() [1/2]

Ptr< VideoReader > cv::cudacodec::createVideoReader ( const Ptr< RawVideoSource > &  source,
const VideoReaderInitParams  params = VideoReaderInitParams() 
)

#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.
paramsInitializaton parameters. See cv::cudacodec::VideoReaderInitParams.

◆ createVideoReader() [2/2]

Ptr< VideoReader > cv::cudacodec::createVideoReader ( const String filename,
const std::vector< int > &  sourceParams = {},
const VideoReaderInitParams  params = VideoReaderInitParams() 
)

#include <opencv2/cudacodec.hpp>

Creates video reader.

Parameters
filenameName of the input video file.
sourceParamsPass through parameters for VideoCapure. VideoCapture with the FFMpeg back end (CAP_FFMPEG) is used to parse the video input. The sourceParams 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.
paramsInitializaton parameters. See cv::cudacodec::VideoReaderInitParams.

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

◆ createVideoWriter() [1/2]

Ptr< cudacodec::VideoWriter > cv::cudacodec::createVideoWriter ( const String fileName,
const Size  frameSize,
const Codec  codec,
const double  fps,
const ColorFormat  colorFormat,
const EncoderParams params,
Ptr< EncoderCallback encoderCallback = 0,
const cuda::Stream stream = cuda::Stream::Null() 
)

#include <opencv2/cudacodec.hpp>

Creates video writer.

Parameters
fileNameName of the output video file.
frameSizeSize of the input video frames.
codecSupports Codec::H264 and Codec::HEVC.
fpsFramerate of the created video stream.
colorFormatOpenCv color format of the frames to be encoded.
paramsAdditional encoding parameters.
encoderCallbackCallbacks for video encoder. See cudacodec::EncoderCallback. Required for working with the encoded video stream.
streamStream for frame pre-processing.

◆ createVideoWriter() [2/2]

Ptr< cudacodec::VideoWriter > cv::cudacodec::createVideoWriter ( const String fileName,
const Size  frameSize,
const Codec  codec = Codec::H264,
const double  fps = 25.0,
const ColorFormat  colorFormat = ColorFormat::BGR,
Ptr< EncoderCallback encoderCallback = 0,
const cuda::Stream stream = cuda::Stream::Null() 
)

#include <opencv2/cudacodec.hpp>

Creates video writer.

Parameters
fileNameName of the output video file.
frameSizeSize of the input video frames.
codecSupports Codec::H264 and Codec::HEVC.
fpsFramerate of the created video stream.
colorFormatOpenCv color format of the frames to be encoded.
encoderCallbackCallbacks for video encoder. See cudacodec::EncoderCallback. Required for working with the encoded video stream.
streamStream for frame pre-processing.

◆ MapHist()

void cv::cudacodec::MapHist ( const cuda::GpuMat hist,
Mat histFull 
)

#include <opencv2/cudacodec.hpp>

Utility function demonstrating how to map the luma histogram when FormatInfo::videoFullRangeFlag == false.

Parameters
histLuma histogram hist returned from VideoReader::nextFrame(GpuMat& frame, GpuMat& hist, Stream& stream).
histFullHost histogram equivelent to downloading hist after calling cuda::calcHist(InputArray frame, OutputArray hist, Stream& stream).
Note
  • This function demonstrates how to map the luma histogram back so that it is equivalent to the result obtained from cuda::calcHist() if the returned frame was colorFormat::GRAY.

◆ operator==()

bool cv::cudacodec::operator== ( const EncoderParams lhs,
const EncoderParams rhs 
)