gravity-addiction / rpi-mpv

rpi scripts for compiling mpv on rpi
MIT License
7 stars 1 forks source link

Rpi4 (8GB) hevc support, mpv command and README #2

Open danboid opened 4 years ago

danboid commented 4 years ago

rpi-mpv correctly detects my RPi 4 and it successfully builds ffmpeg, mpv and their dependencies although I have to manually install the ffmpeg package and I've opened a separate issue for that. Unfortunately I haven't got mpv to play my UHD hevc/h265 videos yet. Can anyone confirm that h265/hevc accelerated playback is possible using mpv on the RPi4 under Raspbian buster?

$ mpv VID.mp4 
Playing: VID.mp4
 (+) Video --vid=1 (*) (hevc 3840x2160 29.997fps)
 (+) Audio --aid=1 --alang=eng (*) (aac 2ch 48000Hz)
AO: [pulse] 48000Hz stereo 2ch float
VO: [rpi] 3840x2160 yuv420p
* failed to add service - already in use?

I get the same error if I run mpv with sudo. This video plays fine under raspbian's VLC build.

Another closely related issue that I think should be covered in the README is what mpv command should I be using to play a h265 on my rpi4? There is the following comment in the script:

##### This is where we create mpv's configuration file that controls how mpv behaves with ALL video and audio. Please see the full version of Appendix 1 for details; also see the testing section for commentary on the "ytdl-format" line. NOTE: The "alsa-buffer-time" completes the fix to the ALSA issue I described earlier. It defines an audio buffer time of 800,000 microseconds (8/10 of a second). Through extensive testing, I found that this was the final step needed to get mpv and ALSA to play nice together.
# mkdir -p /home/pi/.config/mpv
# echo "--fullscreen
# rpi-background=yes
# screenshot-format=png
# ytdl-format=bestvideo[height<=?1080][fps<=?30][vcodec!=?vp9]+bestaudio/best
# --alsa-buffer-time=800000" > /home/pi/.config/mpv/mpv.conf

This config example looks like you are using the rpi backend for mpv which was apparently deprecated in mpv 0.23 yet this script installs mpv 0.29 where they recommend using --vo=opengl, according to the man page for mpv, so maybe this config example only applies to RPi 1/2/3 users?

I've read a post by one of the mpv developers stating that the RPi4 should be capable of playing back accelerated video without any broadcom blobs by using v4l2 under mpv, but I also think he said there was an issue preventing this currently in the raspbian kernel.

danboid commented 4 years ago

Here is the mpv issue where one of the devs says accelerated video playback should be possible without any broadcom binaries on the rpi4:

https://github.com/mpv-player/mpv/issues/7492

danboid commented 4 years ago
$ mpv --vo=gpu --gpu-context=drm --hwdec=v4l2m2m-copy --drm-connector=1.HDMI-A-1 VID.mp4 
Playing: VID.mp4
 (+) Video --vid=1 (*) (hevc 3840x2160 29.997fps)
 (+) Audio --aid=1 --alang=eng (*) (aac 2ch 48000Hz)
[vo/gpu] VT_GETMODE failed: Inappropriate ioctl for device
[vo/gpu/opengl] Failed to set up VT switcher. Terminal switching will be unavailable.
[vo/gpu/opengl] Cannot retrieve DRM resources: Operation not supported
[vo/gpu/opengl] Failed to create KMS.
[vo/gpu] Failed initializing any suitable GPU context!
Error opening/initializing the selected video_out (--vo) device.
Video: no video

Exiting... (Errors when loading file)
gravity-addiction commented 4 years ago

@danboid thanks for spending the time to poke at this script. I have ran across the error in your first post and found it to be caused by the dtoverlay=vc4-fkms-v3d in the /boot/config.txt .. my understanding is that the overlay uses the broadcom mmal and therefore doesn't let mpv have any access to the hwdec. simple, reming out the line with a # and reboot gives mpv access to the hwdecoder again.

I understand that v4l2 is built on top of mmal .. so this might be related.

with disabling the vc4-fkms-v3d dtoverlay I only seem to lose dual monitor support.

danboid commented 4 years ago

Hi @gravity-addiction

Yes, I did have dtoverlay=vc4-fkms-v3d in my config.txt so I commented that out and rebooted but mpv still isn't working, I just get the error:

* failed to add service - already in use?

I get the same error if I run mpv as root or if I boot into console mode. Keyboard input stops working after the first (failed) attempt to play a video with mpv, forcing me to power cycle in console mode or close the terminal window. I have tried increasing the GPU memory to 256 MB but that hasn't helped.

Have you got any model of the RPi4? Have you successfully played a UHD h265 video file with hw accel under mpv? If so, what command are you using?

Any other suggestions? I updated my rpi firmware recently.

Thanks

gravity-addiction commented 4 years ago

@danboid make sure it's not in there twice, i've found the dtoverlay line in my config.txt under both the [pi4] and [all] sections, likely something I did to myself.

I use a rpi4 (4g) as my daily desktop machine. It does play 4k video files, they are just really choppy. I know the libreElec project has done their own ffmpeg code, along with other updates that fixes the smooth 4k playback. I just downloaded the jellyfish uhd hevc 120mbps 10bit and it plays, very choppy on my desktop machine. The --fullscreen switch seems to be required on 4k files, otherwise i've cleared out my ~/.config/mpv/mpv.conf file and ran mpv with just the filename and --fullscreen switch

danboid commented 4 years ago

Yes, dtoverlay=vc4-fkms-v3d was in config.txt twice and I hadn't spotted the second instance. I commented that out too but after rebooting X doesn't boot to the correct, full UHD res of my display without that line, I can only do some weird 1800x900 res or something. I did try mpv in this mode but it still doesn't work, I get exactly the same error as before.

Do you have a UHD or 4K HDMI display attached to your RPi4?

Maybe the GPU on the 8GB Rpi4 is different enough to the 4GB version to stop this working for me?

danboid commented 4 years ago

I have smooth playback of UHD h265 and FullHD h264 files using VLC under Raspbian, which proves it should be possible under mpv and ffplay too.

Under Raspbian VLC preferences, go to Video settings and ensure Output is set to MMAL-based vout plugin, not MMAL X11 splitter.

danboid commented 4 years ago

I have tried using --fullscreen, I get the same error as without.

gravity-addiction commented 4 years ago

i've always had sharing problems with x taking mmal support and locking it to display a 4k monitor or two 1080p monitors. There has to be some updates to mpv like vlc that allows the sharing, or at least piping it through x

danboid commented 4 years ago

Are you aware of any other 8GB RPi4 users having used this script successfully yet? Maybe I'm the first to try it? I've not tried the 64 bit Raspbian kernel yet but that is less likely to work I'd imagine.

danboid commented 4 years ago

As far as I can tell, they should be using the same GPU.

gravity-addiction commented 4 years ago

8gig, no.. I have 4gig units and it does tie into the mmal decoder, I think the implementation is just not there in mpv for the rpi4. The project that drove me into poking this beast was focused on playing 1080p smoothly on a 3a+

gravity-addiction commented 4 years ago

i dont think the gpu is any different between the 4 and 8 gig units.. I haven't come across any difference charts for the 4 or 8, i'd assume it's just memory

danboid commented 4 years ago

If I get it running properly on the 8GB model I shall let you know.

danboid commented 4 years ago

I have tried to use dtoverlay=vc4-kms-v3d and dtoverlay=vc4-kms-v3d-pi4 but fkms is the only one that seems to work at all for me.

Marquees-Brownlee commented 3 years ago

@gravity-addiction @danboid Any luck on trying to get this script to work on your end? I have been trying it on a Raspberry Pi 4, 4 GB model, to no avail as well. The error, "* failed to add service - already in use?" would show up in the terminal at the end of the script, despite the fact that I have commented out both "dtoverlay=vc4-fkms-v3d" in the boot config text file. I would very much love to get MPV working with hardware acceleration working on my Raspberry Pi 4 here. Thanks for any advice.

danboid commented 3 years ago

No, I never did get mpv working with hw accel on my RPi 4 but I'm happy to announce that hw acceleration is now working very nicely for mpv, ffmpeg and VLC on the NVIDIA Jetson Nano. I presume it will also work on the other Jetson boards too?

Its better than the RPi4 as a media playback device as it supports h264 hw decoding (and a few other codecs) too and its all open source code.

https://forums.developer.nvidia.com/t/hardware-decoding-in-mpv-player/75872/7

zmartell commented 3 years ago

@danboid

Would you mind sharing which revision version of the NVIDIA Jetson Nano you are using? If that is true, i would like to purchase one of those.

No, I never did get mpv working with hw accel on my RPi 4 but I'm happy to announce that hw acceleration is now working very nicely for mpv, ffmpeg and VLC on the NVIDIA Jetson Nano. I presume it will also work on the other Jetson boards too?

Its better than the RPi4 as a media playback device as it supports h264 hw decoding (and a few other codecs) too and its all open source code.

https://forums.developer.nvidia.com/t/hardware-decoding-in-mpv-player/75872/7

danboid commented 3 years ago

I'm using the original 4 GB nano but I expect it would run fine on the 2 GB model too.

spookyfirehorse commented 3 years ago

New RPI4 FFMPEG and MPV

for rpi3 change the configure settings in ffmpeg to a53

first edit this is very important because the sources of ffmpeg is there . of corce there another ffmpeg is in the repro but this is the right one

sudo nano /etc/apt/sources.list.d/raspi.list

deb http://archive.raspberrypi.org/debian/ bullseye main deb-src http://archive.raspberrypi.org/debian/ bullseye main

store it

than sudo apt update

and sudo apt build-dep ffmpeg mpv

so now we download the source code

apt source ffmpeg

than change the directory

cd ffmpeg-4.3.4 or your versions number

./configure --prefix=/usr --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf/neon/vfp --incdir=/usr/include/arm-linux-gnueabihf --extra-libs=-latomic --extra-cflags=-I/usr/include/libdrm --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-nonfree --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libpulse --enable-nonfree --enable-libfdk-aac --enable-libx265 --enable-version3 --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --enable-vulkan --enable-mmal --enable-avresample --disable-filter=resample --enable-libwavpack --enable-libv4l2 --enable-sand --enable-vout-drm --enable-vout-egl --enable-v4l2-request --enable-libudev --disable-rpi --cpu=cortex-a72 --enable-neon --enable-v4l2-request --enable-sand --enable-pocketsphinx --disable-static --enable-opencl --enable-libsrt --disable-vaapi --disable-vdpau --enable-librabbitmq --arch=armv7l --extra-version=0+deb11u1+rpt2

than make -j4 and finaly sudo make -j4 install

so ffmpeg is installed

and now mpv

apt source mpv

cd mpv-0.32

sudo chmod 777 waf

ln -s /usr/bin/python3.9 /usr/bin/python

./waf configure --prefix=/usr --libdir=/usr/lib/arm-linux-gnueabihf --confdir=/etc/mpv --zshdir=/usr/share/zsh/vendor-completions --enable-cdda --enable-dvdnav --enable-libmpv-shared --disable-libsmbclient --enable-sdl2 --enable-sndio --disable-build-date --enable-dvbin

./waf -j4 sudo ./waf -j4 install

mpv is installed

nano .config/mpv/mpv.conf

and copy past

gpu-api=opengl

spirv-compiler=auto

panscan=1.000

demuxer=matroska

gpu-context=x11vk

gpu-api=vulkan

vulkan-async-compute=yes

vulkan-async-transfer=yes

vulkan-queue-count=8

vulkan-swap-mode=immediate

no-demuxer-thread vd-lavc-threads=1 video-sync=audio keep-open=yes opengl-glfinish=yes gpu-context=x11egl gpu-api=opengl vo=gpu

if you want equalizer with alsa : apt install libasound2-equalizer

ao=alsa

audio-device=alsa/plugequal

ao=pulse

audio-device=PulseEffects_apps

hwdec=auto-copy hwdec-codecs=all hwdec-image-format=yuv420p

profile=pseudo-gui

no-audio-display

autofit=500

ao=pulse

audio-device=pulse/ladspa_output.mbeq_1197.mbeq

volume=30 ytdl-raw-options=proxy=[socks5://127.0.0.1:8123] ytdl-format=best

fullscreen=yes

audio-display=no

cache=no

no-border

hls-bitrate=max

audio-samplerate=96000

audio-format=float

af=lavfi-crystalizer=1,lavfi-bass=gain=2

af=lavfi-crystalizer=1,lavfi-bass=gain=3,scaletempo2

video-sync=display-resample

volume-max=200 audio-channels=stereo framedrop=decoder+vo

audio-format=s16

hr-seek-framedrop=no

force-seekable=yes

x11-bypass-compositor=no

index=recreate

demuxer-rawaudio-format=s24le

demuxer-rawaudio-rate=48000

demuxer-max-bytes=2000MiB

demuxer-readahead-secs=300

vf=hqdn3d,pp=de

oac=pcm_s16le

alang=de,ger user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"

script-opts=ytdl_hook-ytdl_path=/usr/local/bin/yt-dlp

ytdl=yes profile=sw-fast gpu-dumb-mode=yes scale=lanczos

[drm]

hwdec=auto-copy hwdec-codecs=all drm-connector=1.HDMI-A-1

drm-connector=HDMI-A-1

gpu-context=drm vo=drm gpu-api=opengl gpu-hwdec-interop=drmprime-drm drm-mode=1 vo=drm hwdec-image-format=drm_prime ao=alsa audio-device=alsa/plugequal

ao=pulse

volume=30 ytdl-raw-options=proxy=[socks5://127.0.0.1:8123] ytdl-format=best cache=no hls-bitrate=max

audio-samplerate=48000

af=lavfi-crystalizer=1,lavfi-bass=gain=2

af=lavfi-crystalizer=1,lavfi-bass=gain=3,scaletempo2

audio-channels=stereo framedrop=decoder+vo keep-open=yes

index=recreate

oac=pcm_s16le

alang=de,ger user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"

script-opts=ytdl_hook-ytdl_path=/usr/local/bin/yt-dlp

ytdl=yes

untimed

profile=sw-fast

volume-max=200 scale=lanczos

no-demuxer-thread vd-lavc-threads=1 video-sync=audio

now you can play

from the command line without gui in drm mode

mpv --profile=drm test.mp4

normaly with gui only klick on file

cheers

gravity-addiction commented 3 years ago

@spookyfirehorse I compiled your version I was missing the ladspa and libflite libraries from removed them from your configure. It compiled fine. Thanks for the extended config. I'm still getting jerks with 1080p video. Sorry..

I Dusted off my Jetson nano a couple months ago, first try never got to the point where @danboid is. Going to try again soon tho.

spookyfirehorse commented 3 years ago

Why sorry ?

G @.***> schrieb am Do., 10. Juni 2021, 01:45:

@spookyfirehorse https://github.com/spookyfirehorse I compiled your version I was missing the ladspa and libflite libraries from removed them from your configure. It compiled fine. Thanks for the extended config. I'm still getting jerks with 1080p video. Sorry..

I Dusted off my Jetson nano a couple months ago, first try never got to the point where @danboid https://github.com/danboid is. Going to try again soon tho.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gravity-addiction/rpi-mpv/issues/2#issuecomment-858172047, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALIWEPFMHCOFWLU344RQS5DTR74IBANCNFSM4Q4LERCQ .

danboid commented 3 years ago

I've recently been playing with some Amlogic S905X3 based TV boxes trying to get the meson vpu hw video decoding to work. The X96 Air Q1000 is a great value bit of kit and it can play 1080p videos full screen with mpv under Wayland with no dropped frames without any hardware decoding but unfortunately I have had no luck getting the hardware decoding to work with the videos I've tried.

spookyfirehorse commented 3 years ago

OK now from my side sorry

Dan MacDonald @.***> schrieb am Sa., 12. Juni 2021, 12:07:

I've recently been playing with some Amlogic S905X3 based TV boxes trying to get the hw video decoding to work. The X96 Air Q1000 is a great value bit of kit and it can play 1080p videos full screen with mpv under Wayland with no dropped frames without any hardware decoding but unfortunately I have had no luck getting the hardware decoding to work with the videos I've tried.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gravity-addiction/rpi-mpv/issues/2#issuecomment-860031849, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALIWEPES7UWVNGLAJEKUJNDTSMWURANCNFSM4Q4LERCQ .