Error: 'Your platform doesn't suppport hardware accelerated AV1 decoding.' when i use 'cv2.VideoCapture'

Version:
opencv-contrib-python 4.6.0.66
opencv-python 4.5.5.64
opencv_videoio_ffmpeg460_64.dll
Video:

Filename:
The Boys – Official Season 3 REDBAND Teaser Trailer - Prime Video.mkv
Code:
cv2.VideoCapture(path)
Error message:
[av1 @ 0000028a88053c40] Your platform doesn’t suppport hardware accelerated AV1 decoding.
[av1 @ 0000028a88053c40] Failed to get pixel format.
[av1 @ 0000028a88053c40] Missing Sequence Header.
[av1 @ 0000028a88053c40] video_get_buffer: image parameters invalid
[av1 @ 0000028a88053c40] get_buffer() failed
[av1 @ 0000028a88053c40] thread_get_buffer() failed
[av1 @ 0000028a88053c40] Failed to allocate space for current frame.
[av1 @ 0000028a88053c40] Get current frame error

the first one is just a warning. it’ll try software decoding.
the following lines seem to indicate that AV1 is still experimental, or the implementation that this version of ffmpeg uses is experimental.

get ffmpeg, try ffmpeg -i yourfile.mkv -f null - (which decodes and discards the result). if that also fails/complains, your file may be the issue.

also… you need to remove both python packages, and then install exactly one. both contain the base modules. if you have both/multiple installed, they WILL conflict.

This file works well in potplayer. I tried to input ffmpeg -i 55.mkv -f null - in cmd but display “ ‘ffmpeg’ is not an inner or outer command. ”

Can you open this file in VSCode with python? Just download and try. I think opencv module is uncapable to decode YT download video.

I said to

before you can use the ffmpeg command on the command line.

what is “potplayer”? does your file play with VLC?

This file can be opened with ffmpeg in cmd, the result returned as follow:

ffmpeg version 5.1-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
[libaom-av1 @ 000002434cc0f940] 3.4.0-176-g9473c4783
Input #0, matroska,webm, from '55.mkv':
  Metadata:
    COMPATIBLE_BRANDS: isomiso2avc1mp41
    MAJOR_BRAND     : isom
    MINOR_VERSION   : 512
    ENCODER         : IDMmkvlib0.1
    LANGUAGE        : und
    HANDLER_NAME    : AudioHandler
  Duration: 00:01:46.60, start: 0.000000, bitrate: 1222 kb/s
  Stream #0:0: Video: av1 (Main), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn (default)
  Stream #0:1: Audio: opus, 48000 Hz, stereo, fltp (default)
[libaom-av1 @ 000002434cc55680] 3.4.0-176-g9473c4783
Stream mapping:
  Stream #0:0 -> #0:0 (av1 (libaom-av1) -> wrapped_avframe (native))
  Stream #0:1 -> #0:1 (opus (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    COMPATIBLE_BRANDS: isomiso2avc1mp41
    MAJOR_BRAND     : isom
    MINOR_VERSION   : 512
    HANDLER_NAME    : AudioHandler
    LANGUAGE        : und
    encoder         : Lavf59.27.100
  Stream #0:0: Video: wrapped_avframe, yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn (default)
    Metadata:
      encoder         : Lavc59.37.100 wrapped_avframe
  Stream #0:1: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      encoder         : Lavc59.37.100 pcm_s16le
frame= 2555 fps=106 q=-0.0 Lsize=N/A time=00:01:46.58 bitrate=N/A speed=4.42x
video:1178kB audio:19983kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

But i still don’t know how to open it with opencv python, the warning is still exist.

Potplayer is a popular video player to play movie. I think it is just like VLC.

If you provide a link to the exact file I can take a look.

I can confirm that cv::VideoCapture can decode the av1 sample from here using opencv_videoio_ffmpeg460_64.dll.

I am appreciated for that, just check this out.

1 Like

interesting…

this might be worth a bug report.

standalone ffmpeg does not complain at all. how OpenCV uses ffmpeg is probably at fault.

I have a somewhat stale ffmpeg 4.4.1 here. I’ll try with 5.1… nope, also behaves well. must be OpenCV then.

Ignore my previous comment, I was testing on a build I made against FFmpeg 5.0. I can confirm that the previous test video I mentioned and the one you linked to don’t work with opencv_videoio_ffmpeg460_64.dll. The error comes from here
and seems to imply that AV1 cannot be decoded in software.

Anyway as @crackwitz says you could launch an issue with OpenCV to see if they can update opencv_videoio_ffmpegxxx_64.dll.

1 Like

OK, i did launch an issue in GitHub(btw, sorry for my lame English). Thank you for your suggestion. :slightly_smiling_face:

Yea I saw that, unfortunatley it looks like something they have been discussing for a while so its unlikely to get fixed any time soon.

Idk why they ignored this problem for a very long time. Even i digged it out again, they seem to be not willing to solve this bug.

They are not ignoring the problem this issue is still open. OpenCV is open source so nobody has submitted a PR yet to fix it.

Unfortunately this only effects windows users who use the pre-built ffmpeg dll. I will see if I can dig out the instrucitons for building directly against ffmpeg for you, then you should be able to use a build of ffmpeg which supports av1 decoding.

1 Like

To build against FFmpeg and get AV1 decoding you need to:

  1. Build or dowload and extract a build of FFMpeg to <FFMPEG_BUILD>. I would suggest simply downloading from here and depending on your license requirements you will want to download either
    ffmpeg-n5.0.1-7-g7389a49fd3-win64-gpl-shared-5.0.zip
    or
    ffmpeg-n5.0.1-7-g7389a49fd3-win64-lgpl-shared-5.0.zip
  2. Create a cmake directory <FFMPEG_BUILD>/cmake.
  3. Save the cmake script (ffmpeg-config.cmake) mentioned in the below post to that directory.
    Enabling system FFMPEG on windows · Issue #22273 · opencv/opencv · GitHub
  4. Set CMAKE_PREFIX_PATH or FFMPEG_DIR environmental variables to the directory containing the ffmpeg-config.cmake script.
  5. Include the flag OPENCV_FFMPEG_USE_FIND_PACKAGE=ON when calling cmake.

Then check your cmake output to confirm you have something similar to the below

– Found FFMPEG: D:/3rd_party/deps/ffmpeg-n5.0-latest-win64-gpl-shared-5.0/include (found version “5.0.1-5-g240d82f26e-20220611”) found components: avutil swresample swscale avcodec avformat avfilter avdevice

and not

– FFMPEG: Downloading opencv_videoio_ffmpeg.dll from https://raw.githubusercontent.com/opencv/opencv_3rdparty/65ec04d4573dcdfa4531f0b9e67f35d8ffff873e/ffmpeg/opencv_videoio_ffmpeg.dll
– FFMPEG: Downloading opencv_videoio_ffmpeg_64.dll from https://raw.githubusercontent.com/opencv/opencv_3rdparty/65ec04d4573dcdfa4531f0b9e67f35d8ffff873e/ffmpeg/opencv_videoio_ffmpeg_64.dll
– FFMPEG: Downloading ffmpeg_version.cmake from https://raw.githubusercontent.com/opencv/opencv_3rdparty/65ec04d4573dcdfa4531f0b9e67f35d8ffff873e/ffmpeg/ffmpeg_version.cmake

1 Like

WOW, that looks like too complicated for me. I never used cmake before. Maybe i will try it in the future. Anyway, your continuous help is much appreciated and I benefited a lot.

run cmake-gui. it’ll make all that less daunting.