Skip to content

Commit 6de28c2

Browse files
committed
Merge branch 4.x
2 parents 6437f18 + ce3c668 commit 6de28c2

File tree

6 files changed

+38
-31
lines changed

6 files changed

+38
-31
lines changed

Diff for: modules/cudacodec/include/opencv2/cudacodec.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ struct CV_EXPORTS_W_SIMPLE EncoderParams
186186
public:
187187
CV_WRAP EncoderParams() : nvPreset(ENC_PRESET_P3), tuningInfo(ENC_TUNING_INFO_HIGH_QUALITY), encodingProfile(ENC_CODEC_PROFILE_AUTOSELECT),
188188
rateControlMode(ENC_PARAMS_RC_VBR), multiPassEncoding(ENC_MULTI_PASS_DISABLED), constQp({ 0,0,0 }), averageBitRate(0), maxBitRate(0),
189-
targetQuality(30), gopLength(250), idrPeriod(250) {};
189+
targetQuality(30), gopLength(250), idrPeriod(250), videoFullRangeFlag(false){};
190190
CV_PROP_RW EncodePreset nvPreset;
191191
CV_PROP_RW EncodeTuningInfo tuningInfo;
192192
CV_PROP_RW EncodeProfile encodingProfile;
@@ -198,6 +198,7 @@ struct CV_EXPORTS_W_SIMPLE EncoderParams
198198
CV_PROP_RW uint8_t targetQuality; //!< value 0 - 51 where video quality decreases as targetQuality increases, used with \ref ENC_PARAMS_RC_VBR.
199199
CV_PROP_RW int gopLength; //!< the number of pictures in one GOP, ensuring \ref idrPeriod >= \ref gopLength.
200200
CV_PROP_RW int idrPeriod; //!< IDR interval, ensuring \ref idrPeriod >= \ref gopLength.
201+
CV_PROP_RW bool 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.
201202
};
202203
CV_EXPORTS bool operator==(const EncoderParams& lhs, const EncoderParams& rhs);
203204

Diff for: modules/cudacodec/src/NvEncoder.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void NvEncoder::CreateDefaultEncoderParams(NV_ENC_INITIALIZE_PARAMS* pIntializeP
101101
#endif
102102
pIntializeParams->tuningInfo = tuningInfo;
103103
pIntializeParams->encodeConfig->rcParams.rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
104-
#if (NVENCAPI_MAJOR_VERSION >= 12 && NVENCAPI_MINOR_VERSION >= 2)
104+
#if ((NVENCAPI_MAJOR_VERSION == 12 && NVENCAPI_MINOR_VERSION >= 2) || NVENCAPI_MAJOR_VERSION > 12)
105105
NV_ENC_PRESET_CONFIG presetConfig = { NV_ENC_PRESET_CONFIG_VER, 0, { NV_ENC_CONFIG_VER } };
106106
#else
107107
NV_ENC_PRESET_CONFIG presetConfig = { NV_ENC_PRESET_CONFIG_VER, { NV_ENC_CONFIG_VER } };
@@ -119,7 +119,7 @@ void NvEncoder::CreateDefaultEncoderParams(NV_ENC_INITIALIZE_PARAMS* pIntializeP
119119
}
120120
else if (pIntializeParams->encodeGUID == NV_ENC_CODEC_HEVC_GUID)
121121
{
122-
#if (NVENCAPI_MAJOR_VERSION >= 12 && NVENCAPI_MINOR_VERSION >= 2)
122+
#if ((NVENCAPI_MAJOR_VERSION == 12 && NVENCAPI_MINOR_VERSION >= 2) || NVENCAPI_MAJOR_VERSION > 12)
123123
pIntializeParams->encodeConfig->encodeCodecConfig.hevcConfig.inputBitDepth = pIntializeParams->encodeConfig->encodeCodecConfig.hevcConfig.outputBitDepth =
124124
(m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV420_10BIT || m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444_10BIT) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
125125
#else
@@ -179,7 +179,7 @@ void NvEncoder::CreateEncoder(const NV_ENC_INITIALIZE_PARAMS* pEncoderParams)
179179
if (pEncoderParams->encodeGUID == NV_ENC_CODEC_HEVC_GUID)
180180
{
181181
bool yuv10BitFormat = (m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV420_10BIT || m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444_10BIT) ? true : false;
182-
#if (NVENCAPI_MAJOR_VERSION >= 12 && NVENCAPI_MINOR_VERSION >= 2)
182+
#if ((NVENCAPI_MAJOR_VERSION == 12 && NVENCAPI_MINOR_VERSION >= 2) || NVENCAPI_MAJOR_VERSION > 12)
183183
if (yuv10BitFormat && pEncoderParams->encodeConfig->encodeCodecConfig.hevcConfig.inputBitDepth != NV_ENC_BIT_DEPTH_10)
184184
#else
185185
if (yuv10BitFormat && pEncoderParams->encodeConfig->encodeCodecConfig.hevcConfig.pixelBitDepthMinus8 != 2)
@@ -205,7 +205,7 @@ void NvEncoder::CreateEncoder(const NV_ENC_INITIALIZE_PARAMS* pEncoderParams)
205205
}
206206
else
207207
{
208-
#if (NVENCAPI_MAJOR_VERSION >= 12 && NVENCAPI_MINOR_VERSION >= 2)
208+
#if ((NVENCAPI_MAJOR_VERSION == 12 && NVENCAPI_MINOR_VERSION >= 2) || NVENCAPI_MAJOR_VERSION > 12)
209209
NV_ENC_PRESET_CONFIG presetConfig = { NV_ENC_PRESET_CONFIG_VER, 0, { NV_ENC_CONFIG_VER } };
210210
#else
211211
NV_ENC_PRESET_CONFIG presetConfig = { NV_ENC_PRESET_CONFIG_VER, { NV_ENC_CONFIG_VER } };

Diff for: modules/cudacodec/src/video_writer.cpp

+24-11
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ Ptr<cudacodec::VideoWriter> createVideoWriter(const String&, const Size, const C
5353

5454
#else // !defined HAVE_NVCUVENC
5555

56-
#if defined(WIN32) // remove when FFmpeg wrapper includes PR25874
57-
#define WIN32_WAIT_FOR_FFMPEG_WRAPPER_UPDATE
58-
#endif
59-
6056
NV_ENC_BUFFER_FORMAT EncBufferFormat(const ColorFormat colorFormat);
6157
int NChannels(const ColorFormat colorFormat);
6258
GUID CodecGuid(const Codec codec);
@@ -86,7 +82,7 @@ class FFmpegVideoWriter : public EncoderCallback
8682
FFmpegVideoWriter::FFmpegVideoWriter(const String& fileName, const Codec codec, const int fps, const Size sz, const int idrPeriod) {
8783
if (!videoio_registry::hasBackend(CAP_FFMPEG))
8884
CV_Error(Error::StsNotImplemented, "FFmpeg backend not found");
89-
const int fourcc = codec == Codec::H264 ? cv::VideoWriter::fourcc('a', 'v', 'c', '1') : cv::VideoWriter::fourcc('h', 'e', 'v', '1');
85+
const int fourcc = codec == Codec::H264 ? cv::VideoWriter::fourcc('a', 'v', 'c', '1') : cv::VideoWriter::fourcc('h', 'v', 'c', '1');
9086
writer.open(fileName, fourcc, fps, sz, { VideoWriterProperties::VIDEOWRITER_PROP_RAW_VIDEO, 1, VideoWriterProperties::VIDEOWRITER_PROP_KEY_INTERVAL, idrPeriod });
9187
if (!writer.isOpened())
9288
CV_Error(Error::StsUnsupportedFormat, "Unsupported video sink");
@@ -107,9 +103,7 @@ void FFmpegVideoWriter::onEncoded(const std::vector<std::vector<uint8_t>>& vPack
107103
Mat wrappedPacket(1, packet.size(), CV_8UC1, (void*)packet.data());
108104
const double ptsDouble = static_cast<double>(pts.at(i));
109105
CV_Assert(static_cast<uint64_t>(ptsDouble) == pts.at(i));
110-
#if !defined(WIN32_WAIT_FOR_FFMPEG_WRAPPER_UPDATE)
111106
CV_Assert(writer.set(VIDEOWRITER_PROP_PTS, ptsDouble));
112-
#endif
113107
writer.write(wrappedPacket);
114108
}
115109
}
@@ -321,6 +315,13 @@ GUID EncodingPresetGuid(const EncodePreset nvPreset) {
321315
CV_Error(Error::StsUnsupportedFormat, msg);
322316
}
323317

318+
std::string GetVideoCodecString(const GUID codec) {
319+
if (codec == NV_ENC_CODEC_H264_GUID) return "AVC/H.264";
320+
else if (codec == NV_ENC_CODEC_HEVC_GUID) return "H.265/HEVC";
321+
else if (codec == NV_ENC_CODEC_AV1_GUID) return "AV1";
322+
else return "Unknown";
323+
}
324+
324325
void VideoWriterImpl::InitializeEncoder(const GUID codec, const double fps)
325326
{
326327
NV_ENC_INITIALIZE_PARAMS initializeParams = {};
@@ -337,15 +338,27 @@ void VideoWriterImpl::InitializeEncoder(const GUID codec, const double fps)
337338
initializeParams.encodeConfig->rcParams.maxBitRate = encoderParams.maxBitRate;
338339
initializeParams.encodeConfig->rcParams.targetQuality = encoderParams.targetQuality;
339340
initializeParams.encodeConfig->gopLength = encoderParams.gopLength;
340-
#if !defined(WIN32_WAIT_FOR_FFMPEG_WRAPPER_UPDATE)
341341
if (initializeParams.encodeConfig->frameIntervalP > 1) {
342342
CV_Assert(encoderCallback->setFrameIntervalP(initializeParams.encodeConfig->frameIntervalP));
343343
}
344-
#endif
345-
if (codec == NV_ENC_CODEC_H264_GUID)
344+
if (codec == NV_ENC_CODEC_H264_GUID) {
346345
initializeParams.encodeConfig->encodeCodecConfig.h264Config.idrPeriod = encoderParams.idrPeriod;
347-
else if (codec == NV_ENC_CODEC_HEVC_GUID)
346+
if (encoderParams.videoFullRangeFlag) {
347+
initializeParams.encodeConfig->encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag = 1;
348+
initializeParams.encodeConfig->encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1;
349+
}
350+
}
351+
else if (codec == NV_ENC_CODEC_HEVC_GUID) {
348352
initializeParams.encodeConfig->encodeCodecConfig.hevcConfig.idrPeriod = encoderParams.idrPeriod;
353+
if (encoderParams.videoFullRangeFlag) {
354+
initializeParams.encodeConfig->encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFullRangeFlag = 1;
355+
initializeParams.encodeConfig->encodeCodecConfig.hevcConfig.hevcVUIParameters.videoSignalTypePresentFlag = 1;
356+
}
357+
}
358+
else {
359+
std::string msg = "videoFullRangeFlag is not supported by codec: " + GetVideoCodecString(codec);
360+
CV_LOG_WARNING(NULL, msg);
361+
}
349362
pEnc->CreateEncoder(&initializeParams);
350363
}
351364

Diff for: modules/cudacodec/test/test_video.cpp

+5-13
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,6 @@ struct H264ToH265 : SetDevice
10111011
{
10121012
};
10131013

1014-
#if defined(WIN32) // remove when FFmpeg wrapper includes PR25874
1015-
#define WIN32_WAIT_FOR_FFMPEG_WRAPPER_UPDATE
1016-
#endif
1017-
10181014
CUDA_TEST_P(H264ToH265, Transcode)
10191015
{
10201016
const std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "../highgui/video/big_buck_bunny.h264";
@@ -1054,10 +1050,8 @@ CUDA_TEST_P(H264ToH265, Transcode)
10541050
for (int i = 0; i < nFrames; ++i) {
10551051
cap >> frame;
10561052
ASSERT_FALSE(frame.empty());
1057-
#if !defined(WIN32_WAIT_FOR_FFMPEG_WRAPPER_UPDATE)
10581053
const int pts = static_cast<int>(cap.get(CAP_PROP_PTS));
10591054
ASSERT_EQ(i, pts > 0 ? pts : 0); // FFmpeg back end returns dts if pts is zero.
1060-
#endif
10611055
}
10621056
}
10631057
ASSERT_EQ(0, remove(outputFile.c_str()));
@@ -1066,7 +1060,7 @@ CUDA_TEST_P(H264ToH265, Transcode)
10661060
INSTANTIATE_TEST_CASE_P(CUDA_Codec, H264ToH265, ALL_DEVICES);
10671061

10681062
CV_ENUM(YuvColorFormats, cudacodec::ColorFormat::NV_YUV444, cudacodec::ColorFormat::NV_YUV420_10BIT, cudacodec::ColorFormat::NV_YUV444_10BIT)
1069-
PARAM_TEST_CASE(YUVFormats, cv::cuda::DeviceInfo, YuvColorFormats)
1063+
PARAM_TEST_CASE(YUVFormats, cv::cuda::DeviceInfo, YuvColorFormats, bool)
10701064
{
10711065
};
10721066

@@ -1075,6 +1069,7 @@ CUDA_TEST_P(YUVFormats, Transcode)
10751069
cv::cuda::setDevice(GET_PARAM(0).deviceID());
10761070
const std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "../highgui/video/big_buck_bunny.h265";
10771071
const cv::cudacodec::ColorFormat writerColorFormat = static_cast<cudacodec::ColorFormat>(static_cast<int>(GET_PARAM(1)));
1072+
const bool fullRange = GET_PARAM(2);
10781073
constexpr double fps = 25;
10791074
const cudacodec::Codec codec = cudacodec::Codec::HEVC;
10801075
const std::string ext = ".mp4";
@@ -1088,6 +1083,7 @@ CUDA_TEST_P(YUVFormats, Transcode)
10881083
cv::cudacodec::EncoderParams params;
10891084
params.tuningInfo = cv::cudacodec::EncodeTuningInfo::ENC_TUNING_INFO_LOSSLESS;
10901085
params.rateControlMode = cv::cudacodec::EncodeParamsRcMode::ENC_PARAMS_RC_CONSTQP;
1086+
params.videoFullRangeFlag = fullRange;
10911087
for (int i = 0; i < nFrames; ++i) {
10921088
ASSERT_TRUE(cap.read(frame));
10931089
ASSERT_FALSE(frame.empty());
@@ -1101,7 +1097,7 @@ CUDA_TEST_P(YUVFormats, Transcode)
11011097
yuvFormat = cudacodec::SurfaceFormat::SF_P016;
11021098
bitDepth = cudacodec::BitDepth::SIXTEEN;
11031099
}
1104-
generateTestImages(frame, yuv, bgr, yuvFormat, cudacodec::ColorFormat::BGR, bitDepth, false);
1100+
generateTestImages(frame, yuv, bgr, yuvFormat, cudacodec::ColorFormat::BGR, bitDepth, false, fullRange);
11051101
bgrGs.push_back(bgr.clone());
11061102
if (writer.empty())
11071103
writer = cv::cudacodec::createVideoWriter(outputFile, frame.size(), codec, fps, writerColorFormat, params);
@@ -1125,7 +1121,7 @@ CUDA_TEST_P(YUVFormats, Transcode)
11251121
ASSERT_EQ(0, remove(outputFile.c_str()));
11261122
}
11271123

1128-
INSTANTIATE_TEST_CASE_P(CUDA_Codec, YUVFormats, testing::Combine(ALL_DEVICES, YuvColorFormats::all()));
1124+
INSTANTIATE_TEST_CASE_P(CUDA_Codec, YUVFormats, testing::Combine(ALL_DEVICES, YuvColorFormats::all(), testing::Bool()));
11291125
#endif
11301126

11311127
#if defined(HAVE_NVCUVENC)
@@ -1201,10 +1197,8 @@ CUDA_TEST_P(Write, Writer)
12011197
for (int i = 0; i < nFrames; ++i) {
12021198
cap >> frame;
12031199
ASSERT_FALSE(frame.empty());
1204-
#if !defined(WIN32_WAIT_FOR_FFMPEG_WRAPPER_UPDATE)
12051200
const int pts = static_cast<int>(cap.get(CAP_PROP_PTS));
12061201
ASSERT_EQ(i, pts > 0 ? pts : 0); // FFmpeg back end returns dts if pts is zero.
1207-
#endif
12081202
}
12091203
}
12101204
ASSERT_EQ(0, remove(outputFile.c_str()));
@@ -1299,10 +1293,8 @@ CUDA_TEST_P(EncoderParams, Writer)
12991293
const bool keyFrameActual = capRaw.get(CAP_PROP_LRF_HAS_KEY_FRAME) == 1.0;
13001294
const bool keyFrameReference = i % idrPeriod == 0;
13011295
ASSERT_EQ(keyFrameActual, keyFrameReference);
1302-
#if !defined(WIN32_WAIT_FOR_FFMPEG_WRAPPER_UPDATE)
13031296
const int pts = static_cast<int>(cap.get(CAP_PROP_PTS));
13041297
ASSERT_EQ(i, pts > 0 ? pts : 0); // FFmpeg back end returns dts if pts is zero.
1305-
#endif
13061298
}
13071299
}
13081300
}

Diff for: modules/cudalegacy/include/opencv2/cudalegacy/private.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ namespace cv { namespace cuda
9191

9292
//! @endcond
9393

94-
#endif HAVE_CUDA
94+
#endif // HAVE_CUDA
9595

9696
#endif // OPENCV_CORE_CUDALEGACY_PRIVATE_HPP

Diff for: modules/ml/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ ocv_create_module()
77

88
ocv_add_accuracy_tests()
99
ocv_add_perf_tests()
10-
ocv_add_samples(opencv_imgproc opencv_objdetect opencv_video)
10+
# dnn is transitive dependency pf opencv_video
11+
ocv_add_samples(opencv_imgproc opencv_objdetect opencv_video opencv_dnn)

0 commit comments

Comments
 (0)