Skip to content

Commit 72080b8

Browse files
committed
cudacodec::VideoReader - amend FFmpeg codec resolution
1 parent 813967b commit 72080b8

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

modules/cudacodec/src/ffmpeg_video_source.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ static std::string fourccToString(int fourcc)
6666
(i32_c.c[3] >= ' ' && i32_c.c[3] < 128) ? i32_c.c[3] : '?');
6767
}
6868

69+
// handle old FFmpeg backend - remove when windows shared library is updated
70+
#ifdef _WIN32
6971
static
70-
Codec FourccToCodec(int codec)
72+
Codec FourccToCodecWin32Old(int codec)
7173
{
7274
switch (codec)
7375
{
@@ -100,9 +102,34 @@ Codec FourccToCodec(int codec)
100102
case CV_FOURCC_MACRO('a', 'v', '0', '1'): // fallthru
101103
case CV_FOURCC_MACRO('A', 'V', '0', '1'): return AV1;
102104
default:
103-
break;
105+
return NumCodecs;
104106
}
107+
}
108+
#endif
105109

110+
static
111+
Codec FourccToCodec(int codec)
112+
{
113+
#ifdef _WIN32 // handle old FFmpeg backend - remove when windows shared library is updated
114+
Codec win32OldCodec = FourccToCodecWin32Old(codec);
115+
if(win32OldCodec != NumCodecs)
116+
return win32OldCodec;
117+
#endif
118+
switch (codec)
119+
{
120+
case CV_FOURCC_MACRO('m', 'p', 'g', '1'): return MPEG1;
121+
case CV_FOURCC_MACRO('m', 'p', 'g', '2'): return MPEG2;
122+
case CV_FOURCC_MACRO('F', 'M', 'P', '4'): return MPEG4;
123+
case CV_FOURCC_MACRO('W', 'V', 'C', '1'): return VC1;
124+
case CV_FOURCC_MACRO('h', '2', '6', '4'): return H264;
125+
case CV_FOURCC_MACRO('h', 'e', 'v', 'c'): return HEVC;
126+
case CV_FOURCC_MACRO('M', 'J', 'P', 'G'): return JPEG;
127+
case CV_FOURCC_MACRO('V', 'P', '8', '0'): return VP8;
128+
case CV_FOURCC_MACRO('V', 'P', '9', '0'): return VP9;
129+
case CV_FOURCC_MACRO('A', 'V', '0', '1'): return AV1;
130+
default:
131+
break;
132+
}
106133
std::string msg = cv::format("Unknown codec FOURCC: 0x%08X (%s)", codec, fourccToString(codec).c_str());
107134
CV_LOG_WARNING(NULL, msg);
108135
CV_Error(Error::StsUnsupportedFormat, msg);
@@ -163,7 +190,6 @@ cv::cudacodec::detail::FFmpegVideoSource::FFmpegVideoSource(const String& fname,
163190

164191
int codec = (int)cap.get(CAP_PROP_FOURCC);
165192
int pixelFormat = (int)cap.get(CAP_PROP_CODEC_PIXEL_FORMAT);
166-
167193
format_.codec = FourccToCodec(codec);
168194
format_.height = cap.get(CAP_PROP_FRAME_HEIGHT);
169195
format_.width = cap.get(CAP_PROP_FRAME_WIDTH);

modules/cudacodec/test/test_video.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,11 @@ CUDA_TEST_P(DisplayResolution, Reader)
281281
CUDA_TEST_P(Video, Reader)
282282
{
283283
cv::cuda::setDevice(GET_PARAM(0).deviceID());
284+
const std::string relativeFilePath = GET_PARAM(1);
284285

285286
// CUDA demuxer has to fall back to ffmpeg to process "cv/video/768x576.avi"
286-
if (GET_PARAM(1) == "cv/video/768x576.avi" && !videoio_registry::hasBackend(CAP_FFMPEG))
287-
throw SkipTestException("FFmpeg backend not found");
288-
289-
#ifdef _WIN32 // handle old FFmpeg backend
290-
if (GET_PARAM(1) == "/cv/tracking/faceocc2/data/faceocc2.webm")
291-
throw SkipTestException("Feature not yet supported by Windows FFmpeg shared library!");
292-
#endif
287+
if (relativeFilePath == "cv/video/768x576.avi" && !videoio_registry::hasBackend(CAP_FFMPEG))
288+
throw SkipTestException("FFmpeg backend not found - SKIP");
293289

294290
const std::vector<std::pair< cudacodec::ColorFormat, int>> formatsToChannels = {
295291
{cudacodec::ColorFormat::GRAY,1},
@@ -298,7 +294,7 @@ CUDA_TEST_P(Video, Reader)
298294
{cudacodec::ColorFormat::NV_NV12,1}
299295
};
300296

301-
std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "../" + GET_PARAM(1);
297+
std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "../" + relativeFilePath;
302298
cv::Ptr<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile);
303299
ASSERT_FALSE(reader->set(cudacodec::ColorFormat::RGB));
304300
cv::cudacodec::FormatInfo fmt = reader->format();
@@ -818,13 +814,20 @@ INSTANTIATE_TEST_CASE_P(CUDA_Codec, Scaling, testing::Combine(
818814

819815
INSTANTIATE_TEST_CASE_P(CUDA_Codec, DisplayResolution, ALL_DEVICES);
820816

821-
#define VIDEO_SRC_R "highgui/video/big_buck_bunny.mp4", "cv/video/768x576.avi", "cv/video/1920x1080.avi", "highgui/video/big_buck_bunny.avi", \
817+
#ifdef _WIN32 // handle old FFmpeg backend - remove when windows shared library is updated
818+
#define VIDEO_SRC_R testing::Values("highgui/video/big_buck_bunny.mp4", "cv/video/768x576.avi", "cv/video/1920x1080.avi", "highgui/video/big_buck_bunny.avi", \
822819
"highgui/video/big_buck_bunny.h264", "highgui/video/big_buck_bunny.h265", "highgui/video/big_buck_bunny.mpg", \
823-
"highgui/video/sample_322x242_15frames.yuv420p.libvpx-vp9.mp4", "highgui/video/sample_322x242_15frames.yuv420p.libaom-av1.mp4", \
824-
"cv/tracking/faceocc2/data/faceocc2.webm"
825-
INSTANTIATE_TEST_CASE_P(CUDA_Codec, Video, testing::Combine(
826-
ALL_DEVICES,
827-
testing::Values(VIDEO_SRC_R)));
820+
"highgui/video/sample_322x242_15frames.yuv420p.libvpx-vp9.mp4")
821+
//, "highgui/video/sample_322x242_15frames.yuv420p.libaom-av1.mp4", \
822+
"cv/tracking/faceocc2/data/faceocc2.webm")
823+
#else
824+
#define VIDEO_SRC_R testing::Values("highgui/video/big_buck_bunny.mp4", "cv/video/768x576.avi", "cv/video/1920x1080.avi", "highgui/video/big_buck_bunny.avi", \
825+
"highgui/video/big_buck_bunny.h264", "highgui/video/big_buck_bunny.h265", "highgui/video/big_buck_bunny.mpg", \
826+
"highgui/video/sample_322x242_15frames.yuv420p.libvpx-vp9.mp4")
827+
//, "highgui/video/sample_322x242_15frames.yuv420p.libaom-av1.mp4", \
828+
"cv/tracking/faceocc2/data/faceocc2.webm", "highgui/video/sample_322x242_15frames.yuv420p.mpeg2video.mp4", "highgui/video/sample_322x242_15frames.yuv420p.mjpeg.mp4")
829+
#endif
830+
INSTANTIATE_TEST_CASE_P(CUDA_Codec, Video, testing::Combine(ALL_DEVICES,VIDEO_SRC_R));
828831

829832
const color_conversion_params_t color_conversion_params[] =
830833
{
@@ -859,9 +862,11 @@ INSTANTIATE_TEST_CASE_P(CUDA_Codec, CheckExtraData, testing::Combine(
859862
ALL_DEVICES,
860863
testing::ValuesIn(check_extra_data_params)));
861864

865+
#define VIDEO_SRC_KEY "highgui/video/big_buck_bunny.mp4", "cv/video/768x576.avi", "cv/video/1920x1080.avi", "highgui/video/big_buck_bunny.avi", \
866+
"highgui/video/big_buck_bunny.h264", "highgui/video/big_buck_bunny.h265", "highgui/video/big_buck_bunny.mpg"
862867
INSTANTIATE_TEST_CASE_P(CUDA_Codec, CheckKeyFrame, testing::Combine(
863868
ALL_DEVICES,
864-
testing::Values(VIDEO_SRC_R)));
869+
testing::Values(VIDEO_SRC_KEY)));
865870

866871
INSTANTIATE_TEST_CASE_P(CUDA_Codec, CheckParams, ALL_DEVICES);
867872

0 commit comments

Comments
 (0)