Skip to content

VideoCapture::get(CAP_PROP_FOURCC) with FFMPEG backend returns zero for certain codecs #21101

@cudawarped

Description

@cudawarped
System information (version)
  • OpenCV => 4.5.4
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2019
Detailed description

If a codec has a three letter code returned by avcodec_get_name() and no codec tag, such as VP8 (AV_CODEC_ID_VP8), VP9 (AV_CODEC_ID_VP8) and AV1 (AV_CODEC_ID_AV1) then VideoCapture::get(CAP_PROP_FOURCC) returns codec_tag which for these three codecs results in a zero fourcc code.
Alternatively if avcodec_get_name() returns a 5 letter code such as MPEG4 (AV_CODEC_ID_MPEG4) then it gets truncated. For example if avcodec_get_name() returns MPEG4 (AV_CODEC_ID_MPEG4) the returned fourcc is truncated to the MPEG (MPEG-1).
I am not sure but I assume that these cases may generalize to all <4 and >4 letter codes.

I could see an easy way to fix this for <4 with zero padding although 0VP9 is not the same as VP09 but I am not sure what should be done for >4 letter codecs without a conversion table, mpeg4 should probably be mp4v?

This is confusing for example if a video file is written in windows by VideoWriter() using the fourcc VideoWriter::fourcc('m', 'p', '4', 'v') (MPEG-4), because openeing that file with VideoCapture() and then calling VideoCapture::get(CAP_PROP_FOURCC) returns MPEG wrongly indicating the file is MPEG-1.

Steps to reproduce

Open a vp8/vp9/av1 file or one written by VideoWriter() on windows with fourcc 'mp4v' and call VideoCapture::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 solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions