Skip to content

Conversation

asmorkalov
Copy link
Contributor

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
Copy link
Contributor Author

cc @cudawarped

@cudawarped
Copy link
Contributor

@asmorkalov I don't have a card (>= NVENC 8th Gen) to test this on so all I can confirm is that it builds on Windows and throws an exception when I try to write an AV1 file on hardware (NVENC 7th Gen) which doesn't support it.

Looking at the diff (NVEncoder.cpp, 11.1.5->12.0.16) from the you may need to add additional changes. i.e.

else if (pIntializeParams->encodeGUID == NV_ENC_CODEC_AV1_GUID)
{
    pIntializeParams->encodeConfig->encodeCodecConfig.av1Config.pixelBitDepthMinus8 = (m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV420_10BIT) ? 2 : 0;
    pIntializeParams->encodeConfig->encodeCodecConfig.av1Config.inputPixelBitDepthMinus8 = (m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV420_10BIT) ? 2 : 0;
    pIntializeParams->encodeConfig->encodeCodecConfig.av1Config.chromaFormatIDC = 1;
    pIntializeParams->encodeConfig->encodeCodecConfig.av1Config.idrPeriod = pIntializeParams->encodeConfig->gopLength;
    if (m_bOutputInVideoMemory)
    {
        pIntializeParams->encodeConfig->frameIntervalP = 1;
    }
}
if (pEncoderParams->encodeGUID == NV_ENC_CODEC_AV1_GUID)
{
    if (m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444 || m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444_10BIT)
    {
        NVENC_THROW_ERROR("YUV444 format isn't supported by AV1 encoder", NV_ENC_ERR_INVALID_PARAM);
    }
}
if (pEncoderParams->encodeGUID == NV_ENC_CODEC_AV1_GUID)
{
    bool yuv10BitFormat = (m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV420_10BIT) ? true : false;
    if (yuv10BitFormat && pEncoderParams->encodeConfig->encodeCodecConfig.av1Config.pixelBitDepthMinus8 != 2)
    {
        NVENC_THROW_ERROR("Invalid PixelBitdepth", NV_ENC_ERR_INVALID_PARAM);
    }

    if (pEncoderParams->encodeConfig->encodeCodecConfig.av1Config.chromaFormatIDC != 1)
    {
        NVENC_THROW_ERROR("Invalid ChromaFormatIDC", NV_ENC_ERR_INVALID_PARAM);
    }

    if (m_bOutputInVideoMemory && pEncoderParams->encodeConfig->frameIntervalP > 1)
    {
        NVENC_THROW_ERROR("Alt Ref frames not supported for AV1 in case of OutputInVideoMemory", NV_ENC_ERR_INVALID_PARAM);
    }
}

I'm also not that familiar with AV1 so not sure if you need to write an IVF header for raw AV1 files to make them playable. If so you may need to disable raw output for this codec or introduce the IVFUtils class from CODEC_SDK/Sampls/Utils/NvCodecUtils.h.

Are you going to include any tests, have you tested both raw and containerized output?

@asmorkalov
Copy link
Contributor Author

Not sure, actually. My goal is enable builds and test test with older SDK, e.g. in CI: opencv/ci-gha-workflow#259.

@asmorkalov
Copy link
Contributor Author

It means that the first change is redundant.

@asmorkalov
Copy link
Contributor Author

@cudawarped I reduced the patch size for now and will try to find some 4x or 5x card for experiments with av1 encoder.

@cudawarped
Copy link
Contributor

Not sure, actually. My goal is enable builds and test test with older SDK, e.g. in CI: opencv/ci-gha-workflow#259.

Sorry I completly missed that GetVideoCodecString already returns AV1, everything makes sense now.

@cudawarped
Copy link
Contributor

LGTM! Fixes

video_writer.cpp(321): error C2065: 'NV_ENC_CODEC_AV1_GUID': undeclared identifier

present when using Nvidia Video Codec SDK 11.x

@asmorkalov asmorkalov self-assigned this Sep 29, 2025
@asmorkalov
Copy link
Contributor Author

@cudawarped Thanks a lot!

@asmorkalov asmorkalov merged commit 1231b20 into opencv:4.x Sep 29, 2025
13 checks passed
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