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

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

Sat Feb 03, 2018 8:05 am

86jumpy wrote:
Fri Feb 02, 2018 9:41 pm
Wow wonderful guide. Compliments. I have performed all the steps and at the moment everything works perfectly.

RPi_Mike: Awesome! And thank you. Nothing like a "third-party validator" to prove that everything in my tutorial works!



1) Once you get the 8 * .deb files, if you want to reinstall mpv what is the exact procedure?

RPi_Mike: Please see Appendices 6 and 7 – they cover everything you need to know. On the remote chance you literally just mean mpv, you would simply change my instructions in the appendices from "sudo dpkg -i *.deb" to "sudo dpkg -i mpv_0.27.0-1_armhf.deb". But keep in mind that mpv requires libass and FFmpeg to work – so in most circumstances, there would be no reason to only install mpv.



2) If in the future I had to run sudo apt-get dist-upgrade, could mpv no longer work as before?

RPi_Mike: As previously explained in my original troubleshooting appendix, you can always re-install the .deb files to resolve an issue like that – it takes less than one minute. However, there is now a cleaner and more elegant solution to prevent that from even happening. Please see my tutorial's newly-created Step 15.



3) Are there any minimum hopes that the procedure will work on Raspberry1 mod B or Raspberry 2 mod B?

RPi_Mike: Please see my tutorial's requirements section. Among other things, it says the following: "I don’t have a Raspberry Pi 2, but since the architecture is very similar, there’s a decent but non-guaranteed chance that my instructions will also work reasonably well on that device. Other versions of the Raspberry will definitely not work." If you want to try it on a Raspberry Pi 2, simply take the .deb files you created on your Raspberry Pi 3 and follow my instructions in Appendix 7. If it works, it works. If it doesn't, just follow my instructions in Appendix 5 to completely uninstall it from the Raspberry Pi 2.

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

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

Sat Feb 03, 2018 8:09 am

rpdom wrote:
Fri Feb 02, 2018 9:50 pm
That's where apt pinning can help. Pin to the specific versions from your .deb files and they won't get updated by the standard ones.

Although my original "re-install the .deb files" method only takes 47 seconds, your pinning suggestion is cleaner and more elegant and prevents that issue from even happening. I have therefore added a brand-new "Step 15" to my tutorial (which includes a hat tip to you). I appreciate your constructive input, rpdom!

treeHouse
Posts: 29
Joined: Sat Aug 06, 2016 2:35 am

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

Sun Feb 04, 2018 12:51 am

Thanks a thousand times over for this tutorial. It has proven useful on so many levels, not just mpv.

I'm now using mpv for windows and mac, as well as various non-RPI linuxes. Also, I discovered a great command line youtube program called mps-youtube that is so light on the RPI that it doesn't even register on the ram and CPU meters!

Also, your tips for encoding video with ffmpeg have bled over to my other platforms as well-- its so nice to break away from the expensive commercial solutions.

An interesting note: The last couple raspbian updates seem to have overwritten my ffmpeg build to 3.2. However, mpv still works just fine, so I haven't bothered with reinstalling the ffmpeg deb. Unless I'm totally wrong about that (these instructions build 3.4.1, right?)

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

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

Mon Feb 05, 2018 12:10 pm

treeHouse wrote:
Sun Feb 04, 2018 12:51 am
Thanks a thousand times over for this tutorial. It has proven useful on so many levels, not just mpv.

RPi_Mike: You're quite welcome. My 10,000-word tutorial obviously took a great deal of time to research, develop, validate, and write – so your positive feedback is very much appreciated!


An interesting note: The last couple raspbian updates seem to have overwritten my ffmpeg build to 3.2.

RPi_Mike: I recently added a Step 15 to my tutorial that prevents update-related overwrites from occurring. So just re-install all 8 .deb files as described in Appendix 6 – it literally takes less than ONE MINUTE! Even if everything appears to be working, do it anyway to make sure you're starting from a clean slate. It only takes a minute, after all – so there's no reason not to do it. Then, proceed to Step 15 and follow my simple instructions. That's it – that's all you have to do to prevent any overwriting from occurring in the future!

However, if you did my tutorial before my big update on January 31, 2018, some of your package names and version numbers will be slightly different from the ones currently listed in my instructions. If that is the case, you would need to change those names and numbers when you do Step 15. Fortunately, it's easy to determine the correct package names: It's everything that appears before the first underscore character in the .deb file names! And determining the correct version numbers is just as easy: It's everything that appears between the 2 underscore characters in the .deb file names! For example, ffmpeg_3.4-1_armhf.deb contains a package named "ffmpeg" with a version number of "3.4-1". And ffmpeg_3.4.1-1_armhf.deb also contains a package named "ffmpeg" – but this time its version number is "3.4.1-1". Likewise, x264_0.152.2851-1_armhf.deb contains a package named "x264" with a version number of "0.152.2851-1". And x264-snapshot-20180125-2245_20180125-1_armhf.deb contains a package named "x264-snapshot-20180125-2245" with a version number of "20180125-1".

Perhaps you noticed the "-1" at the end of all the version numbers and are thinking to yourself "there's no such thing as version 3.4.1-1 of FFmpeg!" Well, you would be right about that – there's no such thing! But none of that matters. The only thing that matters is what Raspbian's package manager thinks it is! Adding the "-1" suffix is a Debian convention — it does that in case there ends up being multiple .deb files with the same name (it can then change the suffix to -2, -3, -4, etc).

A final note to any Raspberry novices out there: Anyone who uses the current version of my tutorial can ignore these retrospective considerations. That's because I've already taken care of everything – all you have to do is copy and paste!

kogumelow
Posts: 2
Joined: Sun Feb 18, 2018 3:36 am

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

Sun Feb 18, 2018 3:44 am

Hello, in first place I would like to thank you for your awesome tutorial, I see you have put a lot of time and effort to help people like me get everything working smoothly.

I am having two problems that I hope you can help me with:

1) I can't seem to make the on screen controler (osc) work. Is it a limitation of this version or am I doing something wrong?

2) When I launch it from streamlink I loose control over the player - It plays well but it doesn't receive ANY commands. (The combination streamlink+mpv works very well on a normal computer).

Thanks again!

kogumelow
Posts: 2
Joined: Sun Feb 18, 2018 3:36 am

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

Sun Feb 18, 2018 8:47 am

Another problem I have been having is a bit of lagging in 1080p60fps videos. It is very occasional but it happens.

Commands make it lag A LOT and drop frames for several seconds before recovering, this happens only when in full screen - if I set the display to just 4 or 16% it stops and commands work fluidly. If I send commands without using OSD, via a lua script, it doesn't make the video lag (or lags MUCH less). Has anyone else been facing similar problems? Are there any fixes?

Thanks again.

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

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

Mon Feb 19, 2018 2:57 pm

kogumelow wrote:
Sun Feb 18, 2018 3:44 am
When I launch it from streamlink I loose control over the player - It plays well but it doesn't receive ANY commands. (The combination streamlink+mpv works very well on a normal computer)....... Another problem I have been having is a bit of lagging in 1080p60fps videos. It is very occasional but it happens....... I can't seem to make the on screen controler (osc) work. Is it a limitation of this version or am I doing something wrong?

Where do I even begin? Perhaps I should start with an analogy:

Your back-to-back posts remind me of someone who just bought a brand-new, perfectly working car.

They bring it home and for some reason, they decide they don't want to use it "directly" – just as you have chosen not to use my build of mpv "directly". Instead, they think it will be more fun if they can modify an old smartphone, install some random "streaming" software they found on the Internet, and connect it to a robotic hand attached to the steering wheel.

Then they start "driving" their brand-new car – from their bedroom by remote control. But the car keeps "lagging" – the stream keeps cutting out at random intervals and the steering wheel keeps slipping. They keep trying to issue "commands" – not really to the car, but through the middleware of their smartphone – but the car doesn't seem to respond to these commands. Then they "lose control" of the car and run over some mailboxes and hit five pedestrians.

Then they set up a free account at the website of the local Ford dealership where they bought the car.

A few minutes later, they start posting about all the "problems" they're having with their new car. They implore the readers: "Has anyone else been facing similar problems? Are there any fixes?" The owner of the dealership is understandably horrified – all he knows is that some guy is on there scaring away all the customers with his talk about the many "problems" he's having with his perfectly working car.

The Raspberry is definitely not a "normal" computer in the way you're thinking. "Normal" computers are measured in units of a THOUSAND U.S. dollars: They cost more than a thousand or a good percentage of a thousand. They are designed to be robust multitasking machines that can run several intensive programs at the same time. The cost of a Raspberry, however, is measured in units of TEN dollars! It's not even apples and oranges – it's apples and orangutans. The whole point of my tutorial is to squeeze every last drop from a tiny computer with limited resources and make it do something amazing: Play full-screen 1080p video without a single dropped frame – even at 60 FPS. My build achieves that goal, and it achieves it flawlessly. By actively running another program simultaneously – and making mpv continuously dependent on it – you're sapping away those precious drops and wondering why your Raspberry slows up a bit. Quite frankly, with everything you're doing, I'm amazed that you're only experiencing "occasional" lagging at 60 FPS 1080p!

Finally, there is no on-screen controller. Everything is done through simple taps on the keyboard. Nothing's missing. This is *NOT* mpv on Windows, Mac, or a Linux box with an Intel or AMD CPU. This is *NOT* mpv using NVIDIA or AMD GPUs. Instead, this is mpv on the Raspberry – a completely alien architecture from anything you've probably experienced before. It's a low-power ARM-based CPU with a GPU based on a proprietary technology called "VideoCore". So no – neither my build nor mpv have any "limitations". It's simply how the Raspberry's video architecture works. Part of the reason why mpv is able to work so well on such a tiny, inexpensive computer is because the video is *NOT* piped in to a bloated, resource-hogging windowed GUI that supports extraneous things like on-screen controllers. Instead, video is fed directly to the screen as an OVERLAY. When it comes to hardware-accelerated video on the Raspberry, that's a feature not a flaw!

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

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

Wed Feb 21, 2018 1:00 pm

Kogumelow wrote:

I am having two problems that I hope you can help me with:

1) I can't seem to make the on screen controler (osc) work. Is it a limitation of this version or am I doing something wrong?

2) When I launch it from streamlink I loose control over the player - It plays well but it doesn't receive ANY commands. (The combination streamlink+mpv works very well on a normal computer).


I sense RPi_Mike does not want me posting again to “his” thread given the tone of more than a little asperity which greeted my previous (admittedly rather bloated ) submissions. However once a thread is opened in a public forum I am not sure that the original poster retains any proprietary right to the discussion. Of course moderators can step in and remove a post if contributions stray too far off-topic..The subject of this thread is ffmpeg and mpv.

One solution to the two problems you refer to above is Smplayer, highly regarded and the most used gui for mpv(and mplayer). Contrary to Mike’s assertions about it being a bloated and useless gui, smplayer is highly efficient consuming less than 1% of cpu and approximately 35mb of memory. It brings much utility to mpv particularly mpv on the pi where the video output is displayed in overlay form which makes an osc (but not the osd) impossible. See this recent post by cjan (a guy who kows his stuff) as to the utility of smplayer on the pi:

viewtopic.php?f=53&t=205966#p1276136

Smplayer can be designated as the player for livestreamer( or its’ fork streamlink ) and you will not lose keyboard control. I too tried to use mpv as the player for livestreamer and like you I lost keyboard control. Perhaps there is a livestreamer (or streamlink)
configuration file that will retain keyboard control of mpv but I wasn’t clever enough to figure it out.
However the following livestreamer configuration works with smplayer(and mpv) as the player:

player=smplayer
player-no-close
player-continuous-http


If you are interested I refer you to my original post at:

viewtopic.php?f=38&t=199775#p1248436

I think if you are interested you might find my tips posted there useful for compiling and configuring smplayer. When you toggle smplayer between fullscreen and a smaller overlay window using the hack I referred to you gain access to all of smplayer’s many controls. Remember you have to compile from source and use the most recent version to take advantage of its’ up to date internal youtube code. About a 20 minute compile.

Ffplay, an integral part of ffmpeg also can work extremely well as the designated video player for livestreamer (streamlink). Unfortunately the version of ffplay that is produced by Mike’s tutorial is not hardware accelerated and is pretty much useless as a video player. That is because starting with the ffmpeg series 3.2 and higher, ffmpeg dropped support for sdl1 and used sdl2 instead. Sdl2 on the pi is not hardware accelerated. For a discussion see::

https://raspberrypi.stackexchange.com/q ... al-support


and:


https://discourse.libsdl.org/t/sdl2-per ... rypi/22992


viewtopic.php?f=78&t=106622



However the ffplay that results from compiling ffmpeg sources prior to the 3.2 series produces an ffplay that is hardware accelerated and makes an excellent and very responsive player for livestreamer capable of playing 1080p livestreams or local files in a non- overlay infinetly resizable window that can be dragged or minimized. It also makes a nice player for smtube. It does use quite a bit more cpu resources than mpv but not so much that you can’t multitask. See:


https://ubuntu-mate.community/t/tutoria ... fplay/3784


I use livestreamer (streamlink) withh ffplay as the player with the following configuration:

player=ffplay -vcodec h264_mmal -threads 4 -infbuf -fast

You can also make a desktop shortcut for ffplay permitting you to drag and drop local files. Control is maintained through keyboard and mouse commands. While as Mike mentions it is intended as a testbed player many do use it as a regular video player. I like how quick and responsive it is.. What I did was compiled a later version of ffmpeg so that I could compile mpv 27.0 (Later versions of mpv require a later version of fmpeg) I then uninstalled the later version of ffmpeg and installed a version of ffmpeg prior to the 3.2 series which I had already compiled into a deb file. The mpv 27 still worked and I had a hardware accelerated ffplay. Not everyone may wish to use this cumbersome procedure but it suits my purposes very well! Perhaps compiling sdl2 from source might give a hardware accelerated version of sdl 2. see:


https://choccyhobnob.com/raspberry-pi/s ... pberry-pi/

http://blog.shahada.abubakar.net/post/h ... spberry-pi

RPi_Mike
Posts: 61
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 Feb 21, 2018 2:46 pm

Gadgetguy wrote:
Wed Feb 21, 2018 1:00 pm
my previous (admittedly rather bloated ) submissions

To the other readers out there:

I've already responded to Gadgetguy twice in GREAT DETAIL and will not be taking his bait anymore.

Just know that many of his technical assertions simply aren't true.

To him and the tiny few who don't appreciate my work, I say this:

SHOW US YOUR FULL-SCREEN 1080p SCREEN SHOTS! SHOW US YOUR 30 AND 60 FPS TESTING RESULTS! SHOW US YOUR STEP-BY-STEP TUTORIAL THAT ACTUALLY WORKS!

usable
Posts: 3
Joined: Fri Mar 02, 2018 10:00 am

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

Fri Mar 02, 2018 10:02 am

Hi. Sorry for my bad english. I cant compile mpv. Here the error:
-------------------------------
[241/241] Linking build/mpv
audio/audio.c.18.o: In function `mp_audio_to_avframe':
/home/pi/FFmpeg_Build/mpv-0.27.0/build/../audio/audio.c:451: undefined reference to `av_mallocz_array'
/home/pi/FFmpeg_Build/mpv-0.27.0/build/../audio/audio.c:454: undefined reference to `av_mallocz_array'
audio/aframe.c.18.o: In function `mp_aframe_pool_allocate':
/home/pi/FFmpeg_Build/mpv-0.27.0/build/../audio/aframe.c:433: undefined reference to `av_mallocz_array'
collect2: error: ld returned 1 exit status

Waf: Leaving directory `/home/pi/FFmpeg_Build/mpv-0.27.0/build'
Build failed
-> task in 'mpv' failed with exit status 1 (run with -v to display more information)

insolito
Posts: 17
Joined: Fri Feb 14, 2014 11:44 pm

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

Sat Mar 03, 2018 4:15 pm

If i need only to play music/video, can i skip steps 5, 6, 7, 8, 9 and install only libass, FFmpeg and mpv? video playing from youtube will work without encoders too?

RPi_Mike
Posts: 61
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

Sun Mar 04, 2018 3:37 pm

insolito wrote:
Sat Mar 03, 2018 4:15 pm
If i need only to play music/video, can i skip steps 5, 6, 7, 8, 9 and install only libass, FFmpeg and mpv? video playing from youtube will work without encoders too?

Yes and yes! You can definitely skip several steps in my tutorial and create a version that "only" plays audio and video. YouTube videos will work just fine without the advanced encoders – as will videos from thousands of other sites too. I have tested and confirmed this.

[You will still have many encoding capabilities, thanks to all the "generic" encoders that come natively with FFmpeg's source code – you just won't have the advanced encoders that the rest of my tutorial provides.]

I have a whole section on this in my tutorial – so please see my instructions that begin like this:

DO YOU MAINLY WANT TO PLAY VIDEOS? ARE YOU NOT INTERESTED IN HAVING ADVANCED ENCODING CAPABILITIES? If so, you can easily modify this tutorial and create a stripped-down "play-centric" version by doing 3 simple things.

RPi_Mike
Posts: 61
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

Sun Mar 04, 2018 5:04 pm

usable wrote:
Fri Mar 02, 2018 10:02 am
Hi. Sorry for my bad english. I cant compile mpv. Here the error:
-------------------------------
[241/241] Linking build/mpv
audio/audio.c.18.o: In function `mp_audio_to_avframe':
/home/pi/FFmpeg_Build/mpv-0.27.0/build/../audio/audio.c:451: undefined reference to `av_mallocz_array'
Waf: Leaving directory `/home/pi/FFmpeg_Build/mpv-0.27.0/build'
Build failed

There are only a few things that could explain your mpv compiling problem.

But first, it's important that we take a step back and consider one overwhelming fact:

My entire tutorial has been thoroughly tested and PROVEN to work. That isn't just my personal claim. If you look through the more than 60 posts on this thread, you will see that numerous people have used my tutorial with no problem whatsoever.

So let me address the possibilities that might explain your error – including a VERY ROUGH probability for each scenario that's based on my personal experience and actual feedback I've received from posters to this thread.

NOTE: I obviously don't know anything about you or what you may or may not have done – so everything I'm about to say is *NOT* directed to you personally. These are general observations for the benefit of all readers:

1: YOU MADE A MISTAKE [60%]: There are more than 80 copy and paste steps in my tutorial. If you accidentally got one of them even slightly wrong – or skipped a step or did any of them out of order – that could easily cause all kinds of weird things to happen. As just one example, the last character in the critical block of text that needs to be replaced in mpv's "wscript" file is a tiny and easily missed comma. My tutorial is quite easy to follow, but it requires 100% attention to detail. 99% simply isn't good enough!

2: YOU CHOSE TO DEVIATE FROM – OR IGNORE – AT LEAST SOME OF MY INSTRUCTIONS [20%]: For example, even though I explicitely said in my requirements section that "lite" versions of Raspbian Stretch will not work, some still went ahead and did my tutorial anyway! Guess what? It didn't work out for them! Other people might decide they've already "updated" their system and can safely skip that step. That turned out to be a big mistake too! Someone else accidentally skipped my critical dependencies step and then wondered why they got tons of error messages when they went to compile. Others might decide to "slightly" change or "update" some of the source code I'm linking to on the theory they can make my instructions "a tiny bit better" – because they noticed that one of the versions was recently updated by the developers from x.x.1 to x.x.2. You might get away with it – but there's a very good chance you won't get away with it due to unintended "knock on" effects! All of the source code in my tutorial consists of "locked-in" tarballs, so it's simply not possible for the source code – which I have tested and validated – to suddenly change and stop working on a random Friday. (And yes, I'm fully aware that nothing is absolutely guaranteed in this universe. For example, some hacker could retroactively tamper with the contents of a finalized tarball weeks after it's been published, thus making my prior statement false. I could come up with many other theoretical exceptions – but you get the idea.)

3: YOUR OPERATING SYSTEM IS DAMAGED OR HAS BEEN ALTERED IN A FUNDAMENTAL WAY THAT PREVENTS MY TUTORIAL FROM WORKING [15%]: Throughout my tutorial, I emphasize how important it is to have a truly STANDARD and completely "normal" and HEALTHY COPY of Raspbian Stretch – and how important it is that everything is running on a completely standard and "normal" Raspberry Pi 3. In Step 2, I went into great detail on this subject – including how dubious I am about systems that have been "upgraded" from Raspbian Jessie to Raspbian Stretch. I also have several important warnings in my requirements section. Maybe you accidentally altered certain system files – or installed software that unknowingly altered or damaged your operating system in unexpected ways.

4: DUE TO A SYSTEM UPDATE, THE RASPBERRY'S OPERATING SYSTEM SUDDENLY CHANGED IN A CRITICAL WAY THAT "BROKE" MY TUTORIAL [4.9%]: The Raspberry Pi Foundation is constantly issuing updates to improve the operating system. In theory, one of these updates could unintentionally "break" my tutorial at any time. For example, they might "upgrade" a key system file that affects the behavior of the GPU in an unexpected way. So far, this has never happened. And at this exact moment, I can say it definitely did not happen. That's because I just tested this possibility an hour ago! I nuked my system, installed a fresh copy of Raspbian Stretch, ran a full system update via "dist-upgrade", and then manually compiled and built libass, FFmpeg and mpv FROM SCRATCH – by following my own tutorial as though I were a total beginner! Everything worked PERFECTLY! Unlike you, I did not get any build errors. This confirms that a system update from 2 or 3 or 10 days ago did *NOT* break my tutorial. In fact, just to prove I'm not making this up, here are the final few lines from the compiler after I successfully built mpv only an hour ago:

[235/241] Compiling video/filter/vf_mirror.c
[236/241] Compiling audio/decode/dec_audio.c
[237/241] Compiling input/cmd_list.c
[238/241] Compiling video/vdpau.c
[239/241] Compiling demux/demux_timeline.c
[240/241] Compiling common/tags.c
[241/241] Linking build/mpv
Waf: Leaving directory `/home/pi/FFmpeg_Build/mpv-0.27.0/build'
'build' finished successfully (2m25.146s)


5: ALL KINDS OF OBSCURE POSSIBILITIES [0.1%]: Maybe there was an error-inducing power surge during the compile process. Maybe there's a manufacturing defect in your Raspberry. Maybe, despite built-in error correction, one of the source code tarballs you downloaded somehow got corrupted in transit. Perhaps one of the high-energy byproducts of a cosmic ray just happened to collide with one of the 40-nanometer transistors in your Raspberry's CPU while it was compiling – thus causing it to flip a bit and corrupt the build. There are many other "unlikely but theoretically possible" scenarios.


So those are the possibilities. Since we know the fault cannot be with my fully validated tutorial, there are only 2 things worth trying:

SMALL NUKE (TACTICAL NUKE):
Since your problem *seems* to be limited to mpv, you should try the easiest troubleshooting step first! That would be the following: Simply "nuke" all the items related to the mpv build. To do that, just delete the "mpv-0.27.0" folder and the "v0.27.0.tar.gz" tarball. Both of them should be located at /home/pi/FFmpeg_Build. Then, simply re-start Step 12 (building mpv) all over again from scratch! When you start over, be *VERY* careful to follow all my instructions perfectly.

BIG NUKE (STRATEGIC NUKE):
Notice I said that your problem *seems* to be limited to mpv. Based on the error you report, we can't really know that for sure. For example, mpv is completely dependent on FFmpeg as its "engine". So even though you apparently did not receive any explicit error messages during the build of FFmpeg, we can't necessarily assume that you didn't make a mistake or encounter some problem with FFmpeg. That could easily result in a "knock on" effect that might only show up when you went to compile mpv – thus creating the false impression that the problem is related to mpv (when in fact it's related to FFmpeg or some other step in my tutorial).

I'm especially concerned about possibilities 1, 2, and 3 that I just explained at the beginning of my post. If you did make a mistake at some unknown point in my tutorial – or accidentally skipped or overlooked or chose to do something different at some unknown point – it could be essentially impossible to ever figure out what the true source of the problem is.

Likewise, if your operating system is fundamentally altered or damaged in some unknown way, that could also result in an endless wild goose chase!

So here's the bottom line: If the "small nuke" method doesn't resolve your problem, there's only one realistic option left: You need to back up all your personal data to a safe place, NUKE your entire system, and start my entire tutorial all over again from scratch! If you have NOOBS on your SD card, just boot up your system and tap the SHIFT key to nuke everything and start from a clean slate. Before you do any of this, make sure you have the ability to make a brand-new SD card with Raspbian Stretch on it – by having access to a second working computer with Internet access, for example. Otherwise, you could end up with an unbootable Raspberry – at least until you can get your hands on a new, bootable SD card.

usable
Posts: 3
Joined: Fri Mar 02, 2018 10:00 am

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

Tue Mar 06, 2018 8:45 pm

WOW, so huge reply! Thank you for your attention! I guess it's because i use lite version. Ill try to reinstall full version and start from the very begining. Thank you again!

usable
Posts: 3
Joined: Fri Mar 02, 2018 10:00 am

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

Tue Mar 06, 2018 11:50 pm

ok i did it. everything is perfect. thank you again for your manual :D
p.s. i just checked 1080p 30fps vp9 action video with mpv --ytdl-format.... JUST 7 dropped frames! OMG! vp9 performance is soooo awesome!

emersok
Posts: 5
Joined: Sat Mar 10, 2018 4:17 pm

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

Fri Mar 16, 2018 12:16 pm

A brilliant and comprehensive tutorial!
As far as I can tell ffmpeg and mpv are installed and working. I've tested mpv from the terminal on AVI and MP4 files and also youtube videos. I've also created an MP4 video from a series of PNG images using ffmpeg which also plays correctly using mpv
My problem is running commands from a Python programme on the Raspberry Pi.
Specifically I am capturing timelapse images and then creating a video which I wish to play.

I have a set images and if I enter the following into the raspi terminal I get a video which I can play using mpv.

ffmpeg -framerate 25 -pattern_type glob -i "*.png" -vf format=yuv420p -c:v libx264 -crf 23 output.MP4 (largely as per your appendix)

Inside the Python programme I have tried various options such as subprocess.call, Popen, os.system but to no avail. (probably because I don't really know what I'm doing!!!) e.g

----------------------------------------------
import os
import sys
import subprocess
from subprocess import call
from subprocess import Popen


subprocess.call (['ffmpeg -framerate 25 -pattern_type glob -i "*.png" -vf format=yuv420p -c:v libx264 -crf 23 output.MP4'], shell =True)
-----------------------------------------------------
I've tried the above substituting some of the other commands I've mentioned with various combinations of adding or not adding shell=True etc but in most cases I don't get an error but no video file produced?
I've searched the web and tried various ideas but no luck. Any help would be much appreciated

RPi_Mike
Posts: 61
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

Sun Mar 18, 2018 5:29 am

emersok wrote:
Fri Mar 16, 2018 12:16 pm
A brilliant and comprehensive tutorial!

As far as I can tell ffmpeg and mpv are installed and working. I've tested mpv from the terminal on AVI and MP4 files and also youtube videos. I've also created an MP4 video from a series of PNG images using ffmpeg which also plays correctly using mpv

RPi_Mike: Glad to hear my "brilliant and comprehensive" tutorial worked well for you!


My problem is running commands from a Python programme on the Raspberry Pi....... Specifically I am capturing timelapse images and then creating a video which I wish to play....... but in most cases I don't get an error but no video file produced?

RPi_Mike: This part is definitely off-topic! With surprising regularity, people keep posting questions on my tutorial's thread that deal with "ALIEN" code or "EXTERNAL" programs. They then try to get them to interact with my build of mpv or FFmpeg and wonder why it won't do what they imagine in their minds. They then ask me for a solution to "the problem" – even though it has nothing to do with any aspect of my perfectly working tutorial. In this case, you're asking me about the behavior of the Python programming language and why you can't get it to interact with my build of FFmpeg.

Someone else might ask me about the behavior of other programming languages – like Java or C or C++. For all I know, someone might even try to simulate the Raspberry's entire circuit board inside a virtual machine on a supercomputer – and then ask me why they keep having "problems" when they try to get some other program or code to interact with my build of mpv or FFmpeg inside the supercomputer!

Some may think I'm needlessly truculent about these recurrent posts – but I honestly feel that I'm perfectly capturing the essence of these questions! I'm especially concerned with inexperienced users who might read about all these so-called "problems" and wrongly think "wow – RPi_Mike did a lousy job! Better steer clear of his bogus tutorial!"

Nonetheless, you got me curious about your off-topic question. Your Python script doesn't work because of the way Python interprets the spaces in the command line you're using. As a result, you need to place each part of the FFmpeg command line within single quote marks – with each part separated by a comma and a single space (instead of the entire command line being inserted as one long string). Also, be sure to pay attention to the details. You don't need to invoke "shell" in your code, but I noticed that you wrote it 2 different ways – as "shell =True" and "shell=True". One has a space and the other doesn't. Computers are utterly merciless and demand 100% precision – so if you're going to write scripts, you simply can't make mistakes like that.

Here is the correct version of the Python code you want. I just wrote it myself and confirmed that it works. Test it yourself by creating a standard text file called script.py – then execute it in Terminal by entering "python script.py" (without the quotes). Make sure Terminal is open inside whatever folder contains your PNG image file sequence before you run the script. When it's done executing, an MP4 video will automatically appear inside the same folder! Here's the code – these 3 lines are all you need:

#!/usr/bin/python

import subprocess

subprocess.call(['ffmpeg', '-framerate', '25', '-pattern_type', 'glob', '-i', "*.png", '-vf', 'format=yuv420p', '-c:v', 'libx264', '-crf', '23', 'output.MP4'])

emersok
Posts: 5
Joined: Sat Mar 10, 2018 4:17 pm

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

Sun Mar 18, 2018 10:47 am

Thanks for the response, your code works perfectly.
I have to admit that just after posting my previous reply that I did get the command working (by trial and error) but your code gives me a much better understanding of how to get subprocess calls formatted correctly. This is a great help.
A final note. I am of an age where I take pleasure from the occasional bout of "truculence" or "grumpiness" (particularly if I am right!). I've done my fair share of wading through on-line tutorials but only a small proportion are fully comprehensive, accurate and high-light the pitfalls likely to be encountered, particularly by the inexperienced. Your tutorial falls into the latter category. I'm sure that in many cases the questions directed to you are driven totally by sheer frustration/desperation at not having the knowledge to get something to work rather than any implication that the "problem" lies with your tutorial.
Provided the information gives me the answer I'm seeking then I can certainly put up with the occasional pointed response, in fact I rather enjoy reading them! Thanks again and keep writing the superb tutorials

jl9
Posts: 4
Joined: Sun Mar 18, 2018 3:59 pm

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

Sun Mar 18, 2018 4:43 pm

Hi m80s, at step 10 i find this error

Code: Select all

/FFmpeg_Build $ 
pi@raspberrypi:~/FFmpeg_Build $ cd ffmpeg-3.4.1
pi@raspberrypi:~/FFmpeg_Build/ffmpeg-3.4.1 $ ./configure --prefix=/usr --enable-gpl --enable-nonfree --enable-static --enable-libx264 --enable-libfdk-aac --enable-libvpx --enable-libopus --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-omx --enable-omx-rpi --enable-mmal --enable-libxcb --enable-libfreetype --enable-libass --enable-gnutls --disable-opencl --extra-cflags="-march=armv8-a+crc -mfpu=neon-fp-armv8 -mtune=cortex-a53"
ERROR: libfdk_aac not found

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
I don't want to encode, just play. Is this serious? What did I do wrong?

Thanks

RPi_Mike
Posts: 61
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

Sun Mar 18, 2018 6:57 pm

jl9 wrote:
Sun Mar 18, 2018 4:43 pm
Hi m80s, at step 10 i find this error....... ERROR: libfdk_aac not found....... I don't want to encode, just play. Is this serious? What did I do wrong?

What you did wrong is very simple – you didn't follow my instructions!

I know this because you didn't remove any of the 5 advanced encoders from FFmpeg's "./configure" line. That means you skipped "ITEM B" in my very clear instructions under the section that says (in all caps and bold): "DO YOU MAINLY WANT TO PLAY VIDEOS? ARE YOU NOT INTERESTED IN HAVING ADVANCED ENCODING CAPABILITIES?"

Here's what "ITEM B" told you to do – a direct quote from my tutorial:

ITEM B: Carefully – VERY CAREFULLY – remove the 5 advanced encoder items from the "./configure" line in Step 11 (FFmpeg):

--enable-libx264 --enable-libfdk-aac --enable-libvpx --enable-libopus --enable-libmp3lame


By not removing those items, you're telling FFmpeg to enable encoders that don't exist – so of course that's going to give you an error message! Since you want to "just play" videos with mpv, there's nothing wrong with skipping steps 5 through 9 as you probably did – but you still have to follow the rest of my instructions perfectly. Even if you never use FFmpeg directly, it acts as mpv's "engine" – so both programs are equally critical.

Also, you say the "error" occured at Step 10 when in fact it occurred at Step 11.

Step 10, Step 11... Item B, Item Z... I suppose to some, it's all the same difference.

If you want to have the slightest hope of making it all the way through my tutorial, you'll need to take things much more seriously.

Given what I've already seen of your efforts in this brief snapshot, it's likely that you've made other mistakes as well. So it would probably be a good idea to completely delete the entire FFmpeg_Build folder and start my tutorial all over again from scratch – except this time, PAY ATTENTION and read everything carefully! This is one activity where details matter.

99% isn't good enough. It's 100% or nothing!

emersok
Posts: 5
Joined: Sat Mar 10, 2018 4:17 pm

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

Fri Mar 23, 2018 3:46 pm

Hi,
I am using ffmpeg to produce an MP4 video from a series of time-lapse images of the form
image-0.jpg, imag-1.jpg etc (NB no padding or leading zeroes)

Thanks to your assistance the following works fine

USBstick = "PIUSB"
video_name = "TL3"
still_filepath = "/media/pi/"+ USBstick + "/timelapse/stills/"
video_filepath = "/media/pi/" + USBstick + "/timelapse/video/" + video_name + ".mp4"

(loop in here which creates the sequentially numbered image files and saves them)

subprocess.call(['ffmpeg','-framerate','25','-pattern_type','glob','-i', still_filepath + '*.jpg','-vf','format=yuv420p','-c:v','libx264','-crf','23', video_filepath])

On closer examination I see that the video file is taking some of the images out of sequence when the number of images exceeds 10. My impression is that it is starting at image-10 then getting the images correctly up to image-19 then using image-1 then image-20, image 21 and so forth.

I believe (from reading your notes) that the pattern_type','glob','-i', still_filepath + '*.jpg instruction is related to an alpha numeric sequence? I've tried various combinations of instructions including the use of %d but can't get it working and it does not result in a video file being created.

Any help would be appreciated

jl9
Posts: 4
Joined: Sun Mar 18, 2018 3:59 pm

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

Fri Mar 23, 2018 5:38 pm

RPi_Mike wrote:
Sun Mar 18, 2018 6:57 pm
jl9 wrote:
Sun Mar 18, 2018 4:43 pm
Hi m80s, at step 10 i find this error....... ERROR: libfdk_aac not found....... I don't want to encode, just play. Is this serious? What did I do wrong?

What you did wrong is very simple – you didn't follow my instructions!
Hi thank you for replying and supporting. I did try to follow your indications, because of that I copied the post into the notepad but skipped all the previous steps I already did, with the intro and notes and everything.

The thing is that when I thougth everything was gonna work properly, I found the following error in step 14 (this time is really the 14)

Code: Select all

[lavf] Using subtitle charset: UTF-8-BROKEN
 (+) Video --vid=1 (mpeg4 608x352 23.976fps)
 (+) Audio --aid=1 (mp3 2ch 48000Hz)
 (+) Subs  --sid=1 '2005 - Žižek!.srt' (subrip) (external)
AO: [alsa] 48000Hz stereo 2ch s16
VO: [rpi] 608x352 yuv420p
libEGL warning: DRI2: failed to authenticate
[vo/rpi] Could not create EGL surface!
[vo/rpi] EGL/GLES initialization for OSD renderer failed.
Could not initialize video chain.
Video: no video
Audio and subtitles do work, but no video. Do you know what did I miss? Perhaps it's because I have a more recent version of Raspbian?

BTW, i suppose it's normal I only have 4 .deb files in FFMpeg_build folder, the other 4 being for encoding I suppose.

Thank you for your time.

emersok
Posts: 5
Joined: Sat Mar 10, 2018 4:17 pm

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

Fri Mar 23, 2018 6:07 pm

As per before ....
Just after I'd posted my question re not playing files in sequence I changed my code so that had 0's padding the image file index numbers. I also replaced the "-" in my image file names with "_" so my files are now of the form image_00001.jpg etc
I checked in the raspberry file terminal using echo image_*.jpg and the files are now listed out in the correct numerical order. The mp4 video also plays correctly.

RPi_Mike
Posts: 61
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

Sun Mar 25, 2018 6:04 pm

jl9 wrote:
Fri Mar 23, 2018 5:38 pm
I did try to follow your indications, because of that I copied the post into the notepad but skipped all the previous steps I already did, with the intro and notes and everything.

The thing is that when I thougth everything was gonna work properly, I found the following error in step 14 (this time is really the 14)

I don't know what to tell you dude.

I don't enjoy being critical – but sometimes IT IS WHAT IT IS. This is now your second post with MULTIPLE INDICATIONS that you're simply not following my instructions. You're probably following them to the best of your ability and you might be achieving 95% success. But as I explained earlier, that simply isn't good enough. When it comes to computers – especially an intense activity like building programs from raw source code – it's 100% or nothing.

Last time, you didn't even know what step you were on in my tutorial. This time, you say you "only have 4 .deb files". Well if you skipped the 5 advanced encoders, you should only have 3 .deb files! My full tutorial only builds 8 programs. 3 + 5 = 8. You should only have .deb files for libass, FFmpeg, and mpv. That alone tells me you're making FUNDAMENTAL mistakes.

I also see that mpv was forced to revert to a "broken" version of UTF-8. UTF is the fundamental character encoding standard recognized by almost all modern computers in the world – including the Raspberry.

You also report EGL and GLES errors. Generally, that would be caused by not running the 4 "wget" lines at the beginning of Step 12 (building mpv). Those 4 lines download critical EGL and GLES files to your system.

Not only do I suspect that you haven't followed my instructions, I also suspect that your entire operating system is messed up as well – especially since you're getting weird UTF errors.

My best advice at this point is to simply NUKE YOUR ENTIRE SYSTEM and then re-install the Raspbian operating system from scratch (make sure it's the FULL version and not the LITE version). Then, start my tutorial all over again from scratch! Be sure, of course, to backup your data before you do any of that – and make sure you have either a second bootable SD card or a working computer that will allow you to create a bootable SD card.

Another poster ignored ONE item in my entire tutorial – that alone was enough to prevent the whole thing from working.

Please read my advise to him – it covers virtually EVERY POSSIBLE REASON why you can't get things to work:

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

Raspberry_Dan
Posts: 1
Joined: Sun Apr 15, 2018 10:21 pm

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

Sun Apr 15, 2018 10:52 pm

Dear RPi_Mike, Outstanding work, second to none! I´ve read almost, well many blogs related to raspicam and streaming video from the RPi. I´ve tried several solutions, none completely met my needs. I decided to use FFmpeg for encoding and then serving local and public via a browser. ( I´m rethinking the that now) , and found your FFmpeg post. EXCELLENT post!!! I learnt as much from your post as I did from all my research and solutions
I´ve tried. I created my account on rasberrypi.org simply so I could say ¨THANK YOU!!¨ Keep up the great work! I´m going to reread this post and decide how best to ask my questions, most likely a new thread, or maybe an existing thread. We´ll see. Thanks again!!

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 7 guests