Skip to content

VideoCapture: fix opencv/contrib/#3474#23541

Merged
opencv-pushbot merged 1 commit intoopencv:4.xfrom
cudawarped:fix_3474
Apr 25, 2023
Merged

VideoCapture: fix opencv/contrib/#3474#23541
opencv-pushbot merged 1 commit intoopencv:4.xfrom
cudawarped:fix_3474

Conversation

@cudawarped
Copy link
Copy Markdown
Contributor

@cudawarped cudawarped commented Apr 25, 2023

Fix opencv/contrib/#3474 by allowing the bitstream filter to be applied to all h264/5 raw streams.

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

{
filterName = eVideoCodec == CV_CODEC(CODEC_ID_H264) ? "h264_mp4toannexb" : "hevc_mp4toannexb";
}
filterName = eVideoCodec == CV_CODEC(CODEC_ID_H264) ? "h264_mp4toannexb" : "hevc_mp4toannexb";
Copy link
Copy Markdown
Contributor

@opencv-alalek opencv-alalek Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, there are some H264/H265 streams which are already "filtered" (applying again filtering looks strange).

Details: #15290 (comment)

Perhaps we need to recheck "raw" .h264 files that they are not broken.
(tests are failed on CI)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(tests are failed on CI)

I suspect this may a threading issue related to setting up the bitstream filter for more files when using the version of FFmpeg on the old build bot (56.60.100) because it is less than < 58.9.100 where threading support was enabled by default.

2017-12-26 - a04c2c707d - lavc 58.9.100 - avcodec.h
Deprecate av_lockmgr_register(). You need to build FFmpeg with threading
support enabled to get basic thread-safety (which is the default build
configuration).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, there are some H264/H265 streams which are already "filtered" (applying again filtering looks strange).

We could use the approach adopted in the Nvidia Video Codec SDK samples,

bMp4H264 = eVideoCodec == AV_CODEC_ID_H264 && (
        !strcmp(fmtc->iformat->long_name, "QuickTime / MOV") 
        || !strcmp(fmtc->iformat->long_name, "FLV (Flash Video)") 
        || !strcmp(fmtc->iformat->long_name, "Matroska / WebM")
    );
bMp4HEVC = eVideoCodec == AV_CODEC_ID_HEVC && (
        !strcmp(fmtc->iformat->long_name, "QuickTime / MOV")
        || !strcmp(fmtc->iformat->long_name, "FLV (Flash Video)")
        || !strcmp(fmtc->iformat->long_name, "Matroska / WebM")
    );

which uses the long_name to determine whether we are dealing with a container format or not. The assumption being that container formats are length prefixed and raw files/streams are code prefixed.

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@opencv-alalek updated to use the approach found in the Nvidia Video Codec SDK samples.

@opencv-alalek opencv-alalek added this to the 4.8.0 milestone Apr 25, 2023
Copy link
Copy Markdown
Contributor

@opencv-alalek opencv-alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thank you!

@opencv-alalek opencv-alalek self-assigned this Apr 25, 2023
@opencv-pushbot opencv-pushbot merged commit d4f29a6 into opencv:4.x Apr 25, 2023
@asmorkalov asmorkalov mentioned this pull request May 31, 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.

Problem with using cv2.cudacodec.createVideoReader

3 participants