mpv and hardware acceleration

hit

i use kde under wayland on a lenovo t450

when i watch a video with mpv, cpu come to 300%

vainfo command return


libva info: VA-API version 1.4.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib64/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_4
failed to open /usr/lib64/dri/hybrid_drv_video.so
Not using hybrid_drv_video.so
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.4 (libva 2.3.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Broadwell - 2.3.0
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileH264MultiviewHigh      : VAEntrypointVLD
      VAProfileH264MultiviewHigh      : VAEntrypointEncSlice
      VAProfileH264StereoHigh         : VAEntrypointVLD
      VAProfileH264StereoHigh         : VAEntrypointEncSlice
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileVP8Version0_3          : VAEntrypointVLD

tried

mpv --hwdec vaapi --opengl-backend=wayland myvideo.mp4

get same result

thanks

when load previous command

(+) Video --vid=1 (*) (h264 1920x1080 29.970fps)
 (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
[vaapi] libva: va_getDriverName() failed with unknown libva error,driver_name=(null)
[ffmpeg] AVHWDeviceContext: Cannot load libcuda.so.1                                                                                                                                                                     
[ffmpeg] AVHWDeviceContext: Could not dynamically load CUDA                                                                                                                                                              
libva info: VA-API version 1.4.0
libva info: va_getDriverName() returns -1
libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
failed to open /usr/lib64/dri/hybrid_drv_video.so
Not using hybrid_drv_video.so
[ffmpeg/video] h264: Failed setup for format vaapi_vld: hwaccel initialisation returned error.
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 1920x1080 yuv420p
AV: 00:00:13 / 00:09:44 (2%) A-V:  0.092 Dropped: 16

like loading driver issue?

collinm@linux-77w7:~/bin> sha1sum /usr/lib64/dri/*

1473bd6c1c4a96193ea170b4e912fd02dd26bc89  /usr/lib64/dri/i915_dri.so
1473bd6c1c4a96193ea170b4e912fd02dd26bc89  /usr/lib64/dri/i965_dri.so
a2b6a129c22dfa66edcd1aeb8b02d721d2f99cbe  /usr/lib64/dri/i965_drv_video.so
c6f043bb6712c4a72567e100ac85fa27febe2aec  /usr/lib64/dri/kms_swrast_dri.so
7713f6df3302ca0b09c280f7fa430baa250b7354  /usr/lib64/dri/nouveau_drv_video.so
1473bd6c1c4a96193ea170b4e912fd02dd26bc89  /usr/lib64/dri/r200_dri.so
c6f043bb6712c4a72567e100ac85fa27febe2aec  /usr/lib64/dri/r300_dri.so
c6f043bb6712c4a72567e100ac85fa27febe2aec  /usr/lib64/dri/r600_dri.so
7713f6df3302ca0b09c280f7fa430baa250b7354  /usr/lib64/dri/r600_drv_video.so
1473bd6c1c4a96193ea170b4e912fd02dd26bc89  /usr/lib64/dri/radeon_dri.so
c6f043bb6712c4a72567e100ac85fa27febe2aec  /usr/lib64/dri/radeonsi_dri.so
7713f6df3302ca0b09c280f7fa430baa250b7354  /usr/lib64/dri/radeonsi_drv_video.so
c6f043bb6712c4a72567e100ac85fa27febe2aec  /usr/lib64/dri/swrast_dri.so
c6f043bb6712c4a72567e100ac85fa27febe2aec  /usr/lib64/dri/virtio_gpu_dri.so
c6f043bb6712c4a72567e100ac85fa27febe2aec  /usr/lib64/dri/vmwgfx_dri.so

video card it’s a intel hd 5000 (broadwell gt2)

I keep the following link handy…

https://trac.ffmpeg.org/wiki/HWAccelIntro

It’s a treasure of info stuffed in very few words,
Among other things, describes the various hardware acceleration capabilities and options available for various GPUs, if you’re not satisfied with your current perfromance perhaps another method is possible.

TSU

I’ve had the same issue with Wayland but currently use X11.
VAAPI acceleration works fine for me under X11.
This is with intel-vaapi-driver package installed through zypper.

It would be nice if a guide outlined VAAPI acceleration options in mpv under Wayland/EGL since don’t have time to play around with it right now.
Especially since mpv is the backend for so many players.

The following options might have improved the situation under Wayland.

mpv --hwdec=vaapi-copy,vaapi --gpu-context=wayland --vo=gpu myvideo.mp4

Some people have apparently had success with…

mpv --vo=opengl --hwdec=vaapi --opengl-backend=wayland video.mp4

MPV reports that VAAPI is enabled but I get frozen video.

The following gives me the best result under Wayland.

mpv --vo=opengl --hwdec=vaapi-copy video.mp4

Now get accelerated playback without freezes and error message [vo/opengl/vaapi-egl] vaAcquireSurfaceHandle() failed (invalid VASurfaceID)

Not using hybrid_drv_video.so
Using hardware decoding (vaapi-copy).
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 1280x720 nv12
AV: 00:00:29 / 00:21:35 (2%) A-V: 0.000

get same result… high cpu and mpv display these info

(+) Video --vid=1 () (h264 1920x1080 29.970fps)
(+) Audio --aid=1 (
) (aac 2ch 48000Hz)
failed to open /usr/lib64/dri/hybrid_drv_video.so
Not using hybrid_drv_video.so
[ffmpeg/video] h264: Failed setup for format vaapi_vld: hwaccel initialisation returned error.
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 1920x1080 yuv420p
AV: 00:00:17 / 00:09:44 (2%) A-V: 0.146 Dropped: 152

Doesn’t look like you’re getting hardware acceleration unfortunately.

MPV will return something like
Using hardware decoding (vaapi-copy) if vaapi is active.
That might be why CPU usage is so high if video playback is high quality at that resolution.

Not sure why VAAPI doesn’t initialize. You could possibly try to see if acceleration is available on other videos.

Sounds similar to intel-vaapi-driver fails to load in a Gnome Shell Wayland session · Issue #203 · intel/intel-vaapi-driver · GitHub

Forcing native wayland may work.

tried another video and worked

ok with this one

Video
ID                                       : 224 (0xE0)
Format                                   : MPEG Video
Format version                           : Version 2
Format profile                           : Main@Main
Format settings, BVOP                    : No
Format settings, Matrix                  : Default
Format settings, GOP                     : N=18
Duration                                 : 9 min 44 s
Bit rate mode                            : Variable
Bit rate                                 : 5 671 kb/s
Maximum bit rate                         : 9 000 kb/s
Width                                    : 720 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.684
Time code of first frame                 : 00:00:00:00
Time code source                         : Group of pictures header
GOP, Open/Closed                         : Open
GOP, Open/Closed of first frame          : Closed
Stream size                              : 395 MiB (95%)


was not able for this one…


Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High 4:4:4 Predictive Intra@L4
Format settings                          : CABAC
Format settings, CABAC                   : Yes
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 9 min 43 s
Bit rate mode                            : Variable
Bit rate                                 : 213 Mb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 29.970 (30000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : MBAFF
Scan type, store method                  : Interleaved fields
Scan order                               : Top Field First
Bits/(Pixel*Frame)                       : 3.420
Stream size                              : 14.4 GiB (100%)
Writing library                          : x264 core 155
Encoding settings                        : cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=7 / psy=0 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=0 / chroma_qp_offset=0 / threads=1 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=tff / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=1 / keyint_min=1 / scenecut=40 / intra_refresh=0 / rc=cqp / mbtree=0 / qp=0
Color range                              : Limited
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
Codec configuration box                  : avcC

strange because on https://software.intel.com/en-us/articles/quick-reference-guide-to-intel-processor-graphics

it wrote for the 5500

AVC/H.264, MPEG2, VC1 Decode
Enables smoother playback and longer battery life when viewing h.264, MPEG2, or VC1 DVD, Blu-ray, or streaming conten