-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
VideoCapture (CAP_FFMPEG) returns the incorrect fourcc codec due to codec_tag representing the underlying stream type #22876
Description
System Information
OpenCV version: 4.6.0
Operating System / Platform: Windows 11
Compiler & compiler version: Visual Studio 2022
Detailed description
VideoCapture with the FFmpeg back end returns the incorrect codec fourcc when the codec_tag represents the underlying stream type.
The existing logic is to return the codec_tag if it exists and igored the codec_id
opencv/modules/videoio/src/cap_ffmpeg_impl.hpp
Line 1725 in bc6544c
| if(codec_tag || codec_id == AV_CODEC_ID_NONE) |
This is fine if the codec_tag is valid but, if it is invalid and the codec_id is valid this logic fails.
For example this MPEG-TS video has a valid
codec_id== AV_CODEC_ID_HEVC (173)
and invalid
codec_tag ==36
the MPEG-TS stream type.
Additonaly because the codec_tag is
/**
* Additional information about the codec (corresponds to the AVI FOURCC).
*/
uint32_t codec_tag;
the fourcc returned for the three test video's below is mp4v
highgui/video/big_buck_bunny.mp4
highgui/video/sample_322x242_15frames.yuv420p.mpeg2video.mp4
highgui/video/sample_322x242_15frames.yuv420p.mjpeg.mp4
when they use MPEG-4, MPEG-2 and MJPG respectively.
I can think of easy fixes:
- Only use the
codec_tagif thecodec_idis unavaliable. This may pass all the test cases but break existing user code. - Add an additional property, i.e.
CAP_PROP_CODEC_ID_FOURCCor similar, which a user can fall back on if the fourcc returned fromCAP_PROP_FOURCCis garbage. This is clunky but it is guaranteed not to break any existing user code.
Steps to reproduce
Video from https://4kmedia.org/lg-new-york-hdr-uhd-4k-demo/
VideoCapture cap("LG New York HDR UHD 4K Demo.ts",CAP_FFMPEG);
const double fourcc = cap.get(CAP_PROP_FOURCC);
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)