xuanruiqi / vdpau-va-driver-vp9

Experimental VP9 codec support for vdpau-va-driver (NVIDIA VDPAU-VAAPI wrapper) and chromium-vaapi
GNU General Public License v2.0
16 stars 3 forks source link

Fail to hardware decode YouTube vp9 videos #1

Closed fulalas closed 1 year ago

fulalas commented 2 years ago

I'm failing to hardware decode YouTube vp9 videos -- I'm using this for testing: https://www.youtube.com/watch?v=ojNFvNcMPsE

My system: Slackware x64 current Xorg 1.20.13 (12013000) Nvidia GTX 1650 Super proprietary driver 460.91.03

Using Chromium 88.0.4324.96

This command uses FfmpegVideodecoder (hwdec fails): # chromium --enable-features=VaapiVideoDecoder

vdpau_video: NVIDIA VDPAU Driver Shared Library  460.91.03  Fri Jul  2 05:42:23 UTC 2021
Failed to create dedicated X11 display!
libva error: /usr/lib64/dri/nvidia_drv_video.so init failed
[7184:7184:1208/042348.583348:ERROR:vaapi_wrapper.cc(1266)] Failed to create VaapiWrapper for va_profile: VAProfileH264Main

This command uses MojoVideoDecoder (hwdec works, but only for avc1) # chromium use-gl=desktop --enable-features=VaapiVideoDecoder

Failed to create dedicated X11 display!
vdpau_video: NVIDIA VDPAU Driver Shared Library  460.91.03  Fri Jul  2 05:42:23 UTC 2021
vdpau_video: vdpau_BeginPicture [ctx: 0x56025451c130, context: 33554432, render_target: 50331648]
vdpau_video: vdpau_RenderPicture [ctx: 0x56025451c130, context: 33554432, buffers: 0x7fc3a8006320, num_buffers: 4]
vdpau_video: ... buffers[0]->type: VAPictureParameterBufferType (0)
vdpau_video: ... buffers[1]->type: VAIQMatrixBufferType (1)
vdpau_video: ... buffers[2]->type: VASliceParameterBufferType (4)
vdpau_video: ... buffers[3]->type: VASliceDataBufferType (5)
[...]

Using Opera 82.0.4227.23 (Chrome/96.0.4664.45) using lib_extra/libffmpeg.so

This command uses VDAVideoDecoder (hwdec works, but only for avc1) # opera --use-gl=desktop --enable-features=VaapiVideoDecoder

[10889:11406:1208/044243.202775:ERROR:vaapi_utils.cc(49)] vaMapBuffer failed: invalid VABufferID
[10889:11406:1208/044243.202834:ERROR:vaapi_video_decode_accelerator.cc(532)] Error decoding stream
Failed to create dedicated X11 display!

This command uses VDAVideoDecoder (hwdec doesn't work) # opera --enable-features=VaapiVideoDecoder

vdpau_video: NVIDIA VDPAU Driver Shared Library  460.91.03  Fri Jul  2 05:42:23 UTC 2021
Failed to create dedicated X11 display!
vdpau_video: NVIDIA VDPAU Driver Shared Library  460.91.03  Fri Jul  2 05:42:23 UTC 2021
vdpau_video: vdpau_BeginPicture [ctx: 0x30ce05127600, context: 33554432, render_target: 50331648]
vdpau_video: vdpau_RenderPicture [ctx: 0x30ce05127600, context: 33554432, buffers: 0x30ce04f71740, num_buffers: 3]
vdpau_video: ... buffers[0]->type: VAPictureParameterBufferType (0)
vdpau_video: ... buffers[1]->type: VASliceParameterBufferType (4)
vdpau_video: ... buffers[2]->type: VASliceDataBufferType (5)
vdpau_video: translate_VAPictureParameterBufferVP9 [driver_data: 0x30ce054ad500, obj_context: 0x7fa963838af8, obj_buffer: 0x7fa963838af0]
vdpau_video: translate_VASliceParameterBufferVP9 [driver_data: 0x30ce054ad500, obj_context: 0x7fa963838ae8, obj_buffer: 0x7fa963838ae0, obj_buffer->num_elements: 1]
vdpau_video: vdpau_EndPicture [ctx: 0x30ce05127600, context: 33554432]
vdpau_video: rendering to surface 3000000
vdpau_video: vdp_status after ensure = 0
vdpau_video: vdp_status after render = 0
[13293:13683:1208/044731.015848:ERROR:vaapi_utils.cc(49)] vaMapBuffer failed: invalid VABufferID
[13293:13683:1208/044731.015925:ERROR:vaapi_video_decode_accelerator.cc(532)] Error decoding stream

Some tests result that may help investigating the issue

# vainfo

vainfo: VA-API version: 1.13 (libva 2.13.0)
vainfo: Driver version: Splitted-Desktop Systems VDPAU backend for VA-API - 0.7.4
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG4Simple            : VAEntrypointVLD
      VAProfileMPEG4AdvancedSimple    : VAEntrypointVLD
      <unknown profile>               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD

Weirdly, without your vp9 plugin I get this: # vainfo vaInitialize failed with error code -1 (unknown libva error),exit

When running a VP9 video on Mpv using hwdec=vaapi-copy:

[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[vaapi] Failed to initialize VAAPI: unknown libva error

When running a VP9 video on Mpv using hwdec=auto (hwdec works -- it selects nvdec-copy): no error/warning

When running a VP9 video on Mpv using hwdec=vdpau-copy (hwdec works): no error/warning


Questions:

  1. I first compiled the libvdpau you recommended (https://gitlab.freedesktop.org/vdpau/libvdpau.git), but it's not clear if I should use it for decoding, or if this is just for compiling your plugin. During the tests above I used it anyway -- it doesn't seem to change the results.
  2. Is this plugin supposed to provide vaapi hwdec for players (like Mpv) as well?

Thanks in advance!

marioroy commented 2 years ago

Though not apples to apples, I'm using Firefox on Clear Linux and vp9 decoding works great. In the ffmpeg-on-clear-linux repository exists scripts for building nv-codec-headers, libvdpau, and vdpau-va-driver-v9 to include scripts for building ffmpeg-cuda and dependencies.

I lack the time to try similarly for Chromium. Well, captured various output.

export LIBVA_DRIVERS_PATH=/usr/lib64/dri
export LIBVA_DRIVER_NAME=nvidia

ldd nvidia_drv_video.so

$ ldd /usr/lib64/dri/nvidia_drv_video.so 
    ...
    libvdpau.so.1 => /usr/local/lib/libvdpau.so.1 (0x00007fba230cc000)
    libGL.so.1 => /opt/nvidia/lib64/libGL.so.1 (0x00007fba23550000)
    libGLX.so.0 => /opt/nvidia/lib64/libGLX.so.0 (0x00007fba22ca2000)
    libGLdispatch.so.0 => /opt/nvidia/lib64/libGLdispatch.so.0 (0x00007fba229b1000)
    ...

vainfo

$ vainfo
libva info: VA-API version 1.11.0
libva info: Trying to open /usr/lib64/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_11
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.11 (libva 2.11.0)
vainfo: Driver version: Splitted-Desktop Systems VDPAU backend for VA-API - 0.7.4
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG4Simple            : VAEntrypointVLD
      VAProfileMPEG4AdvancedSimple    : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD

vdpauinfo

$ vdpauinfo
display: :0   screen: 0
API version: 1
Information string: NVIDIA VDPAU Driver Shared Library  495.29.05  Thu Sep 30 15:49:18 UTC 2021

Video surface:

name   width height types
-------------------------------------------
420     8192  8192  NV12 YV12 
422     8192  8192  UYVY YUYV 
444     8192  8192  

Decoder capabilities:

name                        level macbs width height
----------------------------------------------------
MPEG1                           0 65536  4096  4096
MPEG2_SIMPLE                    3 65536  4096  4096
MPEG2_MAIN                      3 65536  4096  4096
H264_BASELINE                  51 65536  4096  4096
H264_MAIN                      51 65536  4096  4096
H264_HIGH                      51 65536  4096  4096
VC1_SIMPLE                      1  8190  2048  2048
VC1_MAIN                        2  8190  2048  2048
VC1_ADVANCED                    4  8190  2048  2048
MPEG4_PART2_SP                  3  8192  2048  2048
MPEG4_PART2_ASP                 5  8192  2048  2048
DIVX4_QMOBILE                   0  8192  2048  2048
DIVX4_MOBILE                    0  8192  2048  2048
DIVX4_HOME_THEATER              0  8192  2048  2048
DIVX4_HD_1080P                  0  8192  2048  2048
DIVX5_QMOBILE                   0  8192  2048  2048
DIVX5_MOBILE                    0  8192  2048  2048
DIVX5_HOME_THEATER              0  8192  2048  2048
DIVX5_HD_1080P                  0  8192  2048  2048
H264_CONSTRAINED_BASELINE      51 65536  4096  4096
H264_EXTENDED                  51 65536  4096  4096
H264_PROGRESSIVE_HIGH          51 65536  4096  4096
H264_CONSTRAINED_HIGH          51 65536  4096  4096
H264_HIGH_444_PREDICTIVE       51 65536  4096  4096
HEVC_MAIN                      153 262144  8192  8192
HEVC_MAIN_10                   153 262144  8192  8192
HEVC_MAIN_STILL                --- not supported ---
HEVC_MAIN_12                   153 262144  8192  8192
HEVC_MAIN_444                  153 262144  8192  8192

...
marioroy commented 2 years ago

I am delighted to report that vp9 decoding is working in Chromium. The chromium-latest-linux repository works great on Clear Linux. I modified the run.sh script as such.

#! /bin/bash

export LIBVA_DRIVERS_PATH=/usr/lib64/dri
export LIBVA_DRIVER_NAME=nvidia
export LD_LIBRARY_PATH=/opt/nvidia/lib64:/usr/local/lib
export FONTCONFIG_PATH=/usr/share/defaults/fonts

# To rid of the Google API keys are missing notification.
export GOOGLE_API_KEY=no
export GOOGLE_DEFAULT_CLIENT_ID=no
export GOOGLE_DEFAULT_CLIENT_SECRET=no

BASEDIR=$(dirname $0)

if [ $XDG_SESSION_TYPE == wayland ]
then
    $BASEDIR/latest/chrome --window-size=1100,900 \
        --use-gl=egl --enable-features=VaapiVideoDecoder \
        --user-data-dir="$DATADIR" $* &> /dev/null &
elif [ $XDG_SESSION_TYPE == x11 ]
then
    $BASEDIR/latest/chrome --window-size=1100,900 \
        --use-gl=desktop --enable-features=VaapiVideoDecoder \
        --user-data-dir="$DATADIR" $* &> /dev/null &
fi

First time

$ ./update-and-run.sh

Subsequently

$ ./run.sh
ghost commented 2 years ago

--disable-features=UseChromeOSDirectVideoDecoder