Skip to content

QSV HWAccel throwing Function not implemented #2132

@ladaapp

Description

@ladaapp

Using recent builds of v16.1.0 QSV encoder like h264_qsv work as expected.

I am using this code to check if Nvidia cuda hardware is available in my app to filter available encoders which works as expected (does raise an exception if no Nvidia hardware is available or driver issue and doesn't raise otherwise)

av.codec.hwaccel.HWAccel('cuda', allow_software_fallback=False).create(av.codec.Codec('h264_nvenc', 'w'))
def is_cuda_encoding_available():
    try:
        av.codec.hwaccel.HWAccel('cuda', allow_software_fallback=False).create(av.codec.Codec('h264_nvenc', 'w'))
        return True
    except Exception:
        return False

Doing the same for QSV though does not work. It will raise an Function not implemented exception even if QSV is available (encoding via h264_qsv works).

av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))

Interestingly it works if i'm building PyAv using source distribution against packages ffmpeg libs on ArchLinux so this might be a packaging issue in pyav-ffmpeg?

There is also no problem when using the binary wheels for Windows of v16.1.0. I don't have a Windows machine with QSV-capable hardware myself but i've received reports from two Windows user that this HWAccel code does not throw an Function not implemented exception.

Here is my test log:

Arch Linux with QSV hardware, self-built PyAV against Arch Linux-packaged FFmpeg libraries, works ✔️

uv pip uninstall av
uv pip install --no-cache av --no-binary av

# install QSV runtime
sudo pacman -S vpl-gpu-rt

>>> import av
>>> av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
<av.codec.hwaccel.HWAccel object at 0x7fad2de9f9a0>

# uninstall QSV runtime
sudo pacman -Rs vpl-gpu-rt

python
>>> import av
>>> av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "av/codec/hwaccel.pyx", line 154, in av.codec.hwaccel.HWAccel.create
    ret._initialize_hw_context(codec)
    ^^^
  File "av/codec/hwaccel.pyx", line 137, in av.codec.hwaccel.HWAccel._initialize_hw_context
    err_check(
    ^^^
  File "av/error.pyx", line 424, in av.error.err_check
    raise cls(code, message, filename, log)
    ^^^
av.error.UnknownError: [Errno 1313558101] Unknown error occurred

Arch Linux with QSV hardware, using official PyAv binary wheel, doesn't work ❌

uv pip uninstall av
uv pip install av==16.1.0

sudo pacman -S vpl-gpu-rt

python
>>> import av
>>> av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "av/codec/hwaccel.pyx", line 154, in av.codec.hwaccel.HWAccel.create
  File "av/codec/hwaccel.pyx", line 137, in av.codec.hwaccel.HWAccel._initialize_hw_context
  File "av/error.pyx", line 424, in av.error.err_check
av.error.NotImplementedError: [Errno 38] Function not implemented

sudo pacman -Rs vpl-gpu-rt


python
>>> import av
>>> av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "av/codec/hwaccel.pyx", line 154, in av.codec.hwaccel.HWAccel.create
  File "av/codec/hwaccel.pyx", line 137, in av.codec.hwaccel.HWAccel._initialize_hw_context
  File "av/error.pyx", line 424, in av.error.err_check
av.error.NotImplementedError: [Errno 38] Function not implemented

https://gitlab.archlinux.org/archlinux/packaging/packages/ffmpeg/-/blob/main/PKGBUILD?ref_type=heads
https://gitlab.archlinux.org/archlinux/packaging/packages/libvpl/-/blob/main/PKGBUILD?ref_type=heads

Ubuntu with no QSV hardware, using official PyAv binary wheel, doesn't work ❌

uv pip uninstall av
uv pip install av==16.1.0
>>> import av
>>> av.codec.hwaccel.HWAccel('cuda', allow_software_fallback=False).create(av.codec.Codec('h264_nvenc', 'w'))
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    av.codec.hwaccel.HWAccel('cuda', allow_software_fallback=False).create(av.codec.Codec('h264_nvenc', 'w'))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "av/codec/hwaccel.pyx", line 154, in av.codec.hwaccel.HWAccel.create
  File "av/codec/hwaccel.pyx", line 137, in av.codec.hwaccel.HWAccel._initialize_hw_context
  File "av/error.pyx", line 424, in av.error.err_check
av.error.PermissionError: [Errno 1] Operation not permitted
>>> av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "av/codec/hwaccel.pyx", line 154, in av.codec.hwaccel.HWAccel.create
  File "av/codec/hwaccel.pyx", line 137, in av.codec.hwaccel.HWAccel._initialize_hw_context
  File "av/error.pyx", line 424, in av.error.err_check
av.error.NotImplementedError: [Errno 38] Function not implemented

Windows with no QSV hardware, using official PyAv binary wheel, works ✔️

uv pip uninstall av
uv pip install av==16.1.0
>>> import av
>>> av.codec.hwaccel.HWAccel('cuda', allow_software_fallback=False).create(av.codec.Codec('h264_nvenc', 'w'))
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    av.codec.hwaccel.HWAccel('cuda', allow_software_fallback=False).create(av.codec.Codec('h264_nvenc', 'w'))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "av/codec/hwaccel.pyx", line 154, in av.codec.hwaccel.HWAccel.create
  File "av/codec/hwaccel.pyx", line 137, in av.codec.hwaccel.HWAccel._initialize_hw_context
  File "av/error.pyx", line 424, in av.error.err_check
av.error.PermissionError: [Errno 1] Operation not permitted
>>> av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    av.codec.hwaccel.HWAccel('qsv', allow_software_fallback=False).create(av.codec.Codec('h264_qsv', 'w'))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "av/codec/hwaccel.pyx", line 154, in av.codec.hwaccel.HWAccel.create
  File "av/codec/hwaccel.pyx", line 137, in av.codec.hwaccel.HWAccel._initialize_hw_context
  File "av/error.pyx", line 424, in av.error.err_check
av.error.UnknownError: [Errno 1313558101] Unknown error occurred

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions