Can't create encoder with PyNvVideoCodec 2.0.0

Hello!

PyNvVideoCodec 1.0.2 works fine on my system.

I wanted to upgrade the dependency for my project to 2.0.0, as it was just released, yet this simple code:

import PyNvVideoCodec as nvc
encoder = nvc.CreateEncoder(1920, 1080, "NV12", False)

produces the following error:

_PyNvVideoCodec.PyNvVCException: PyNvEncoderCaps :
Error code : 8
Error Type : m_nvenc.nvEncGetEncodeCaps(hEncoder, encodeGUID, &capsParam, &v) returned error 8
at /project/src/PyNvVideoCodec/src/PyNvEncoder.cpp:1022

I’d also like to mention that when I ran poetry add pynvvideocodec@2.0.0 I got the following warning:

Validation of the RECORD file of PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl failed. Please report to the maintainers of that package so they can fix their build process. Details:
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, pynvvideocodec./libxcb-xfixes-6de855b8.so.0.0.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, pynvvideocodec./libcuda-40d19bb1.so is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, pynvvideocodec./libcudart-c64a25f3.so.12.3.101 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, pynvvideocodec./libxcb-shm-0be6dfbf.so.0.0.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, pynvvideocodec./libdrm-b0291a67.so.2.4.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, pynvvideocodec./libxcb-shape-7716c890.so.0.0.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, pynvvideocodec./libxcb-5ddf6756.so.1.1.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, pynvvideocodec./libXau-154567c4.so.6.0.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, PyNvVideoCodec/libxcb-xfixes-6de855b8.so.0.0.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, PyNvVideoCodec/libcuda-40d19bb1.so is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, PyNvVideoCodec/libcudart-c64a25f3.so.12.3.101 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, PyNvVideoCodec/libxcb-shm-0be6dfbf.so.0.0.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, PyNvVideoCodec/libdrm-b0291a67.so.2.4.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, PyNvVideoCodec/libxcb-shape-7716c890.so.0.0.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, PyNvVideoCodec/libxcb-5ddf6756.so.1.1.0 is not mentioned in RECORD
In /home/orlandobutnaru/.cache/pypoetry/artifacts/37/ff/ab/bb902959863a94611b9195ec6ea700b78c8e0fd8d51102b4477aa4e6cc/PyNvVideoCodec-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl, PyNvVideoCodec/libXau-154567c4.so.6.0.0 is not mentioned in RECORD

Also, the linked documentation PyNvVideoCodec 1.0 - NVIDIA Docs is not up to date yet.

System information

  • NVIDIA GeForce RTX 3060 Laptop GPU
  • Driver Version: 535.183.01
  • CUDA Version: 12.2
  • OS: Ubuntu 20.04.6 LTS
  • Python 3.11.12

I’ve come up with a fix. It seems like the error is the fact that NV_ENC_CAPS_EXPOSED_COUNT is tried to be queried.

The fix is to simply change the <= in this line:

for (int i = static_cast<int>(NV_ENC_CAPS_NUM_MAX_BFRAMES); i <= static_cast<int>(NV_ENC_CAPS_EXPOSED_COUNT); ++i)

to a <.

I didn’t get to test all my code with 2.0.0 yet but I’ll get back if anything else pops up.

I’ve found another bug:

std::vector<std::tuple<CUdeviceptr, int64_t, SEI_MESSAGE, CUevent>> PyDecode(uint8_t*, uint64_t, int32_t pts, int32_t decode_flag);

pts is int32_t here, yet PyDecode is only called here:

std::vector<DecodedFrame> PyNvDecoder::Decode(const PacketData packetData)
{
    NVTX_SCOPED_RANGE("py::decode")
    std::vector<DecodedFrame> frames;
    py::gil_scoped_release release;
    auto vecTupFrame = decoder->PyDecode((uint8_t*)packetData.bsl_data, packetData.bsl,

    packetData.pts, // this is int64_t

    packetData.decode_flag);
    auto funcCAIDLPack = std::bind(GetCAIMemoryViewAndDLPack, decoder.get(), std::placeholders::_1);
    std::transform(vecTupFrame.begin(), vecTupFrame.end(), std::back_inserter(frames), funcCAIDLPack);
    py::gil_scoped_acquire acquire;
    return frames;
}

with pts = packetData.pts which is int64_t.

NvDecoder::PyDecode ends up calling NvDecoder::Decode which, again, takes in an int64_t.

In the end, this causes issues when using large numbers in Python as the PTS for the packets. They won’t come back attached to the decoded frames as the same value.

Where can I create merge/pull requests for this project? Or get faster feedback?