senten
Posts: 6
Joined: Thu Oct 13, 2016 8:40 pm

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Sun May 13, 2018 2:45 pm

Thanks a lot for this excellent tutorial.

I was curious if this would work also using Ubuntu Mate on the Raspberry Pi 3 B. If anyone else is searching for the answer, I tried it today, it appears it does, at least for HW decoding :)

I followed the steps using Ubuntu Mate 16.04.4. I only checked the HW decoding, I did not follow the steps for HW encoding.

In steps 2 and 12, you can set the GPU memory by opening the /boot/config.txt and searching for "gpu_mem=", setting it there and uncommenting the line, then rebooting.

In step 3, linux-headers-rpi2 was not available, I installed raspberrypi-kernel-headers instead, I'm not sure if this is necessary or not.

Also, for step 14, in associating mpv with various video file types, I did not see an option for "Execute in terminal emulator", and because of this, I didn't get the keyboard control of mpv working yet.

Thanks again. (I'm not asking for any support here, just posting it for anyone looking for information on whether it's worth their while doing it on Ubuntu Mate on the Rpi3)

Using this in combination with acestream-engine and acestream-launcher, I can play 1080p fullscreen video from acestream using mpv. Works perfectly. :)

bloxwichkiwi
Posts: 1
Joined: Fri May 18, 2018 10:50 am

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Fri May 18, 2018 11:04 am

Hi Mike,

Brilliant tutorial. Thanks very much. Must have taken a lot of effort.
I did have a problem though with step 12;

I get this error with wscript modified as suggested;

...
Checking for Android support : no
Checking for Raspberry Pi support : no
You manually enabled the feature 'rpi', but the autodetection check failed.
[email protected]:/FFmpeg_Build/mpv-0.27.0 $

Modifying the last few lines of the section of script to the foillowing.......

lib=['mmal_core', 'mmal_util', 'mmal_vc_client', 'bcm_host']),
# We still need all OpenGL symbols, because the vo_opengl code is
# generic and supports anything from GLES2/OpenGL 2.1 to OpenGL 4 core.
check_cc(lib=["EGL","GLESv2"]),
),

gives...

...
Checking for Android support : no
Checking for Raspberry Pi support : yes
Checking for iOS OpenGL ES hardware decoding interop support : no
Checking for OpenGL without platform-specific code (e.g. for libmpv) : not found any of libmpv-shared, libmpv-static
Checking for MALI via Linux fbdev : no
Checking for OpenGL video outputs : yes
Checking for EGL helper functions : yes
Checking for FFmpeg/Libav present : yes
Checking for libav* is FFmpeg : no
Checking for libav* is Libav : no
Checking for Libav/FFmpeg library versions : not found any of is_ffmpeg, is_libav
Unable to find development files for some of the required FFmpeg/Libav libraries. You need at least FFmpeg 3.2.2 or Libav 12. Aborting.
[email protected]:/FFmpeg_Build/mpv-0.27.0 $

Any idea what I am doing wrong?

Thanks,
Dave.

RPi_Mike
Posts: 69
Joined: Sat Dec 09, 2017 12:57 am
Location: United States

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Sat May 19, 2018 10:25 pm

bloxwichkiwi wrote:
Fri May 18, 2018 11:04 am
[email protected]:/FFmpeg_Build/mpv-0.27.0 $

Checking for Libav/FFmpeg library versions : not found any of is_ffmpeg, is_libav
Unable to find development files for some of the required FFmpeg/Libav libraries. You need at least FFmpeg 3.2.2 or Libav 12. Aborting.

From just one tiny clue, I can tell your system is UNORTHODOX – or totally messed up!

That tiny clue is your command prompt.

On a completely "normal" Raspbian system, your command prompt while inside the mpv build directory should look EXACTLY like this:

[email protected]:~/FFmpeg_Build/mpv-0.27.0 $

If I enter the pwd command in this location on my perfectly normal system, I get this:

/home/pi/FFmpeg_Build/mpv-0.27.0

The pwd command stands for "print working directory" – although conceptually, I prefer to think of it as the "present working directory". It shows the FULL, EXPLICIT PATH that Terminal is currently located in.

But in your case, your command prompt says this:

[email protected]:/FFmpeg_Build/mpv-0.27.0 $

If you compare your command prompt to mine and look very carefully, you'll notice the little squiggly tilde symbol (~) is missing from your path. The tilde symbol acts as an abbreviation for your home directory – which on any "normal" Raspberry system is /home/pi. To the untrained eye, it may be "just a little symbol". But it actually has HUGE implications.

On your system, if you run the pwd command while Terminal is inside the mpv build folder, it will say this:

/FFmpeg_Build/mpv-0.27.0

That means something astounding – you placed the FFmpeg_Build folder at the ROOT level of your system! That means it exists at "/" instead of "/home/pi". This is definitely NOT an acceptable practice. The root has special properties and is intended "for system use only" – it's definitely not a location for you to be placing source code build folders. Among other things, it's not even owned by the user named "pi" – instead, it's owned by the user named "root". As a result, when logged in normally as user "pi", it has completely alien permissions. That means in Step 4 of my tutorial, you would have needed to deviate from my instructions by using "sudo mkdir FFmpeg_Build" instead of "mkdir FFmpeg_Build" to create the folder in the first place! Otherwise, you would have encountered a "permission denied" error message. By using "sudo", that also means the FFmpeg_Build folder would automatically be owned by root, not pi. Given my detailed instructions, my tutorial has every right to assume that folder is owned by pi – yet in your case, it would be owned by root.

Not to sound like a scolding professor, but this alone tells me that at least to some degree, you decided to do things "your own way". Not a good idea – especially when you consider how complicated and utterly unforgiving it is to build MULTIPLE programs from raw source code. And just to cover myself: Maybe you didn't encounter a permissions issue and therefore didn't have to use "sudo". Well, that would be equally messed up – because that would mean you previously made a completely non-standard, fundamental alteration to your root's permissions.

The missing tilde symbol also means you either don't have a normal home directory (which means you "tampered" with your system) – or for some reason, you do have a home directory (perhaps even /home/pi) – but, as already mentioned, you chose to do things your own way and created the build folder right off your root. My instructions clearly say to open Terminal – which, by default, will automatically open inside your home directory (/home/pi) on any standard, unaltered Raspbian system.

As you may have noticed, I repeatedly emphasized throughout my tutorial that your system must be completely "standard" and "normal" – I even defined those terms in great detail.

As if that weren't enough, I can tell something else from your command prompt – your host name is also unorthodox and non-standard.

Your host name is "hollandpi". On a normal system, it should simply be "raspberrypi". I'm not saying there's anything technically "wrong" about that in and of itself. After all, people are free to alter their host names – or do anything else they wish with their Raspberries!

But my point is that these unusual arrangements don't "just happen". They tell me that you're either an advanced user doing advanced things and thereby creating an unorthodox system in the process – or you're mostly just a regular user trying to do "advanced" things without really understanding their implications!

Either way, it spells trouble. It's a clear "violation" of my tutorial's well-defined rules that emphasize normality and standardization – so I'm not at all surprised that you're having problems. Since I'm able to extract all this concerning information from just a single command prompt, it makes me justifiably suspicious about other unknown "tweaks" you've probably made as well.

You also took it upon yourself to experiment with the wscript file. I realize you probably did that only after you encountered problems. But trust me – my version is the only correct one. By altering the script and leaving out SEVERAL critical elements, you were only digging an even deeper hole for yourself. Remember – everything in my tutorial has been thoroughly tested and proven to work. There's no legitimate reason to change ANYTHING!

Finally, be aware that just because your problems MANIFESTED in Step 12 does not necessarily mean that the SOURCE of your problems have anything to do with Step 12! For example, since mpv is totally dependent on my customized build of the FFmpeg engine in Step 11, even the slightest mistake in building FFmpeg can easily result in errors that only manifest later on while building mpv in Step 12. The untrained observer might therefore think "oh gee – what's wrong with mpv?" When in fact, the question itself is not even right!

Then again, FFmpeg might be perfectly fine. In many cases, the primary error you report – "Checking for Libav/FFmpeg library versions : not found any of is_ffmpeg" – can easily be caused by accidentally skipping the "export LIBRARY_PATH=/opt/vc/lib" line in my mpv build instructions. That essential line comes immediately after the wscript editing phase in my procedure – so it's entirely possible that you got distracted by your edits of the wscript file and accidentally skipped over that critical export command. I'm NOT saying that's what happened – your error messages are generic enough that several other possibilities exist.

No matter what your particular circumstances, however, there's really only one big thing to remember – when followed to the letter, my tutorial is proven to work.

BOTTOM LINE: Try a "tactical nuke" on the mpv build folder and see what happens. If that doesn't work, you'll need to do a "strategic nuke" on your entire system! I'm strongly guessing you'll need the latter.

What do I mean by tactical and strategic nukes? See my detailed troubleshooting guide that I wrote for someone else – it explains almost EVERYTHING you need to know. It also covers almost every conceivable mistake and oversight someone could possibly make on my tutorial:

viewtopic.php?f=38&t=199775&start=50#p1281045

johndavies
Posts: 151
Joined: Fri Dec 20, 2013 1:00 pm

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Sun May 20, 2018 6:30 am

I added the following post to the Graphics, Sound and Media Section some time ago. Afterwards begin to think that I should have included it in the excellent TUTORIAL. Accordingly here it is.


Those who have built RPi_Mike's excellent enhanced mpv can use it to play and save some streamed material.To play, type mpv and the URL of the compatible streamed material into a Terminal and press Enter e.g.

Code: Select all

mpv https://abcnews24mha-lh.akamaihd.net/i/[email protected]/master.m3u8

To save material which can be played later you you add an "EXPERIMENTAL" mpv command --record-file="path to your chosen name for the recorded file.ts". An example is

Code: Select all

mpv https://abcnews24mha-lh.akamaihd.net/i/[email protected]/master.m3u8 --record-file="/home/pi/Aussinews.ts"
According to a post on the Reddit site, only .mkv and .ts files can be saved using this "EXPERIMENTAL" command. m3u8 files need to be saved as .ts files while all the others need to be saved as .mkv files The file is saved when the stream comes to an end or when the playback is stopped. I cannot give any more guidance as I know very little about streaming and the iptv world. A site where you can find streamed material to experiment with is https://github.com/notanewbie/LegalStream. You will need to click on most grouped URL file names to open them up to find out single URLs.

geevee
Posts: 1
Joined: Sat Jun 02, 2018 10:56 pm

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Tue Jun 05, 2018 11:52 am

RPi_Mike: You are a saint and a beautiful man, you solved the problem I was experiencing PERFECTLY!

I followed your instructions once and got a perfect result. THANK YOU!

...and for the rest of you ungrateful human waste, you should all be thanking this guy.

-GEVEE

G160
Posts: 11
Joined: Sun Dec 23, 2012 1:32 pm

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Tue Jul 10, 2018 4:41 pm

Thanks for this guide, its really well laid out and easy to follow.

I have one problem though, when using mpv for viewing hls streams, I'm getting quite a lot of buffering, after a bit of googling i discovered that quite a few changes were made to mpv from version 0.28 onwards which address this issue.

Is it possible to use version 0.28 with your method and if so how hard would it be?
I tried following your guide and installing 0.28 instead of 0.27 but i get errors at the step:

Code: Select all

./waf configure --prefix=/usr --enable-rpi
with that version.

Any help is appreciated.
Failing that if anyone knows of any other method/guide to get ffmpeg/mpv(v0.28) working with mmal acceleration, it would also be appreciated.

RPi_Mike
Posts: 69
Joined: Sat Dec 09, 2017 12:57 am
Location: United States

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Wed Jul 11, 2018 6:02 am

G160 wrote:
Tue Jul 10, 2018 4:41 pm
Is it possible to use version 0.28 with your method and if so how hard would it be?
I tried following your guide and installing 0.28 instead of 0.27 but i get errors at the step:

NOTE TO READERS – JUST SO NO ONE GETS SCARED OFF BY MY TUTORIAL: This person chose to step outside my instructions and experiment on his own. There's nothing inherently wrong with that, but it obviously didn't work out too well in this case! My tutorial still works perfectly.

NOTE TO POSTER (G160): It is true that mpv's source code developers have made some improvements in the latest version (0.28). For most people, however, that slightly newer version offers no big advantage. My build (0.27) still works great and meets almost everyone's needs. However, just by coincidence, the one area you mention – HLS-based streaming – did receive a significant improvement. They enhanced the caching, so HLS-related buffering should work better in the newer version.

I therefore understand why you were tempted to build 0.28 – but there's one big catch you overlooked: As the British might say, your decision had unintended "knock-on" effects.

You see, the latest version of mpv also requires the latest version of FFmpeg!

As just one of many examples, mpv 0.28.x requires libavcodec version >= 58.7.100 as indicated here.

But the version of FFmpeg that my tutorial builds (3.4.x) contains libavcodec version 57.107.100 as indicated here.

FFmpeg is the "engine" that mpv uses – so these are absolutely critical dependencies that must be met. If mpv doesn't have EXACTLY what it needs, it simply won't work.

As of this writing – July 11, 2018 – the developers of mpv have not issued a fundamentally new "whole number" version of mpv in 7 months (since mpv 0.28.0 came out on December 24, 2017). Since that's only a few months newer than my build's version, it simply didn't make sense for me to spend hours and hours – or even days – completely re-doing the development, testing and re-writing of the entire tutorial just to update mpv's version by a matter of weeks. This is especially true when you consider that I'm doing all this for free!

However, I do keep my eye on mpv's "latest release" GitHub page. As soon as I see they've issued a fundamentally new version, I will probably do a complete update of my tutorial – assuming (1) I have the time to do all that and (2) I don't encounter an unexpected showstopper. New versions have new code, after all – so who knows what might happen! For all I know, it might not even work on the Raspberry.

Until then, you're free to experiment on your own. First and foremost, of course, you would need to build the latest version of FFmpeg (4.0.x) from raw source code. Also, be aware that if you do wish to experiment, you'll probably have to build the latest version of libass as well, since that's also a critical dependency. And to avoid any weird conflicts before you proceed, you'll also need to do a complete removal of all the packages you previously built. If you're not exactly sure how to do that, your best bet is to "nuke" your entire system with a brand-new install of Raspbian and try all over again from scratch.

Or better yet... just wait for RPi_Mike to set ya straight! :-)

G160
Posts: 11
Joined: Sun Dec 23, 2012 1:32 pm

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Wed Jul 11, 2018 6:30 am

@RPI_Mike
Yes i should clarify, i followed your tutorial to the letter and it worked perfectly, not a single error.
Playing backnormal MKVs,MP4s,etc worked excellently, so do normal internet streams, and weirdly even some HLS streams, just certain ones were buffering so i decided to do a little investigation.

I have mpv installed on my mac, which plays literally everything perfectly, that version installed from brew showed v0.28 so then it all started to become a little clearer.

Thanks for your explanation of the issue, i have a little time today and my raspian was a fresh install, so I'll keep a backup of the .debs created so if my attempts fail then i can just revert to your tried and tested method.

Many thanks again Mike, your work on this IS appreciated by some.

G160
Posts: 11
Joined: Sun Dec 23, 2012 1:32 pm

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Wed Jul 11, 2018 10:21 am

@RPI_Mike
Well that was an experience!
After building the latest libass, ffmpeg and mpv, it all went really smoothly until i attempted to play something when i was greeted with the dreaded 'Segfault' error.

God knows what the problem is, so ive reinstalled the .debs from your guide and im back up and runnning.
Shame i cant really use it for HLS streams as it is, but i'll have to live with it until someone can figure out what the hell is going on.
Cheers anyway.

senten
Posts: 6
Joined: Thu Oct 13, 2016 8:40 pm

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Mon Jul 16, 2018 3:03 pm

@G160, as a possible workaround for playing back HLS streams, I wonder if streamlink would do the job? https://github.com/streamlink/streamlink

After installing it, you could try running

Code: Select all

streamlink <your HLS stream URL> best --player=mpv
Streamlink should take care of the HLS stuff, and pass it to mpv for decoding. (there's also a streamlink setting for using different cache sizes)

Of course this is going way off from RPi_Mike's intentions, and streamlink running in the background doing the HLS streaming business may mean the raspi cannot keep up, but might be worth trying out.

G160
Posts: 11
Joined: Sun Dec 23, 2012 1:32 pm

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Mon Jul 16, 2018 5:18 pm

@senten
Thanks for the idea, i'll give it a go and see how i get on.
Nothing to lose really.

getty23
Posts: 1
Joined: Mon Aug 06, 2018 5:08 am

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Mon Aug 06, 2018 6:09 am

Hello,

I was wondering if anyone has already tried it on Ubuntu Core with a snap?
I try to get MPV running on Ubuntu Core but I am having some trouble (compare: https://forum.snapcraft.io/t/hdmi-outpu ... ay/5858/23).

If you have advices or tricks, just let me know.

Thanks and best regards

sramctc
Posts: 2
Joined: Thu Jun 14, 2018 8:26 am

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Tue Aug 07, 2018 1:21 am

Dear Mike,

I got this error message while building and installing MPV [mpv will not work without libass and FFmpeg] (STEP 12)

vutil >= 55.34.100 libavcodec >= 57.64.100 libavformat >= 57.56.100 libswscale >= 4.2.100 libavfilter >= 6.65.100 libswresample >= 2.3.100' not found)
Unable to find development files for some of the required FFmpeg/Libav libraries. You need at least FFmpeg 3.2.2 or Libav 12. Aborting.

is it normal or not?

Thanks you very much

RPi_Mike
Posts: 69
Joined: Sat Dec 09, 2017 12:57 am
Location: United States

Re: TUTORIAL: Play or Encode High-Quality Video and Audio – with FFmpeg and mpv

Wed Aug 08, 2018 9:52 pm

getty23 wrote:
Mon Aug 06, 2018 6:09 am
I was wondering if anyone has already tried it on Ubuntu Core with a snap? I try to get MPV running on Ubuntu Core but I am having some trouble.

SO LET ME GET THIS STRAIGHT: You're trying to build a very intense video rendering program – mpv — and get it to work on an obscure, stripped-down, bare-bones operating system that's primarily built for IoT applications? And on top of that, you want it to work inside a sandboxed snap? And you want all this to happen on a little $35 Raspberry?

WOW! Unless you're a total genius with access to top-secret equipment that can "see" the tiny electrical impulses deep inside the Broadcom chip – and can use those insights to reverse engineer exactly how it handles video – your chance of pulling all that off is about... ZERO!

Even if you could somehow get mpv "working", it's extremely unlikely that it would ever support GPU-based hardware acceleration like my tutorial does. That means your frame rate for 1080p video would be about 2 SPF. And no – that's not a typo or a measure of sunscreen protection! That's 2 seconds per frame – not 2 frames per second! It reminds me of the 62-metric-ton M1A2 main battle tank. If you asked the guys who drive those things how many miles per gallon it gets, they would just laugh – because the only meaningful question is "how many gallons per mile does it get!" [The answer is almost 2, by the way – 2 gallons per mile!]

As I clearly indicated, my tutorial is designed to work with one specific operating system – the Full Desktop version of Raspbian Stretch, the Raspberry's official OS. The other official Raspberry operating system – the stripped-down "lite" version of Raspbian Stretch – will definitely NOT work.

One individual, however, did report some measure of success with Ubuntu Mate – because its underlying architecture is very similar to the full version of Raspbian. He did it by slightly modifying my tutorial (see post at the top of this page). But Ubuntu Core inside a snap? I would abandon all hope on that one!



sramctc wrote:
Tue Aug 07, 2018 1:21 am
I got this error message while building and installing MPV....... Unable to find development files....... You need at least FFmpeg 3.2.2....... Aborting.

is it normal or not?

SO LET ME GET THIS STRAIGHT: You're asking me if it's "normal" to get a catastrophic error message where the entire build comes to a crashing halt? No, that's definitely not normal! For those who have read my other posts over many months, I'm sure this will sound like a broken record: My tutorial, if followed to the letter, is documented to work perfectly. Tons of posts on here, from people all around the world, have firmly established that basic fact. So that's the giant elephant in the room. In other words, it means it's almost certain that you made a mistake. [Just to cover myself, there's always the very remote possibility that the Raspberry Pi Foundation just issued a Raspbian update a few days ago that somehow broke my tutorial. I would have to re-compile everything from scratch, every single day, to exclude that possibility with mathematical certainty – and I'm obviously not going to do that!]

But just to quickly address the error messages you mention: "Unable to find development files" would suggest that you forgot to install (or improperly installed) some or all of the critical dependencies in Step 3. One person who posted on here months ago, who complained about things not working, later admitted that he was "in a rush" and "probably skipped" that step. I honestly don't know why people even bother with my tutorial if they're not going to take it seriously. I think it's pretty obvious that it's not some casual thing you can do while watching your favorite TV show. It's literally 100% or nothing. 99% won't cut it.

And that message from mpv about you needing "at least FFmpeg 3.2.2"? It's hard not to chuckle on that one – because the whole point of the giant step just before it was to build FFmpeg 3.4.1. And while it's true I'm not a Fields Medalist like Ed Witten, I'm pretty sure that 3.4.1 is greater than 3.2.2. In other words, it means you didn't successfully build FFmpeg in the first place. Without a proper build of FFmpeg, mpv is pure fantasy – because FFmpeg is the "engine" that mpv uses.

Fortunately for you, I previously wrote an extremely detailed troubleshooting guide that covers virtually every single mistake a person could possibly make on my tutorial. As long as you follow my advice, you'll be in good shape. If you're not 100% certain of the current status of your Raspberry in every regard – and I suspect you're not – your best bet is to use my "strategic nuke" method. But check out all my thoughts before you make your final decision:

RPi_Mike's FFmpeg / mpv Troubleshooting Guide

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 9 guests