Skip to content

Fix video codec fourcc #21101#22333

Merged
asmorkalov merged 2 commits intoopencv:4.xfrom
cudawarped:fix_for_21101
Aug 26, 2022
Merged

Fix video codec fourcc #21101#22333
asmorkalov merged 2 commits intoopencv:4.xfrom
cudawarped:fix_for_21101

Conversation

@cudawarped
Copy link
Copy Markdown
Contributor

@cudawarped cudawarped commented Aug 2, 2022

This PR should fix #21101 in most cases by returning a valid fourcc from CvCapture_FFMPEG::getProperty(CAP_PROP_FOURCC) when codec_tag==0 and _opencv_avcodec_get_name(codec_id) is invalid. Previously as noted in the issue getProperty would have returned 0.

In addition to the description in #21101, it appears that the value of video_st->CV_FFMPEG_CODEC_FIELD->codec_tag depends on the video file itself and not just the codec used. That is some vp9 video's will have a valid codec_tag and some will have zero. As a result all of the test cases apart from "../cv/tracking/faceocc2/data/faceocc2.webm" would have worked before this change and are included to verify that the previous functionality still works.

Futhermore with reference to the question of which fourcc to return for vp8[9] and av1. Unfortunately because codec_tag could be valid we have no control over the return value from getProperty without breaking the fourcc's which are already returned. E.g. the value of video_st->CV_FFMPEG_CODEC_FIELD->codec_tag for a vp9 file could be vp09, vp90, VP09, VP90 or zero, and in the first four cases forcing a return value of VP90 would break existing code relying on the return value from getProperty.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@asmorkalov asmorkalov requested a review from alalek August 2, 2022 16:13
@asmorkalov asmorkalov changed the title Fix for 21101 Fix video codec fourcc #21101 Aug 2, 2022
@asmorkalov asmorkalov requested review from asmorkalov and removed request for asmorkalov August 19, 2022 13:48
@asmorkalov asmorkalov merged commit 42561e1 into opencv:4.x Aug 26, 2022
@asmorkalov
Copy link
Copy Markdown
Contributor

Related changes for cudacodec: opencv/opencv_contrib#3340

@alalek alalek mentioned this pull request Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants