Video Encoding/Decoding#
Detailed Description#
Classes#
Name |
Description |
|---|---|
|
|
Interface for encoder callbacks. View details |
|
|
Different parameters for CUDA video encoder. View details |
|
Struct providing information about video file format. : View details |
Class for converting the raw YUV Surface output from VideoReader if output color format is set to ColorFormat::NV_YUV_SURFACE_FORMAT (VideoReader::set(ColorFormat::NV_YUV_SURFACE_FORMAT)) to the requested ColorFormat. View details |
|
Interface for video demultiplexing. : View details |
|
Video reader interface, see createVideoReader(). View details |
|
VideoReader initialization parameters. View details |
|
Video writer interface, see createVideoWriter(). View details |
Enumerations#
enum cv::cudacodec::BitDepth {
cv::cudacodec::EIGHT = 0,
cv::cudacodec::SIXTEEN = 1,
cv::cudacodec::UNCHANGED = 2
}Bit depth of the frame returned by VideoReader::nextFrame() and VideoReader::retrieve() View details
Chroma formats supported by cudacodec::VideoReader. View details
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. View details
enum cv::cudacodec::ColorFormat {
cv::cudacodec::UNDEFINED = 0,
cv::cudacodec::BGRA = 1,
cv::cudacodec::BGR = 2,
cv::cudacodec::GRAY = 3,
cv::cudacodec::RGB = 5,
cv::cudacodec::RGBA = 6,
cv::cudacodec::NV_YUV_SURFACE_FORMAT = 7,
cv::cudacodec::NV_NV12 = 4,
cv::cudacodec::NV_YV12 = 8,
cv::cudacodec::NV_IYUV = 9,
cv::cudacodec::NV_YUV444 = 10,
cv::cudacodec::NV_AYUV = 11,
cv::cudacodec::NV_YUV420_10BIT = 12,
cv::cudacodec::NV_YUV444_10BIT = 13
}ColorFormat for the frame returned by VideoReader::nextFrame() and VideoReader::retrieve() or used to initialize a VideoWriter. View details
enum struct cv::cudacodec::ColorSpaceStandard {
cv::cudacodec::ColorSpaceStandard::BT709 = 1,
cv::cudacodec::ColorSpaceStandard::Unspecified = 2,
cv::cudacodec::ColorSpaceStandard::Reserved = 3,
cv::cudacodec::ColorSpaceStandard::FCC = 4,
cv::cudacodec::ColorSpaceStandard::BT470 = 5,
cv::cudacodec::ColorSpaceStandard::BT601 = 6,
cv::cudacodec::ColorSpaceStandard::SMPTE240M = 7,
cv::cudacodec::ColorSpaceStandard::YCgCo = 8,
cv::cudacodec::ColorSpaceStandard::BT2020 = 9,
cv::cudacodec::ColorSpaceStandard::BT2020C = 10
}Video Signal Description Color Primaries of the VideoReader source (section E.2.1 VUI parameters semantics of H265 spec file) View details
enum cv::cudacodec::DeinterlaceMode {
cv::cudacodec::Weave = 0,
cv::cudacodec::Bob = 1,
cv::cudacodec::Adaptive = 2
}Deinterlacing mode used by decoder. View details
Multi Pass Encoding. View details
Rate Control Modes. View details
Nvidia Encoding Presets. Performance degrades and quality improves as we move from P1 to P7. View details
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. View details
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. View details
enum cv::cudacodec::SurfaceFormat {
cv::cudacodec::SF_NV12 = 0,
cv::cudacodec::SF_P016 = 1,
cv::cudacodec::SF_YUV444 = 2,
cv::cudacodec::SF_YUV444_16Bit = 3
}Video surface formats output by the decoder. View details
enum struct 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::VideoReaderProps::PROP_BIT_DEPTH = 9,
cv::cudacodec::VideoReaderProps::PROP_PLANAR = 10
}cv::cudacodec::VideoReader generic properties identifier. View details
Enumeration Type Documentation#
BitDepth#
#include <opencv2/cudacodec.hpp>
Bit depth of the frame returned by VideoReader::nextFrame() and VideoReader::retrieve()
Enumerator:
|
8 bit depth. |
|
16 bit depth. |
|
Use source bit depth. |
ChromaFormat#
enum cv::cudacodec::ChromaFormat
#include <opencv2/cudacodec.hpp>
Chroma formats supported by cudacodec::VideoReader.
Enumerator:
|
|
|
|
|
Codec#
enum cv::cudacodec::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:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Y,U,V (4:2:0) |
|
Y,V,U (4:2:0) |
|
Y,UV (4:2:0) |
|
YUYV/YUY2 (4:2:2) |
|
UYVY (4:2:2) |
ColorFormat#
enum cv::cudacodec::ColorFormat
#include <opencv2/cudacodec.hpp>
ColorFormat for the frame returned by VideoReader::nextFrame() and VideoReader::retrieve() or used to initialize a VideoWriter.
Enumerator:
|
|
|
OpenCV color format. VideoReader and VideoWriter. |
|
OpenCV color format. VideoReader and VideoWriter. |
|
OpenCV color format. VideoReader and VideoWriter. |
|
OpenCV color format. VideoReader and VideoWriter. |
|
OpenCV color format. VideoReader and VideoWriter. |
|
Nvidia YUV Surface Format output by the Nvidia decoder, see SurfaceFormat. VideoReader only. |
|
Nvidia Buffer Format - Semi-Planar YUV [Y plane followed by interleaved UV plane]. VideoWriter only. Deprecated Deprecated for use with VideoReader, use NV_YUV_SURFACE_FORMAT instead. |
|
Nvidia Buffer Format - Planar YUV [Y plane followed by V and U planes]. VideoWriter only. |
|
Nvidia Buffer Format - Planar YUV [Y plane followed by U and V planes]. VideoWriter only. |
|
Nvidia Buffer Format - Planar YUV [Y plane followed by U and V planes]. VideoWriter only. |
|
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. VideoWriter only. |
|
Nvidia Buffer Format - 10 bit Semi-Planar YUV [Y plane followed by interleaved UV plane]. Each pixel of size 2 bytes. Most Significant 10 bits contain pixel data. VideoWriter only. |
|
Nvidia Buffer Format - 10 bit Planar YUV444 [Y plane followed by U and V planes]. Each pixel of size 2 bytes. Most Significant 10 bits contain pixel data. VideoWriter only. |
ColorSpaceStandard#
enum class cv::cudacodec::ColorSpaceStandard
#include <opencv2/cudacodec.hpp>
Video Signal Description Color Primaries of the VideoReader source (section E.2.1 VUI parameters semantics of H265 spec file)
Enumerator:
|
ITU-R [151] standard for high-definition television. |
|
Unspecified color space standard. |
|
Reserved for future use. |
|
FCC color space standard. |
|
ITU - R BT.470, used for older analog television systems. |
|
ITU - R BT.601, used for standard definition television. |
|
SMPTE 240M, used for early HDTV systems. |
|
YCgCo color space, used in some video compression algorithms. |
|
ITU - R BT.2020, used for ultra-high-definition television. |
|
ITU - R BT.2020 Constant Luminance, used for ultra-high-definition television. |
DeinterlaceMode#
enum cv::cudacodec::DeinterlaceMode
#include <opencv2/cudacodec.hpp>
Deinterlacing mode used by decoder.
Enumerator:
|
Weave both fields(no deinterlacing).For progressive content and for content that doesn’t need deinterlacing. |
|
Drop one field. |
|
Adaptive deinterlacing needs more video memory than other deinterlacing modes. |
EncodeMultiPass#
enum cv::cudacodec::EncodeMultiPass
#include <opencv2/cudacodec.hpp>
Multi Pass Encoding.
Enumerator:
|
Single Pass. |
|
Two Pass encoding is enabled where first Pass is quarter resolution. |
|
Two Pass encoding is enabled where first Pass is full resolution. |
EncodeParamsRcMode#
enum cv::cudacodec::EncodeParamsRcMode
#include <opencv2/cudacodec.hpp>
Rate Control Modes.
Enumerator:
|
Constant QP mode. |
|
Variable bitrate mode. |
|
Constant bitrate mode. |
EncodePreset#
enum cv::cudacodec::EncodePreset
#include <opencv2/cudacodec.hpp>
Nvidia Encoding Presets. Performance degrades and quality improves as we move from P1 to P7.
Enumerator:
|
|
|
|
|
|
|
EncodeProfile#
enum cv::cudacodec::EncodeProfile
#include <opencv2/cudacodec.hpp>
Supported Encoder Profiles.
Enumerator:
|
|
|
|
|
|
|
|
|
|
|
EncodeTuningInfo#
enum cv::cudacodec::EncodeTuningInfo
#include <opencv2/cudacodec.hpp>
Tuning information.
Enumerator:
|
Undefined tuningInfo. Invalid value for encoding. |
|
Tune presets for latency tolerant encoding. |
|
Tune presets for low latency streaming. |
|
Tune presets for ultra low latency streaming. |
|
Tune presets for lossless encoding. |
|
SurfaceFormat#
enum cv::cudacodec::SurfaceFormat
#include <opencv2/cudacodec.hpp>
Video surface formats output by the decoder.
Enumerator:
|
Semi-Planar YUV [Y plane followed by interleaved UV plane]. |
|
16 bit Semi-Planar YUV [Y plane followed by interleaved UV plane]. Can be used for 10 bit(6LSB bits 0), 12 bit (4LSB bits 0) |
|
Planar YUV [Y plane followed by U and V planes]. |
|
16 bit Planar YUV [Y plane followed by U and V planes]. Can be used for 10 bit(6LSB bits 0), 12 bit (4LSB bits 0) |
VideoReaderProps#
enum class cv::cudacodec::VideoReaderProps
#include <opencv2/cudacodec.hpp>
cv::cudacodec::VideoReader generic properties identifier.
Enumerator:
|
Index for retrieving the decoded frame using retrieve(). |
|
Index for retrieving the extra data associated with a video source using retrieve(). |
|
Base index for retrieving raw encoded data using retrieve(). |
|
Number of raw packages recieved since the last call to grab(). |
|
Status of raw mode. |
|
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. |
|
ColorFormat of the decoded frame. This can be changed before every call to nextFrame() and retrieve(). |
|
Status of VideoReaderInitParams::udpSource initialization. |
|
Status of VideoReaderInitParams::allowFrameDrop initialization. |
|
Bit depth of the decoded frame. This can be changed before every call to nextFrame() and retrieve(). |
|
Planar when true, packed when false. This can be changed before every call to nextFrame() and retrieve(). |
Function Documentation#
createNVSurfaceToColorConverter()#
Ptr< NVSurfaceToColorConverter > cv::cudacodec::createNVSurfaceToColorConverter(
const ColorSpaceStandard colorSpace,
const bool videoFullRangeFlag = false )
#include <opencv2/cudacodec.hpp>
Creates a NVSurfaceToColorConverter.
Parameters
colorSpace— The requested ColorSpaceStandard for the converter.videoFullRangeFlag— Indicates if the black level, luma and chroma of the source are represented using the full or limited range (AKA TV or “analogue” range) of values as defined in Annex E of the ITU-T Specification.
createVideoReader()#
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
source— RAW video source implemented by user.params— Initializaton parameters. See cv::cudacodec::VideoReaderInitParams.
createVideoReader()#
Ptr< VideoReader > cv::cudacodec::createVideoReader(
const String & filename,
const std::vector< int > & sourceParams = {},
const VideoReaderInitParams params = VideoReaderInitParams() )
#include <opencv2/cudacodec.hpp>
Creates video reader.
FFMPEG is used to read videos. User can implement own demultiplexing with cudacodec::RawVideoSource
Parameters
filename— Name of the input video file.sourceParams— Pass through parameters for VideoCapure. VideoCapture with the FFMpeg back end (CAP_FFMPEG) is used to parse the video input. ThesourceParamsparameter 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.params— Initializaton parameters. See cv::cudacodec::VideoReaderInitParams.
createVideoWriter()#
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
fileName— Name of the output video file.frameSize— Size of the input video frames.codec— Supports Codec::H264 and Codec::HEVC.fps— Framerate of the created video stream.colorFormat— OpenCv color format of the frames to be encoded.params— Additional encoding parameters.encoderCallback— Callbacks for video encoder. See cudacodec::EncoderCallback. Required for working with the encoded video stream.stream— Stream for frame pre-processing.
createVideoWriter()#
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
fileName— Name of the output video file.frameSize— Size of the input video frames.codec— Supports Codec::H264 and Codec::HEVC.fps— Framerate of the created video stream.colorFormat— OpenCv color format of the frames to be encoded.encoderCallback— Callbacks for video encoder. See cudacodec::EncoderCallback. Required for working with the encoded video stream.stream— Stream 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.
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.
Parameters
hist— Luma histogram hist returned from VideoReader::nextFrame(GpuMat& frame, GpuMat& hist, Stream& stream).histFull— Host histogram equivelent to downloading hist after calling cuda::calcHist(InputArray frame, OutputArray hist, Stream& stream).
operator==()#
bool cv::cudacodec::operator==(
const EncoderParams & lhs,
const EncoderParams & rhs )
#include <opencv2/cudacodec.hpp>