Gadgetguy
Posts: 98
Joined: Fri Aug 15, 2014 2:55 am

Recipe for hardware-accelerated mpv video player in Raspbian Buster using Raspberry Pi 3 !!!

Sat Jul 13, 2019 3:48 am

For those who still don’t have a Raspberry Pi 4 and are using older Raspberry Pis with the legacy graphics driver enabled and who would like to have a hardware accelerated mpv in the Raspbian Buster distribution you might find my recipe for a successful compile useful.
I have managed to get mpv working in Buster with my Pi 3B
using the legacy graphics driver. I compiled Mpv against the pre-installed ffmpeg in the Buster repository (which is a special Raspberry version compiled with mmal enabled). It should also be emphasized these instructions only apply to Raspbian Buster with the legacy graphics driver enabled on Raspberry Pi’s prior to Pi 4.

In order to get a succesful compilation of mpv-with mmal hardware acceleration it is necessarary to update the Raspberry Pi firmware before beginning the compilation by using:

sudo rpi-update (see caution)

Of course you should be aware and warned that there are many cautions from authoritative sources on the Raspbian website that firmware updates should not be taken lightly as it may cause malfunctions in your distribution. I personally have not experienced any problems with my distribution however. You may wish to refer to the following official Raspbian documentation “Updating the kernel”:

https://www.raspberrypi.org/documentati ... pdating.md

which also gives you the command to restore your firmware to the latest stable firmware should you experience problems i.e.:


sudo apt-get install --reinstall raspberrypi-bootloader raspberrypi-kernel..





After updating the firmware I Installed the following packages from the Raspbian Buster repository
via Synaptic graphical package manager which also automatically installs their associated dependencies:

checkinstall
devscripts


libavcodec-dev
libavdevice-dev
libavfilter-dev
libavformat-dev
libavutil-dev
libpostproc-dev
libswresample-dev
libswscale-dev

libluajit-5.1-dev
libasound2-dev
libass-dev

libbluray-dev
libcdio-cdda-dev
libcdio-dev
libcdio-paranoia-dev
libdvdnav-dev
libdvdread-dev
libjpeg-dev
libjpeg62-turbo-dev
libv4l-dev



I then downloaded the latest mpv:

https://github.com/mpv-player/mpv/releases

:
to my home directory extracted it and opened the extracted folder in terminal. (It compiles fairly quickly.).I then input the following commands into terminal:


./bootstrap.py



export LIBRARY_PATH=/opt/vc/lib

export PKG_CONFIG_PATH=/opt/vc/lib/pkgconfig

export CPATH=/opt/vc/include





./waf configure --prefix=/usr
./waf build -j4
sudo checkinstall ./waf install


After the compilation completes you can of course delete the extracted folder but don’t forget to save your compiled deb file in safe storage in case you wish to use it again.

In order to get mpv working properly in raspberry pi. It is necessary to configure it properly by means of a configuration file – mpv.conf normally located in the folder:

/home/pi/.config/mpv


Although Mpv’s reference manual specifies that video out for Rasperry pi is specified as vo=gpu , I found this didn’t work. Rather I specified video out as the supposedly deprecated vo=rpi.


The contents of my mpv.conf (which work very well) are as follows:


rpi-background=yes
terminal=yes
vo=rpi
geometry=20%+1075+550
ytdl-format=bestvideo[ext=mp4][width<=1920][height<=1080]+bestaudio[ext=m4a]/best[ext=mp4]/best



( note- to get full screen video toggle the “f” key.. Of course if you wish to display full screen as soon as it opens you could insert fs=yes into configuration)

The entry :

geometry=20%+1075+550 

instructs mpv when the keyboard toggle “f” is used to toggle back and forth between a full screen and a small overlay pseudo-window if you will, that takes up 5% of the display and that starts at 1075 pixels from the right and 550 pixels down from the top and on my my television screen with a native resolution of 1360x768

This places a small but crystal clear video ( rendered as overlay rather than an x11 window) just up from the bottom right hand corner where it can be monitored and listened to without interfering too much with the rest of the screen and then toggled back and forth to fullscreen by using the keyboard command “ f ” . Obviously this
“hack “could be varied to suit personal preferences. Another “hack “ I experimented with was to instead put the following entry into the configuration file “ autofit=1% “ which allows you to toggle back and forth between full screen and a minuscule nearly invisible dot but still retain audio playback. These “hacks” allows you multitask, continue browsing, manipulate controls, change configurations etc. ( particularly when using mpv as the engine for the gui smplayer), while still monitoring the video in a small unobtrusive window. Various configurations options using autofit and geometry are described in  mpv's online manual referenced above.



The entry: rpi-background=yes instructs  mpv  to paint a black background on the sides if a standard definition video does not take up the full width of the screen as this is more aesthetically pleasing and less distracting 


The entry : ytdl-format=bestvideo[ext=mp4][width<=1920][height<=1080]+bestaudio[ext=m4a]/best[ext=mp4]/best



instructs  mpv  to play the best quality video returned by youtube-dl within the parameters specified.



Here is a succesful mpv.conf file I used for my 1080p television:


rpi-background=yes
terminal=yes
vo=rpi
geometry=20%+1500+825
ytdl-format=bestvideo[ext=mp4][width<=1920][height<=1080]+bestaudio[ext=m4a]/best[ext=mp4]/best






Since mmal video is rendered as an overlay it is important if you are in full screen mode to retain keyboard control or you are up the creek without a paddle so to speak. For mpv this means terminal must remain the active “focused” window .If you are in full screen and should lose focus on the terminal as the application “ on top “ you lose keyboard control. I notice this can happen if you should inadvertently though force of habit mouse click on the full screen display, when other windows are open. Focus can usually be quickly regained by pressing the alt-tab combo followed by fhe “f” toggle untill focus is regained. This is one of the few annoying drawbacks of mmal accelerated mpv/smplayer on the Pi. And it doesn’t happen often. It would be great if someone could offer advice on how to prevent this from happening in the first place. When watching a video with a web browser open I try to start the video when I am in a new tab.


So that your specifically compiled Raspberry Pi version of mpv does not get overwritten on distro update by the generic version of mpv currently in the Buster repository you should lock it and mark it as hold. The following article provides very useful information on how this can be effected:



https://www.linuxuprising.com/2018/10/h ... ng-in.html


I hope to post a follow up on experience with an mpv gui - smplayer which greatly enhances the experience of mpv especially on the older Raspberry pis which rely on an mmal overlay to achieve hardware accelerated video output.
f
Last edited by Gadgetguy on Sat Jul 13, 2019 9:23 am, edited 1 time in total.

User avatar
RPi_Mike
Posts: 191
Joined: Sat Dec 09, 2017 12:57 am
Location: United States

Re: Recipe for hardware-accelerated mpv video player in Raspbian Buster using Raspberry Pi 3 !!!

Sat Jul 13, 2019 8:42 am

Gadgetguy wrote:
Sat Jul 13, 2019 3:48 am
In order to get a succesful compilation of mpv-with mmal hardware acceleration it is necessarary to update the Raspberry Pi firmware before beginning the compilation by using:

sudo raspi-config (see caution)

Of course you should be aware and warned that there are many cautions from authoritative sources on the Raspbian website that firmware updates should not be taken lightly as it may cause malfunctions in your distribution.

So your very first instruction is to "update the Raspberry Pi firmware" with sudo raspi-config?

That's impossible since there's nothing in the Software Configuration Tool that would allow anyone to do that.

You were probably thinking about the vastly different sudo rpi-update command — especially given all your cautions and warnings!

Also, I can't help but notice that multiple items in "your recipe" are suspiciously similar or even identical to my script — like the 3 very specific export lines in exactly the same order. You could have at least switched things around to not make it so obvious.

User avatar
Michiel O.
Posts: 178
Joined: Mon Dec 12, 2016 12:06 pm

Re: Recipe for hardware-accelerated mpv video player in Raspbian Buster using Raspberry Pi 3 !!!

Sat Jul 13, 2019 9:11 am

RPi_Mike wrote:
Sat Jul 13, 2019 8:42 am
identical to my script
Where can I find your script?
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

User avatar
RPi_Mike
Posts: 191
Joined: Sat Dec 09, 2017 12:57 am
Location: United States

Re: Recipe for hardware-accelerated mpv video player in Raspbian Buster using Raspberry Pi 3 !!!

Sat Jul 13, 2019 9:38 am

Michiel O. wrote:
Sat Jul 13, 2019 9:11 am
Where can I find your script?

I was referring to a script I published last year. It's currently on the first page of this room, but here's a direct link. Please post there if you have any questions.

User avatar
Michiel O.
Posts: 178
Joined: Mon Dec 12, 2016 12:06 pm

Re: Recipe for hardware-accelerated mpv video player in Raspbian Buster using Raspberry Pi 3 !!!

Sat Jul 13, 2019 10:08 am

Thanks you for the link. You've done some impressive research work! And it's also packaged in a nice, easy-to-use script.
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

Gadgetguy
Posts: 98
Joined: Fri Aug 15, 2014 2:55 am

Re: Recipe for hardware-accelerated mpv video player in Raspbian Buster using Raspberry Pi 3 !!!

Sat Jul 13, 2019 12:19 pm

RPi_Mike wrote:

"So your very first instruction is to "update the Raspberry Pi firmware" with sudo raspi-config?

That's impossible since there's nothing in the Software Configuration Tool that would allow anyone to do that.

You were probably thinking about the vastly different sudo rpi-update command — especially given all your cautions and warnings!

Also, I can't help but notice that multiple items in "your recipe" are suspiciously similar or even identical to my script — like the 3 very specific export lines in exactly the same order. You could have at least switched things around to not make it so obvious."
[/quote]


In my initial and now corrected post, I noted the raspberry pi firmware must be updated in order to successfully compile a hardware accelerated mpv on the raspberry pi. I inadvertently and inexcusably gave readers the wrong command to accomplish this. As Rpi_Mike has correctly and helpfully pointed out ( thats what forums are for) I intended to advise readers (most of whom if they have got this far with the Raspberry Pi would have been aware of my glaring error) that the correct command to update the firmware is:

sudo rpi-update

The dangers of posting late at night and not carefully proofreading posts!


What is not so helpful is RPI_Mike’s attitude that he created ffmpeg and mpv and has some kind of proprietary right to it. He merely published on this forum a well written tutorial that many Pi users including myself fave found useful. I don’t disparage his contributions to the Raspberry Pi community which has been been very useful but merely his attitude that he created mpv. There have been lots of tutorials and information on compiling mpv for the Raspberry Pi scattered hither and yon throughout the internet. I have no intention of getting into a lengthy unproductive and unseemly argument with him but his posts and numerous unfriendly putdowns of other posters betray an arrogance which should not go unchallenged, and that I suspect derives from insecurity.

I freely acknowledge Mike ‘s expertise in linux and computing is vastly superior to mine but also probably vastly inferirior to many other posters on these forums. The purpose of forums such as these is both to provide help to other users and also to seek help, solutions and suggestions for problems.As stated, I have no pretensions to expertise in linux. Unlike most contributors to these forums I am uncomfortable and unfamiliar with the command line and usually prefer to use software with a gui if possible.

But to allay the suspicions of paranoid Mike it should be noted that I first compiled mpv on the Pi way back in early 2016 ( long before Mike appeared on the scene, and certainly not on my own but using information gleaned from various documents, tutorials, blogs and forums suggestions etc and I have been using it ever since, long before Mike’s script. I first posted about mpv on these forums back in 2016 because I was surprised considering how well mpv worked on the pi, at the almost non-existent mentions of mpv and smplayer on the official Raspberry Pi forums. I hoped my posts would both help other readers and also further the development of these video players for the Pi, eg:


GPU accelerated mpv media player combined with smplayer gui at:

https://www.raspberrypi.org/forums/view ... 5#p1044619

(by the way I am not the nwgat.ninja referred to in this post
as apparently some readers erroneouly surmised)

and

Nearly nirvana mpv and smplayer but can use a little help at:
https://www.raspberrypi.org/forums/view ... 5#p1005147

and Re: Smtube for quick efficient Youtube browsing

https://www.raspberrypi.org/forums/view ... 5#p1376549



Mike an admission I will acknowledge I did take
the following line :

export CPATH=/opt/vc/include

from “your “ script. I came across it when I was having trouble getting version 29 of
mpv to compile without error on stretch.

By the way where was your version of mpv for Buster for users of the 3B. And by the way where did you get the uncredited ideas for toggling mpv between full screen and a small predefined overlay and for painting a black background on standard definition videos. They weren’t in your original post Huh? Mike I noticed you used "I wanted FULL SCREEN NIRVANA" in one of your posts where did that come from? Don't you know I own that word. You shouldn't be so obvious when you purloin someone else's ideas.
After all no one else should use nirvana unless they give me credit!!

Other readers I hope will forgive my lengthy comments motivated by pique on Mikes unmannerly comments to me and others. I shall try to restrain myself from further such comments
However, Mike and other readers please don’t hesitate to advise if my recipe for mpv for Buster doesn’t work for you or is any way deficient.

User avatar
RPi_Mike
Posts: 191
Joined: Sat Dec 09, 2017 12:57 am
Location: United States

Re: Recipe for hardware-accelerated mpv video player in Raspbian Buster using Raspberry Pi 3 !!!

Sat Jul 13, 2019 2:14 pm

Gadgetguy wrote:
Sat Jul 13, 2019 12:19 pm
RPI_Mike’s attitude..... arrogance..... insecurity..... paranoid Mike

In a demonstration of grace and dignity, I will not take any of your bait.

Return to “Graphics, sound and multimedia”