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
|
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_tag if the codec_id is unavaliable. This may pass all the test cases but break existing user code.
- Add an additional property, i.e.
CAP_PROP_CODEC_ID_FOURCC or similar, which a user can fall back on if the fourcc returned from CAP_PROP_FOURCC is 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
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_tagif it exists and igored thecodec_idopencv/modules/videoio/src/cap_ffmpeg_impl.hpp
Line 1725 in bc6544c
This is fine if the
codec_tagis valid but, if it is invalid and thecodec_idis valid this logic fails.For example this MPEG-TS video has a valid
codec_id== AV_CODEC_ID_HEVC (173)and invalid
codec_tag ==36the MPEG-TS stream type.
Additonaly because the
codec_tagisthe fourcc returned for the three test video's below is
mp4vwhen they use MPEG-4, MPEG-2 and MJPG respectively.
I can think of easy fixes:
codec_tagif thecodec_idis unavaliable. This may pass all the test cases but break existing user code.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/
Issue submission checklist