Raspberry Pi 3 hardware accelerated video playback
Table of contents
About how to play video with hardware video decode on RPi3 and a Wayland desktop environment.
Motivation🔗
- hardware video decode uses less CPU and is more power efficient
- old MMAL isn't supported now
- everyone have switched to standard V4L2 APIs (see raspberrypi/userland)
- standard
mpv
shipped with ArchLinux ARM do support hardware video decode on RPi3, BUT:- need to use
--hwdec=v4l2m2m-copy
- only compatible with
--vo=gpu
on Wayland(Sway), not--vo=dmabuf-wayland
- need to use
So, in order to play video smoothly on Wayland, run mpv --vo=gpu video.mp4
, but CPU load will be very high. To play with lower CPU usage, use mpv --hwdec=v4l2m2m-copy --vo=gpu video.mp4
, but the playback will be choky. None of them is ideal.
Solution🔗
Build mpv against rpi-ffmpeg which implements v4l2m2m
(w/o -copy
) for Raspberry Pi, and that will be compatible with dmabuf-wayland
, which gives a decent performance.
So my procedure is:
- clone mpv-build
- run
./update
in mpv-build's folder - add rpi-ffmpeg as a remote for freshly cloned ffmpeg repository and switch to
release/5.1/main
(mpv requires ffmpeg 4.4 or later) - add extra ffmpeg options to
ffmpeg_options
under mpv-build's folder(see content below) - run
./build -j4
in mpv-build's folder - then you can utilize hardware video decode with something like
mpv --vo=dmabuf-wayland --hwdec=v4l2m2m video.mp4
Content for ffmpeg_options
(not all necessary but I haven't tested it):
--enable-libx264
--enable-libmp3lame
--enable-libfdk-aac
--enable-libdrm
--enable-opengl
--enable-outdev=vout_drm
--enable-hwaccels
--enable-v4l2_m2m
--enable-nonfree
--enable-sand
--enable-v4l2-request
Appendix🔗
The hardware decode node for RPi3 is /dev/video10
. To see supported formats, run v4l2-ctl --list-formats-out -d 10
.