Possible RPi mpv --hwdec=v4l2m2m-copy solution

I was testing my latest linux-rpi4-udl 5.15.11-1 DVB/DVBT/ATSC kernel (This should work with all pi kernels in the repo) I pushed yesterday to try to get to the bottom of why “mpv --hwdec=v4l2m2m-copy” mp4 HW decoding stopped working with the newer kernels as per this closed thread @enrico20026 started:

https://forum.manjaro.org/t/arm-device-update-issue/85201

I decided to try some kodi configs that uses v4l for HW decoding and it appears that it works with v4lm2m using HW decoding (v4lm2m-copy)

Config.txt changes:

#gpu_mem=64
 
#enable vc4
dtoverlay=vc4-fkms-v3d,cma-512
#max_framebuffers=2
dtoverlay=rpivid-v4l2
disable_fw_kms_setup=1

Added an additional parameter to the command line:

mpv --hwdec=v4l2m2m-copy --hwdec-codecs=all bbb_sunflower_1080p_30fps_normal.mp4

2 Likes

so, does ffmpeg need to rebuild?

No, the one in the repo that mpv is compiled with works with mp4.

Could you show config.txt complete and mpv/config ? Trying your setting i have channels rai working with v4l2m2m-copy

and mediaset not working

when i try mediaset hd or others hd channels i get error on libva and
after minutes, i get crash…

using local/linux-rpi4-rc 5.12.rc8-1
all channels hd work

I have multiple stuff in it for different configs:

over_voltage=5
arm_freq=2000

#gpu_mem=512
#initramfs initramfs-linux.img followkernel
#device_tree=dtbs/broadcom/bcm2711-rpi-4-b.dtb
kernel=kernel8.img
#kernel=Image
arm_64bit=1
disable_overscan=1

#enable sound
dtparam=audio=on
#hdmi_drive=2

# Enable bluetooth using kernel
dtparam=krnbt=on

#dtoverlay=dwc2

#enable vc4
dtoverlay=vc4-fkms-v3d,cma-512
#dtoverlay=vc4-kms-v3d,cma-512
#max_framebuffers=2
dtoverlay=rpivid-v4l2
disable_fw_kms_setup=1

#disable_splash=1

I did not mention it because I did not think it affects it but I have xf86-video-fbdev installed.

here is wayland with xwayland disabled:
…sway/config

xwayland disable

libva should not be used. What do you have in your mpv config:

[ray@pi4 ~]$ cat ~/.config/mpv/config 
ao=pulse
autofit-smaller=90%
autofit-larger=90%
volume-max=400
dtoverlay=vc4-fkms-v3d,cma-512

kodi config.txt dtoverlay=vc4-kms-v3d,cma-512 maybe (it doesnt work :frowning:

installing mesa-git: libva-mesa-driver is uninstalled, but mpv-git :

[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
Using hardware decoding (v4l2m2m-copy).

if i try to uninstall libva:

Packages (100) abseil-cpp-20211102.0-1 chromaprint-1.5.1-1 chromium-96.0.4664.110-1 dbus-glib-0.112-2
faac-1.30-2 faad2-2.10.0-1 ffmpeg-2:4.4.1-1 ffms2-2.40-1 fftw-3.3.10-1 firefox-95.0.2-1
fluidsynth-2.2.4-1 gsm-1.0.19-1 gssdp-1.4.0.1-1 gst-libav-1.18.5-1
gst-plugins-bad-1.18.5-4 gst-plugins-bad-libs-1.18.5-4 gstreamer-vaapi-1.18.5-1
gupnp-1:1.4.1-1 gupnp-igd-1.2.0-2 hidapi-0.11.0-1 hunspell-1.7.0-3 hwloc-2.7.0-1
imath-3.1.3-4 jasper-2.0.33-1 jemalloc-1:5.2.1-6 kwayland-5.89.0-1 l-smash-2.14.5-2
libass-0.15.2-1 libavtp-0.1.0-2 libbs2b-3.1.0-7 libdbusmenu-qt5-0.9.3+16.04.20160218-6
libdc1394-2.2.6-2 libdca-0.0.7-1 libdvdnav-6.1.1-1 libevent-2.1.12-1 libgme-0.6.3-1
libibus-1.5.25-5 libinstpatch-1.1.6-1 libkate-0.4.1-7 liblrdf-0.6.1-4 libmicrodns-0.2.0-1
libmms-0.6.4-3 libmng-2.0.3-3 libmodplug-0.8.9.0-3 libmpcdec-1:0.1+r475-3 libnice-0.1.18-2
libofa-0.9.3-9 libplacebo-4.157.0-1 libsoxr-0.1.3-2 libsrtp-1:2.4.2-1 libssh-0.9.6-1
libva-utils-2.11.1-0.1 libvdpau-1.4-1 libvdpau-va-gl-0.4.2-3 lua52-5.2.4-5
mailcap-2.1.53-1 minizip-1:1.2.11-5 mjpegtools-2.2.1-1 mpv-git-0.34.0_120_gf40d66f624-1
neon-0.32.1-1 opencore-amr-0.1.5-5 openexr-3.1.3-1 openmpi-4.1.2-1 portaudio-1:19.7.0-1
python-jinja-3.0.3-3 python-pyqt5-5.15.6-6 python-pyqt5-sip-12.9.0-3
python-pyqt5-webengine-5.15.5-3 qt5-imageformats-5.15.2-1 qt5-location-5.15.2-4
qt5-webchannel-5.15.2+kde+r5-1 qt5-webengine-5.15.7-2.1
qutebrowser-git-2.4.0.r156.g955c6fb76-1 raptor-2.0.15-17 re2-1:20211101-1 rnnoise-0.4.1-1
rtmpdump-1:2.4.r96.fa8646d-6 rubberband-2.0.0-1 sdl2-2.0.18-3 shaderc-2021.3-1
simplescreenrecorder-0.4.3-1 snappy-1.1.9-2 soundtouch-2.3.0-1 spandsp-0.0.6-3 srt-1.4.4-1
telegram-desktop-3.4.0-1 ttf-opensans-1.101-2 tvheadend-4.2.8-4 uchardet-0.0.7-1
uriparser-0.9.5-1 vapoursynth-R57-2 vid.stab-1.1-3 wildmidi-0.4.4-1
x264-3:0.163.r3060.5db6aa6-1 xvidcore-1.3.7-2 zbar-0.23.1-9 zimg-3.0.3-1 zvbi-0.2.35-4
zxing-cpp-1.2.0-1 libva-2.12.0-0.1

Total Removed Size: 1022.40 MiB
Blockquote

mesa-git conflicts:

Conflicts With : mesa opencl-mesa vulkan-intel vulkan-radeon vulkan-swrast vulkan-broadcom
vulkan-panfrost vulkan-mesa-layer libva-mesa-driver mesa-vdpau
Replaces : None

libva gets pulled in with other packages. mpv will ses and try it but can not use it on the rpi.

I installed Manjaro ARM yesterday with the minimal installation on a RPI4 for Kodi as media center.

Whatever modification you make, please do not mess up with libcec-rpi 6.xxxx, as it does not work with fkms, but only with kms.
I have the default kernel e.g. 5.10.83-1-MANJARO-ARM-RPI
Which more recent kernel version i could install to be sure to have HW acceleration and libcec working ?
Thanks

I do not mess with libcec-rpi, archarm provides it. The one in the repo works in KMS only. You have to go 1 version down for it to work with FKMS.

12m
state of the art:
old linux-rpi4-rc 5.12 ok

Linux archlinux 5.16.0-rc8-1-MANJARO-ARM-RPI #1 SMP PREEMPT Wed Jan 5 16:13:15 UTC 2022 aarch64 GNU/Linux
works for RAI channels:

(+) Video --vid=1 (h264 720x576 25.000fps)
(+) Audio --aid=1 --alang=ita (mp2 2ch 48000Hz)
Audio --aid=2 --alang=oth (mp2 1ch 48000Hz)
Audio --aid=3 --alang=eng (mp2 2ch 48000Hz)
Subs --sid=1 --slang=ita,ita,eng (dvb_teletext)
[ffmpeg/audio] mp2: Header missing
Error decoding audio.
[ffmpeg/video] h264: co located POCs unavailable
[ffmpeg/video] h264: co located POCs unavailable
[ffmpeg/video] h264: co located POCs unavailable
AO: [alsa] 48000Hz stereo 2ch s16
VO: [gpu] 720x576 => 1024x576 yuv420p
AV: 00:00:02 / 00:00:03 (64%) A-V: -0.000 Cache: 1.0s/164KB
[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
Cannot load libcuda.so.1
[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
AV: 00:00:02 / 00:00:03 (66%) A-V: -0.000 Cache: 0.9s/160KB
[ffmpeg/video] h264_v4l2m2m: capture: driver decode error
[ffmpeg/video] h264_v4l2m2m: capture: driver decode error
[ffmpeg/video] h264_v4l2m2m: capture: driver decode error
mpv after last 3 messages works

when im on different muxer, mediaset and others, i get audio, but no screen:

Resuming playback. This behavior can be disabled with --no-resume-playback.
Playing: http://10.42.0.1:9981/stream/channelid/980712222?ticket=C2500DD78586115A2FFD1DD3ADC66AA40F16A208&profile=pass

[ffmpeg/video] h264: non-existing PPS 0 referenced
[ffmpeg/video] h264: non-existing PPS 0 referenced
[ffmpeg/video] h264: decode_slice_header error
[ffmpeg/video] h264: no frame!
ffmpeg message is repeated 20 or more
then i play ctrl+h to use hwdec=v4l2m2m-copy
and i get this without screen only audio

(+) Video --vid=1 (h264 1920x1080 50.000fps)
(+) Audio --aid=1 --alang=ita (ac3 2ch 48000Hz)
Audio --aid=2 --alang=eng (aac_latm 2ch 48000Hz)
Subs --sid=1 --slang=ita (dvb_teletext)
[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
Cannot load libcuda.so.1
[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
AO: [alsa] 48000Hz stereo 2ch float

i dont know if this is helpful 

Can you upload a couple of minutes of a non working stream some where I can download.

this is mesgd to start, working on your request

[ 8.790372] bcm2835-isp bcm2835-isp: Device node stats[2] registered as /dev/video23
[ 8.790401] bcm2835-isp bcm2835-isp: Register output node 0 with media controller

[ 8.790422] bcm2835-isp bcm2835-isp: Register capture node 1 with media controller
[ 8.790440] bcm2835-isp bcm2835-isp: Register capture node 2 with media controller
[ 8.790458] bcm2835-isp bcm2835-isp: Register capture node 3 with media controller
[ 8.807581] bcm2835-isp bcm2835-isp: Loaded V4L2 bcm2835-isp
[ 8.939706] Console: switching to colour frame buffer device 240x67
[ 9.075234] vc4-drm gpu: [drm] fb0: vc4drmfb frame buffer device
[ 9.095200] random: crng init done
[ 9.098668] random: 7 urandom warning(s) missed due to ratelimiting
[ 10.680027] bcmgenet fd580000.ethernet: configuring instance for external RGMII (RX delay)
[ 10.688961] bcmgenet fd580000.ethernet eth0: Link is Down
[ 12.735423] bcmgenet fd580000.ethernet eth0: Link is Up - 100Mbps/Full - flow control off
[ 12.744106] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 33.759232] cam-dummy-reg: disabling
[ 33.762860] cam1-reg: disabling
[ 148.086976] pcm512x 1-004c: No SCLK, using BCLK: -2

This is only audio (forced hwdec)
mpv --hwdec=v4l2m2m-copy 20\ Mediaset\ HD
[Possible RPi mpv –hwdec=v4l2m2m-copy solution - Pastebin.com](https://Only audio no video)

This is only audio (forced hwdec)
In this play, the cache grows unti crash:
AV: 00:00:32 / 00:00:43 (74%) A-V: 0.000 Cache: 11s/33MB
AV: 00:02:05 / 00:02:16 (91%) A-V: 0.000 Cache: 11s/108MB
and keep running:
AV: 00:00:32 / 00:00:43 (74%) A-V: 0.000 Cache: 11s/33MB
AV: 00:02:44 / 00:02:56 (93%) A-V: 0.000 Cache: 11s/139MB

mpv --hwdec=v4l2m2m-copy Rai\ 1\ HD
This is ok:
cache also is ok:
mpv --hwdec=v4l2m2m-copy Rai\ 1\ HD > mpvlog2.txt
AV: 00:00:19 / 00:00:21 (93%) A-V: 0.000 Dropped: 4 Cache: 0.6s/287KB

playng mpv chan1 chan2 chan 3
example:

mpv --vd-lavc-check-hw-profile=no playlistMediaset

where playlist is a list of link to channels (im a spam for pastebin for the moment im sorry i give the log:

#EXTM3U
#EXTINF:-1 tvg-id=“1e7b743a2c732ac06379e534556a8049”,Rete4 HD
http://10.42.0.1:9981/stream/channelid/980712222?ticket=C2500DD78586115A2FFD1DD3ADC66AA40F16A208&profile=pass
#EXTINF:-1 tvg-id=“3d2ffe80f13e2156e11e010815dff595”,Canale5 HD
http://10.42.0.1:9981/stream/channelid/16658237?ticket=7C75371FE39707953FCE5494030F5ACCFC21977D&profile=pass

i get this log from ffmpeg:

[ffmpeg/video] h264: non-existing PPS 0 referenced
[ffmpeg/video] h264: non-existing PPS 0 referenced
[ffmpeg/video] h264: decode_slice_header error
[ffmpeg/video] h264: no frame!
[ffmpeg/video] h264: non-existing PPS 0 referenced
[ffmpeg/video] h264: non-existing PPS 0 referenced
[ffmpeg/video] h264: decode_slice_header error
[ffmpeg/video] h264: no frame!
Not seekable, but enabling seeking on user request.
 (+) Video --vid=1 (h264 1920x1080 50.000fps)
 (+) Audio --aid=1 --alang=ita (ac3 2ch 48000Hz)
     Audio --aid=2 --alang=eng (aac_latm 2ch 48000Hz)
[ffmpeg/video] h264: reference picture missing during reorder
[ffmpeg/video] h264: Missing reference picture, default is 2147483647
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: number of reference frames (0+5) exceeds max (4; probably corrupt input), discarding one
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: number of reference frames (0+5) exceeds max (4; probably corrupt input), discarding one
[ffmpeg/video] h264: reference picture missing during reorder
[ffmpeg/video] h264: Missing reference picture, default is 65618
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: mmco: unref short failure
!!! hwdec !!! --------------
AO: [alsa] 48000Hz stereo 2ch float
VO: [gpu] 1920x1080 yuv420p
[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)

while on the Raiplaylist
here i posted a wrong file, now is right apologize sorry :slight_smile:

Resuming playback. This behavior can be disabled with --no-resume-playback.
Playing: http://10.42.0.1:9981/stream/channelid/614691879?ticket=6F4DC4200C187623158AB495AA59BA295A3AD5CE&profile=pass
[ffmpeg/video] h264: non-existing PPS 0 referenced
[ffmpeg/video] h264: non-existing PPS 0 referenced
[ffmpeg/video] h264: decode_slice_header error
[ffmpeg/video] h264: no frame!
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: number of reference frames (0+5) exceeds max (4; probably corrupt input), discarding one
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: mmco: unref short failure
Not seekable, but enabling seeking on user request.
 (+) Video --vid=1 (h264 1920x1080 25.000fps)
 (+) Audio --aid=1 --alang=ita (ac3 2ch 48000Hz)
     Audio --aid=2 --alang=eng (aac_latm 2ch 48000Hz)
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: number of reference frames (0+5) exceeds max (4; probably corrupt input), discarding one
[ffmpeg/video] h264: mmco: unref short failure
AO: [alsa] 48000Hz stereo 2ch float
[ffmpeg/video] h264: mmco: unref short failure
[ffmpeg/video] h264: mmco: unref short failure
VO: [gpu] 1920x1080 yuv420p
[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[vaapi] libva: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
Saving state.
Not seekable, or time unknown - not saving position.

Exiting... (Quit)

I was wanting @2 minute video sample I could download and test here.

It looks like from your post you may be using tvheadend. If that is the case then you may be better off using tvheadend as a backend for kodi then you can have HW decoding for h264 better suited for the rpi. It requires an addon package I have made for kodi to interface with tvheadend.

Here is the same video I posted in my OP playing in kodi-rpi:

Housekeeping … no activity …