From 871f931e95e3571c45d2f8ebad7c34e2ba390c46 Mon Sep 17 00:00:00 2001 From: cudawarped <12133430+cudawarped@users.noreply.github.com> Date: Tue, 25 Apr 2023 08:25:06 +0300 Subject: [PATCH] VideoCapture: apply bitstream filter to all h264/5 raw streams --- modules/videoio/src/cap_ffmpeg_impl.hpp | 12 +++++------- modules/videoio/test/test_ffmpeg.cpp | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index dfa272639d..f8a0c78bce 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -1327,6 +1327,10 @@ bool CvCapture_FFMPEG::setRaw() return true; } +static inline bool h26xContainer(const char* formatLongName) { + return !strcmp(formatLongName, "QuickTime / MOV") || !strcmp(formatLongName, "FLV (Flash Video)") || !strcmp(formatLongName, "Matroska / WebM"); +} + bool CvCapture_FFMPEG::processRawPacket() { if (packet.data == NULL) // EOF @@ -1350,14 +1354,8 @@ bool CvCapture_FFMPEG::processRawPacket() #endif ) { - // check start code prefixed mode (as defined in the Annex B H.264 / H.265 specification) - if (packet.size >= 5 - && !(packet.data[0] == 0 && packet.data[1] == 0 && packet.data[2] == 0 && packet.data[3] == 1) - && !(packet.data[0] == 0 && packet.data[1] == 0 && packet.data[2] == 1) - ) - { + if(h26xContainer(ic->iformat->long_name)) filterName = eVideoCodec == CV_CODEC(CODEC_ID_H264) ? "h264_mp4toannexb" : "hevc_mp4toannexb"; - } } if (filterName) { diff --git a/modules/videoio/test/test_ffmpeg.cpp b/modules/videoio/test/test_ffmpeg.cpp index 906b215ab4..d3f0d5b8fc 100644 --- a/modules/videoio/test/test_ffmpeg.cpp +++ b/modules/videoio/test/test_ffmpeg.cpp @@ -196,7 +196,7 @@ TEST_P(videoio_container, read) file.write(reinterpret_cast(raw_data.data), size); ASSERT_FALSE(file.fail()); } - ASSERT_GE(totalBytes, (size_t)65536) << "Encoded stream is too small"; + ASSERT_GE(totalBytes, (size_t)39775) << "Encoded stream is too small"; } std::cout << "Checking extracted video stream: " << fileNameOut << " (size: " << totalBytes << " bytes)" << std::endl; @@ -226,6 +226,7 @@ const videoio_container_params_t videoio_container_params[] = videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h264", "h264", "h264", "I420"), videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h265", "h265", "hevc", "I420"), videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "mjpg.avi", "mjpg", "MJPG", "I420"), + videoio_container_params_t(CAP_FFMPEG, "video/sample_322x242_15frames.yuv420p.libx264", "mp4", "h264", "avc1", "I420") //videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h264.mkv", "mkv.h264", "h264", "I420"), //videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h265.mkv", "mkv.h265", "hevc", "I420"), //videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h264.mp4", "mp4.avc1", "avc1", "I420"),