Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cudacodec::VideoWriter: Add 10 bit YUV420 and YUV444 encoding #3860

Merged

Conversation

cudawarped
Copy link
Contributor

@cudawarped cudawarped commented Dec 30, 2024

Currently cudacodec::VideoWriter only encodes 8 bit YUV input. This PR adds the capacity to encode 10 bit YUV input as well.

Discussed in this forum post.

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

@cudawarped cudawarped changed the title `cudacodec::VideoWriter: Add 10 bit YUV420 and YUV444 encoding cudacodec::VideoWriter: Add 10 bit YUV420 and YUV444 encoding Dec 30, 2024
@asmorkalov asmorkalov self-requested a review January 6, 2025 11:35
@asmorkalov asmorkalov self-assigned this Jan 6, 2025
@asmorkalov
Copy link
Contributor

Test result for my 1080:

[==========] Running 3 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 3 tests from CUDA_Codec/YUVFormats
[ RUN      ] CUDA_Codec/YUVFormats.Transcode/0, where GetParam() = (NVIDIA GeForce GTX 1080, cudacodec::ColorFormat::NV_YUV444)
[ WARN:[email protected]] global ffmpeg_video_source.cpp:102 FourccToChromaFormat ChromaFormat not recognized: 0x50343434 (444P). Assuming I420
[ERROR:[email protected]] global video_parser.cpp:86 parseVideoData OpenCV(4.11.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudacodec/src/video_decoder.cpp:144: error: (-210:Unsupported format or combination of formats) Video codec is not supported by this GPU hardware video decoder refer to Nvidia's GPU Support Matrix to confirm your GPU supports hardware decoding of the video source's codec. in function 'create'

unknown file: Failure
C++ exception with description "OpenCV(4.11.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudacodec/src/video_reader.cpp:130: error: (-2:Unspecified error) Parsing/Decoding video source failed, check GPU memory is available and GPU supports requested functionality. in function 'waitForDecoderInit'
" thrown in the test body.
[  FAILED  ] CUDA_Codec/YUVFormats.Transcode/0, where GetParam() = (NVIDIA GeForce GTX 1080, cudacodec::ColorFormat::NV_YUV444) (416 ms)
[ RUN      ] CUDA_Codec/YUVFormats.Transcode/1, where GetParam() = (NVIDIA GeForce GTX 1080, cudacodec::ColorFormat::NV_YUV420_10BIT)
[ WARN:[email protected]] global ffmpeg_video_source.cpp:102 FourccToChromaFormat ChromaFormat not recognized: 0x0A0B3359 (Y3??). Assuming I420
[       OK ] CUDA_Codec/YUVFormats.Transcode/1 (587 ms)
[ RUN      ] CUDA_Codec/YUVFormats.Transcode/2, where GetParam() = (NVIDIA GeForce GTX 1080, cudacodec::ColorFormat::NV_YUV444_10BIT)
[ WARN:[email protected]] global ffmpeg_video_source.cpp:102 FourccToChromaFormat ChromaFormat not recognized: 0x0A003359 (Y3??). Assuming I420
[ERROR:[email protected]] global video_parser.cpp:86 parseVideoData OpenCV(4.11.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudacodec/src/video_decoder.cpp:144: error: (-210:Unsupported format or combination of formats) Video codec is not supported by this GPU hardware video decoder refer to Nvidia's GPU Support Matrix to confirm your GPU supports hardware decoding of the video source's codec. in function 'create'

unknown file: Failure
C++ exception with description "OpenCV(4.11.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudacodec/src/video_reader.cpp:130: error: (-2:Unspecified error) Parsing/Decoding video source failed, check GPU memory is available and GPU supports requested functionality. in function 'waitForDecoderInit'
" thrown in the test body.
[  FAILED  ] CUDA_Codec/YUVFormats.Transcode/2, where GetParam() = (NVIDIA GeForce GTX 1080, cudacodec::ColorFormat::NV_YUV444_10BIT) (314 ms)
[----------] 3 tests from CUDA_Codec/YUVFormats (1317 ms total)

[----------] Global test environment tear-down
[==========] 3 tests from 1 test case ran. (1317 ms total)
[  PASSED  ] 1 test.
[  FAILED  ] 2 tests, listed below:
[  FAILED  ] CUDA_Codec/YUVFormats.Transcode/0, where GetParam() = (NVIDIA GeForce GTX 1080, cudacodec::ColorFormat::NV_YUV444)
[  FAILED  ] CUDA_Codec/YUVFormats.Transcode/2, where GetParam() = (NVIDIA GeForce GTX 1080, cudacodec::ColorFormat::NV_YUV444_10BIT)

@cudawarped
Copy link
Contributor Author

[ FAILED ] 2 tests, listed below:
[ FAILED ] CUDA_Codec/YUVFormats.Transcode/0, where GetParam() = (NVIDIA GeForce GTX 1080, cudacodec::ColorFormat::NV_YUV444)
[ FAILED ] CUDA_Codec/YUVFormats.Transcode/2, where GetParam() = (NVIDIA GeForce GTX 1080, cudacodec::ColorFormat::NV_YUV444_10BIT)

Thank you again for taking the time to test this on your local machine, I know CUDA is a pain.

Regarding the error the 1080 doesn't support decoding of YUV444, see the Video Support Matrix.

The error message

Video codec is not supported by this GPU hardware video decoder refer to Nvidia's GPU Support Matrix to confirm your GPU supports hardware decoding of the video source's codec

isn't more specific because there are numerous reasons a video source isn't supported and the actual reason is not returned by the Video Codec API.

Support is checked by filling out the format information, calling cuvidGetDecoderCaps() checking the value of CUVIDDECODECAPS::bIsSupported. See cudacodec::video_decoder.cpp` and Querying decode capabilities for more info.

@cudawarped
Copy link
Contributor Author

[ WARN:[email protected]] global ffmpeg_video_source.cpp:102 FourccToChromaFormat ChromaFormat not recognized: 0x50343434 (444P). Assuming I420

Looking at the console output, the above is confusing. Establishing the chroma format in the demuxer is redundant as this is overwritten when the video is parsed. I suggest to remove this from

FourccToChromaFormat(pixelFormat, format_.chromaFormat, format_.nBitDepthMinus8);

In addition to my previous comment I will update the error message to include the codec and chroma format. That is the new message for CUDA_Codec/YUVFormats.Transcode/2 will be

10 bit H.265/HEVC with YUV 444 chroma format is not supported by this GPU hardware video decoder. Please refer to Nvidia's GPU Support Matrix to confirm your GPU supports hardware decoding of this video source.

@cudawarped cudawarped force-pushed the cudacodec_videowriter_add_ten_bit_encoding branch from bfea856 to b1838d4 Compare January 6, 2025 15:10
@cudawarped cudawarped force-pushed the cudacodec_videowriter_add_ten_bit_encoding branch from b1838d4 to 6131706 Compare January 7, 2025 06:27
@asmorkalov asmorkalov merged commit 75f5bd2 into opencv:4.x Jan 8, 2025
11 checks passed
@asmorkalov asmorkalov mentioned this pull request Jan 15, 2025
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.

2 participants