opencv icon indicating copy to clipboard operation
opencv copied to clipboard

Fix video codec fourcc #21101

Open cudawarped opened this issue 3 years ago • 0 comments

This PR should fix https://github.com/opencv/opencv/issues/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 https://github.com/opencv/opencv/issues/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

  • [x] 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
  • [x] The PR is proposed to the proper branch
  • [x] There is a reference to the original bug report and related work
  • [x] 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

cudawarped avatar Aug 02 '22 14:08 cudawarped

Related changes for cudacodec: https://github.com/opencv/opencv_contrib/pull/3340

asmorkalov avatar Aug 29 '22 07:08 asmorkalov