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

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

Tue Dec 12, 2017 4:20 pm

WITH THIS TUTORIAL and a Raspberry Pi 3, you can play or encode almost any video or audio – from the last century's most obscure formats to the very latest in high definition. In fact, this tutorial creates a system so muscular, it will play 1080p video at a whopping 60 frames per second. I will show you, step-by-step, how to build customized versions of FFmpeg and mpv that feature powerful GPU-based hardware acceleration, full-screen display, and extensive encoder, decoder and filter support. I have also included detailed benchmarks that reveal the Raspberry's outstanding video performance when its GPU is fully utilized. Finally, I wrote ten separate appendices with tons of useful information, including how to use mpv and FFmpeg – and how to acquire the highest-quality videos from hundreds of websites with a downloading tool known as youtube-dl. At more than 16,000 words, this is the most comprehensive media-related tutorial on the Raspberry Pi.

UPDATE – JANUARY 2018: Although my tutorial has worked perfectly from the very beginning, a small but vocal minority objected to my use of the developmental "firmware" code provided by the rpi-update command. That choice was not dictated by me – it was dictated by essential GPU-related files that are missing in the Raspberry's stock firmware. Although no one reported an issue with this command, I conducted an exhaustive binary compare of the stock and developmental firmware codes – more than 4,000 files in total. Through this effort, I identified 4 tiny files that completely eliminate the need for rpi-update!
NASA.jpg
NASA.jpg (225.96 KiB) Viewed 10534 times
This 1920 x 1080 screenshot was taken directly from my Raspberry. Captured from a 60 frame-per-second 1080p video, this supercomputer simulation of colliding neutron stars demonstrates the power of this tutorial. Full-screen mode in mpv is always "pure video" with no distractions – but for informational purposes, I have superimposed the small Terminal window in the upper-left corner to show the video's flawless statistics (including no dropped frames). Quite simply, the FFmpeg / mpv combination can handle almost anything you throw at it! To view this image at full resolution, right-click and select "open image in new tab" – or on phones and tablets, “tap and hold” and save it to your pictures for full-size viewing. NOTE: NASA chose TV-based frame rates rather than monitor-based frame rates, which explains the fractional 59.940 frame rate.

DUAL TECHNOLOGIES: FFmpeg and the mpv media player are the two most fundamental video and audio tools in the Raspberry Pi universe. This is equally true in the larger open source and Linux multiverse. On the content-creation and encoding side, nothing beats the power and flexibility of FFmpeg. And on the content-consumption side, nothing beats mpv. Simply put, if you’re a Raspberry Pi user and want to share video or audio with anyone in the world, you need FFmpeg to encode it. And if you want to enjoy high-quality video and audio with a truly capable media player, you need mpv to decode and play it. The two work hand-in-hand – FFmpeg is the “engine” that mpv uses to render video and audio. But having just any version of these programs is NOT sufficient. Instead, both programs must fully support hardware acceleration via the Raspberry’s GPU – using the MMAL API to decode, and the OpenMAX API to encode. There’s only one way to do all that and my tutorial tells you how.

METHOD: My instructions use source code to build the latest versions of FFmpeg and the mpv media player – with all necessary Raspberry-specific tweaks. Building from source code may sound complicated, but it’s the only viable way to experience multimedia nirvana on a Raspberry Pi. Fortunately, this tutorial is written in an accessible manner that spells everything out. It can be followed by almost anyone with a basic understanding of Linux.

REQUIREMENTS: This tutorial will work on any standard Raspberry Pi 3! All you need is the completely free Raspbian Stretch operating system (initially released on August 17, 2017). If you just got a Raspberry kit, there's a chance the pre-made SD card still has Raspbian Jessie on it – that's the previous generation of Raspbian and it will not work with this tutorial. You can always download the latest version of NOOBS from this website and make a brand-new SD card with Raspbian Stretch on it. Also, "lite" versions of Raspbian will not work either. Finally, advanced users should know that mpv will not work with the experimental desktop GL drivers (via raspi-config). The bottom line is actually very modest and simple – all you need is the current version of the Raspberry Pi's standard operating system. That's it! 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.

WHAT, SPECIFICALLY, WILL THIS TUTORIAL GIVE YOU? This tutorial will enable your Raspberry Pi 3 to play almost any audio or video on any HDMI-capable TV or monitor – in full screen mode – at all resolutions up to 1920 x 1080. It will even pump out an astonishing 60 frames per second of high-definition 1080p video (MP4 / H.264) without dropping a single frame. It will also let you encode audio and video into almost any format – including MP4 and WebM. It will let you encode MP4 videos with the most universally-playable codec pair (H.264 for the video track and AAC for the audio track). It will also let you encode WebM videos with the most advanced compression technology currently available (VP9 for the video track and Opus for the audio track). You will also be able to choose high-quality, software-based H.264 encoding – or much faster hardware-accelerated H.264 encoding. Finally, my instructions will create freestanding Debian software packages that will allow you to quickly install or re-install everything you need, in just a couple minutes, on any Raspberry Pi 3. That means these instructions, though a bit involved, are a one-time thing. Once you’ve done it, you’re good to go.

FULLY TESTED AND PROVEN TO WORK: This is not your typical tutorial. If you look for information on hardware-accelerated mpv on the Raspberry Pi, you will find tantalizing bits and pieces on the Internet – most wrong, some right. But nowhere in the entire Googleverse will you find a complete procedure that actually works. All of the existing documentation is generic and utterly useless in dealing with the Raspberry’s unique CPU and GPU architecture. But I was determined to transform my Pi into a truly capable multimedia machine – so I personally struggled with this, off and on, for several weeks and experienced great frustration. That is why I decided to make this contribution to the Raspberry community instead of keeping it to myself. I tried to write this tutorial in a clear, explicit way that does not “assume knowledge” or skip even the slightest step. I also took the time to fully test and validate my procedure on a clean install of Raspbian Stretch – the Raspberry Pi’s latest operating system. Of course, all operating systems are subject to change at any point in the future – but at the time of this writing, I can confidently say that every aspect of this tutorial works!

WHY SO COMPLICATED? In a perfect world, you would simply go to the FFmpeg and mpv official websites and download “the Raspberry Pi version” – then double-click the files and relax as they automatically install. Unfortunately, no such thing exists! You will see Linux versions, but they only run on Intel and AMD-based systems – not the ARM-based architecture that the Raspberry uses. You will also find the raw “source code” for each program – but that’s of no use unless you’re a sophisticated user. And even if you are quite advanced, you’ll almost certainly get tripped-up – because there are a whole series of insanely obscure and undocumented Raspberry-specific issues that must be overcome. Or wouldn’t it be nice if you could just type “sudo apt-get install mpv” and have everything work? For reasons I explain below, that won’t work either.

DETAILS & BACKGROUND: Versions of FFmpeg and mpv are available in the Raspbian software repository. In fact, they are now the “official” encoder and media player of the Debian Stretch distribution of Linux, upon which Raspbian Stretch is based. Unfortunately, due to a perfectly legitimate desire to maintain backward compatibility with older Raspberry models, the repository – accessed via “sudo apt-get install” – only provides a generic build of mpv (and an older version of FFmpeg). As a result, mpv is unable to take advantage of hardware acceleration, and therefore does not leverage the Raspberry’s surprisingly powerful on-board GPU to play video. Instead, all video is rendered “in software” by the CPU. Because of this, videos bigger than 240p will drop frames and “stutter”. The stuttering gets so bad that at 1080p, the frame rate drops to 0.5 – half a frame per second! That's 60 times too slow for standard 30 FPS video.

Some might point to OMXPlayer as a potential solution. It is, after all, the Raspberry’s only “official” media player with hardware acceleration support. But the playing options and keyboard controls offered by this aging player are severely limited. More importantly, the other leading video format – the more advanced and newer WebM (VP9) – is simply not supported by OMXPlayer. This is not trivial, given that YouTube – the world’s biggest provider of video – only supports two major video formats: WebM (VP9) and MP4 (H.264). In the near future, when the next-generation open source AV1 codec is released, having access to a state-of-the-art media player will be even more crucial.

The other leading potential contender – the generally well-regarded VLC media player – is only available in a generic "stock" version without GPU-based hardware acceleration (unless of course you have the sophistication to compile from source code; or take the risk of downloading a pre-compiled binary from a questionable website). But even with GPU support, its WebM video capabilities are limited and high-resolution MP4s are subject to frequent frame drops. This state of affairs could theoretically change at any time, of course – but my VLC testing results are what they are.

And what if you need to encode a video in the ONLY modern format that works on every major browser and media player? That “universal” format is of course an MP4. But keep in mind that an MP4 is merely a “container” and file extension. What really matters is what’s on the “inside” – the actual codecs used to encode the video and audio. On the video side, the only universal choice is H.264 (sometimes referred to as AVC or AVC1). That can be done with the open source “x264” codec – which is included in my instructions. And on the audio side, the best universal choice (and MP3 successor) is AAC – specifically, the excellent Fraunhofer implementation of AAC (Advanced Audio Codec). That is also included in my instructions. My tutorial provides the very latest versions of these encoding technologies.

And what if you wish to encode a WebM video with the more advanced VP9 (video) and Opus (audio) codecs? My tutorial does that too.

Finally, what if you wish to take advantage of hardware-accelerated H.264 encoding on the Raspberry? For those of you that follow my instructions, you will gain access to the “h264_omx” hardware encoder. This leverages the Raspberry’s GPU to encode H.264 video, resulting in a roughly three-fold speed-up in encoding time (versus the software-based, but higher-quality, x264 codec).



---------
TESTING RESULTS: As the saying goes, "I ate my own dog food". That means I pretended to be a complete novice and robotically followed every step in my tutorial without any assumed knowledge. All my testing was conducted on a standard Raspberry Pi 3 with a clean, brand-new installation of the standard operating system (Raspbian Stretch). My results? Everything worked perfectly! Quite frankly, I was astonished by the performance of such a small and inexpensive computer. With the customized versions of FFmpeg and mpv that my tutorial provides, the Raspberry really shines. In fact, it can fully render high-definition video at 60 frames per second! That’s FULL COLOR, FULL SCREEN, ZERO DROPPED FRAMES and TRUE HIGH-DEFINITION – 1920 x 1080.

Most video you'll encounter is encoded at 24, 25 or 30 frames per second, but some are available at 60 FPS. As long as the video is encoded with the extremely common H.264 codec (referred to by YouTube's servers as "avc1"), the Raspberry can play an MP4 video at 60 frames per second – pumping out more than 124 MILLION full-color pixels every second without skipping a beat! Frame rates this high are especially nice for high-motion video with lots of fast movement, as it greatly reduces motion blur. The Raspberry can do this because its GPU is specifically optimized for H.264 at the hardware level. For more details on how to acquire high-quality video, please see Appendix 2 toward the bottom of this document.

Here are my other testing results – for both mpv (decoding/playing video) and FFmpeg (encoding video). All frame rates are 30 FPS:


---------
MPV: BENCHMARK RESULTS FOR MY SOURCE-BUILT VERSION ON THE RASPBERRY PI 3:

PLAYING HIGH-COMPLEXITY VIDEO – 1920 X 1080 – 30 FPS – FULL SCREEN – SIGNIFICANT MOTION AND INTRAFRAME DETAIL:

MP4 video (H.264 video / AAC audio): 0.0% dropped frames (perfect)

WebM video (VP9 video / Opus audio): 2.5% dropped frames (almost perfect)



PLAYING MID-COMPLEXITY VIDEO – 1920 X 1080 – 30 FPS – FULL SCREEN – LESS MOTION:

MP4 video (H.264 video / AAC audio): 0.0% dropped frames (perfect)

WebM video (VP9 video / Opus audio): 0.2% dropped frames (virtually perfect)



PLAYING HIGH-COMPLEXITY VIDEO – 1280 X 720 – 30 FPS – FULL SCREEN – SIGNIFICANT MOTION AND INTRAFRAME DETAIL:

MP4 video (H.264 video / AAC audio): 0.0% dropped frames (perfect)

WebM video (VP9 video / Opus audio): 0.0% dropped frames (perfect)



---------
FFMPEG: BENCHMARK RESULTS FOR MY SOURCE-BUILT VERSION ON THE RASPBERRY PI 3:

ENCODING HIGH-COMPLEXITY 30 FPS VIDEO FROM A 1920 X 1080 JPEG IMAGE SEQUENCE – SIGNIFICANT MOTION AND INTRAFRAME DETAIL – HIGH QUALITY SETTINGS:

Software-Based H.264 Encoding (CPU): 2.3 FPS (13 times slower than real time)

Hardware-Based H.264 Encoding (GPU): 6.3 FPS (4.8 times slower than real time)



ENCODING HIGH-COMPLEXITY 30 FPS VIDEO FROM A 640 X 480 JPEG IMAGE SEQUENCE – SIGNIFICANT MOTION AND INTRAFRAME DETAIL – HIGH QUALITY SETTINGS:

Software-Based H.264 Encoding (CPU): 16 FPS (1.9 times slower than real time)

Hardware-Based H.264 Encoding (GPU): 38 FPS (1.3 times FASTER than real time)




---------
INSTRUCTIONS: Here, finally, are my instructions. The following 15 steps use raw source code to “build” and install the most robust versions possible of FFmpeg and mpv on your Raspberry Pi 3. In Step 11, it will take about 25 minutes for your system to compile FFmpeg’s source code with the “make -j4” command. This is by far the most computationally intensive step in my procedure. By using the “-j4” option, all 4 cores in the Raspberry’s CPU will be placed at full-throttle – so your CPU will run at 100% capacity. A compile time of 25 minutes is actually quite impressive when you consider that over one million lines of FFmpeg code are being compiled on a $35 computer!


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 these 3 simple things:

ITEM A: Skip steps 5, 6, 7, 8, 9. In other words, you would not build and install the 5 advanced encoders. All other steps, however, must be fully done. To spell it out explicitly, that means you would do steps 1, 2, 3, 4, 10, 11, 12, 13, 14, 15.

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

ITEM C: Since you would only be installing FFmpeg, mpv, and libass, you would only "pin" those 3 programs in Step 15.


CRITICAL TIP: Copy and paste these instructions into the Text Editor (located under Accessories) and save them! Other than Terminal and the Text Editor, you should not have any programs running when you follow these instructions – especially not the resource-heavy web browser. You need all system resources devoted to this task! To avoid making mistakes or accidentally skipping steps, position the Terminal window on the left side of your screen and the Text Editor (with these instructions) on the right side of your screen. That way, it will be super easy to copy the command lines, one at a time, and paste them into Terminal.

MAKE THIS TUTORIAL MUCH EASIER: Terminal's default settings don't support the standard keyboard shortcuts for copy and paste. To get through my tutorial much faster and avoid mistakes – and view a sample layout that shows the best way to follow my instructions – please visit my brief tutorial on this subject: TERMINAL: The Two Most Useful Customizations

WHAT IF I MAKE A MISTAKE OR HAVE A PROBLEM? Think of each program (steps 5 to 12) as a separate "module". If the compiling suddenly stops with a big error message or if one of the programs don't work, there's a good chance you made a copy & paste mistake or accidentally skipped a step! The first thing you should try if weird problems like that occur is to simply delete that individual program's "build" folder (they are all located inside FFmpeg_Build at /home/pi/FFmpeg_Build) and just start that individual program's entire procedure all over again from sratch!

IMPORTANT NOTE ON CHECKINSTALL: Several of these steps invoke the extremely useful “checkinstall” command. It installs the compiled program *AND* creates a freestanding Debian software package (.deb). A .deb file is a great thing to have, because it lets you install an entire program in just a matter of seconds! That way, you won’t have to re-do this tutorial in the future – an especially good thing if you ever want to use these programs on another Raspberry (or if you ever re-install the operating system on your existing Raspberry).

WARNING #1: Compiling source code is very intense and will push your CPU to its limits for a prolonged period of time. If you do not have adequate heat dissipation, your Raspberry is very likely to overheat to above 80° Celsius (176° Fahrenheit) and will throttle-back, lock-up or crash – or even worse, it might quietly corrupt your code in random ways without you even knowing. Then you might get stuck with inexplicable behavior that will be impossible to troubleshoot. So it’s worth getting a small 40mm fan that attaches to your Raspberry’s case, along with copper heatsinks for the 3 main chips. If you don’t have those simple add-ons, you can hang your Raspberry (by the rugged HDMI cable) in front of a standard house fan. That should “blow away” enough heat to keep your Raspberry cool enough to get through the compiling step.

KNOW YOUR CPU's TEMPERATURE: When you're doing heavy compiling, you definitely don't want to fly blind – at least not until you have a decent idea of your Raspberry's thermal behavior. So monitor your CPU temperature by doing this: Right-click the Task Bar and click Add / Remove Panel Items. Then click the Add button; scroll down and double-click "Temperature Monitor"; then click the Close button. With just a tiny 40mm fan and small heat sinks, my Pi3 never exceeds 60° Celsius – but definitely try to keep it under 70°.

WARNING #2: For experienced users, what I'm about to say is just common sense. But it's still important to emphasize: ANYTHING you do with a computer could cause you to lose all your data. And ANYTHING you do with a computer could cause your operating system to become unbootable. In fact, the simple act of turning on your computer could do either of these things. For example, you could get hit with a random power surge before you even start this tutorial! There is no specific risk associated with my tutorial – but I still wish to include these 2 items of general advice:

1: BACKUP YOUR DATA: Always keep a backup copy of any data you would not want to lose. That includes your personal files, documents and pictures. You can easily copy and paste your data to a USB thumb drive (or any other storage device). Once you've made the backup, DO NOT leave it physically attached to your system. Instead, put it away in a safe place!

2: BACKUP YOUR OPERATING SYSTEM: Always keep a second working copy of your operating system. Otherwise, if something goes wrong, your Raspberry could temporarily become a useless "brick" – at least until you can get your hands on another SD card with a working operating system! Making a backup copy of your operating system only takes 10 minutes. HERE'S HOW: First, reboot your computer to make sure everything is "fresh". After it comes back up, give it a couple minutes to fully "settle down". Then take a second SD card, place it in a USB SD card adapter, and plug it into your Raspberry. If any windows appear, close them! Then click the Raspberry Menu | Accessories | SD Card Copier. When the SD Card Copier window appears, do nothing for a full minute (I have personally found this pause to be critical for everything to work properly – at least for the current version of Raspbian). Once you've done that, click the "Copy From Device" drop-down box and select your INTERNAL SD card (typically, it will have a name like "mmcblk0"). Then click the "Copy To Device" drop-down box and select your EXTERNAL SD card (the one you just put in the USB adapter). Then check the "New Partition UUIDs" box and click Start. After only 10 minutes or so, you will have a brand-new working copy of your operating system! Put it away in a safe place and you can breath easy!



---------
STEP 1: FULLY UPDATE YOUR OPERATING SYSTEM:


***Open Terminal:

NOTE: Copy the following line, paste it into Terminal, and hit the Enter key. From now on, I will assume you know that each command line or stanza is to be dealt with in the same manner:

sudo apt-get update

NOTE: When the following command asks if you want to continue, press "y" and hit Enter. If the screen goes blank after 10 minutes of keyboard inactivity, you can *CAREFULLY* tap the SHIFT key to reawaken the display:

sudo apt-get dist-upgrade

***Close Terminal


***REBOOT!!






STEP 2: TEMPORARILY SET YOUR RASPBERRY’S GPU MEMORY ALLOCATION TO 32 MB:


***STOP!


BEFORE WE PROCEED, LET'S MAKE SURE YOU REALLY HAVE A COMPLETELY "NORMAL", TRULY STANDARD, AND FULLY UPDATED VERSION OF THE RASPBIAN STRETCH OPERATING SYSTEM! I AM ESPECIALLY DUBIOUS OF SYSTEMS THAT HAVE BEEN "UPGRADED" FROM RASPBIAN JESSIE TO RASPBIAN STRETCH (AS OPPOSED TO A COMPLETELY CLEAN INSTALL, FROM SCRATCH, ON A BLANK SD CARD). THIS ISN'T JUST MY OPINION – IT'S THE OPINION OF THE RASPBERRY PI FOUNDATION IN THEIR OFFICIAL RELEASE STATEMENT. AND I QUOTE: "AS THIS IS A MAJOR VERSION UPGRADE, WE RECOMMEND USING A CLEAN IMAGE; THESE ARE AVAILABLE FROM THE DOWNLOADS PAGE ON OUR SITE AS USUAL. UPGRADING AN EXISTING JESSIE IMAGE IS POSSIBLE, BUT IS NOT GUARANTEED TO WORK IN EVERY CIRCUMSTANCE."


NOW, INTERROGATE YOUR SYSTEM WITH THE FOLLOWING COMMAND:


lsb_release -a


YOU SHOULD NOW SEE THE FOLLOWING OUTPUT:

No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.4 (stretch)
Release: 9.4
Codename: stretch


IF YOUR RESULTS DIVERGE EVEN SLIGHTLY FROM THE ABOVE OUTPUT, PLEASE STOP USING THIS TUTORIAL – UNLESS OF COURSE YOU LIVE IN THE FUTURE AND THE VERSION NUMBER HAS SINCE MOVED TO 9.5 OR GREATER. EVEN THEN, THERE ARE NO GUARANTEES – I OBVIOUSLY HAVE NO CONTROL OVER THE BEHAVIOR OF FUTURE OPERATING SYSTEMS! ALSO, IF IT SAYS "9.4" BUT DOES NOT EXPLICITLY SAY "stretch", PLEASE ABANDON THIS TUTORIAL AND CAREFULLY REVIEW MY "REQUIREMENTS" SECTION AND WHAT I JUST SAID ABOUT JESSIE. EVEN IF YOUR RESULTS PRECISELY MATCH THE ABOVE OUTPUT, BE ON NOTICE THAT YOUR SUCCESS IS STILL QUESTIONABLE IF YOU HAVE MERELY "UPGRADED" FROM JESSIE. ON TOP OF THAT, EVEN IF YOU SUPERFICIALLY MEET ALL THE REQUIREMENTS I'M DESCRIBING HERE, YOUR SUCCESS IS STILL QUESTIONABLE IF YOU'VE BEEN "TINKERING" WITH YOUR RASPBERRY – MODIFYING SYSTEM FILES, CHANGING FUNDAMENTAL SYSTEM SETTINGS, OR "EXPERIMENTING" WITH OTHER MEDIA PLAYERS. IF THAT'S THE BACKGROUND OF YOUR RASPBERRY – ESPECIALLY IF YOU'RE NOT A TOTAL EXPERT – IT'S PROBABLY A GOOD IDEA TO START WITH A COMPLETELY CLEAN INSTALL OF YOUR OPERATING SYSTEM IF YOU WANT THIS TUTORIAL TO GO OFF WITHOUT A HITCH!


NOW, IF YOU'RE SURE YOUR RASPBERRY PI 3 IS COMPLETELY "NORMAL" AND MEETS ALL THE ABOVE REQUIREMENTS, YOU MAY PROCEED WITH THE GPU MEMORY ALLOCATION:


Click the Raspberry Menu | Preferences | Raspberry Pi Configuration | Performance Tab

Change "GPU Memory" to 32 (The default is 64, but that is too large for our current purposes; we will increase it later on.)

Click OK | Click No to reboot (You’ll be rebooting soon anyway – so rebooting now is not necessary.)

NOTE: This is a temporary setting to maximize the memory resources available to your CPU (not your GPU). This is especially important for compiling – a computationally intense process that will occur later in this tutorial.






STEP 3: INSTALL DEPENDENCIES – STANDARD SOFTWARE PACKAGES FROM THE OFFICIAL RASPBIAN REPOSITORY [The programs in this tutorial cannot be compiled and built without them]:


***Open Terminal:

NOTE: The following stanza will take ABOUT 5 minutes to complete – paste the entire block of text into Terminal. It will download only 48 MB of files (or less, depending on what you may already have on your system). For important commentary on this step, please see Appendix 9 – "Technical Notes and Observations":

sudo apt-get install automake checkinstall libsdl2-dev libva-dev libluajit-5.1-dev libtool libvdpau-dev libxcb-shm0-dev texinfo libfontconfig1-dev libfribidi-dev python-docutils libbluray-dev libjpeg-dev libtheora-dev libvorbis-dev libgnutls28-dev linux-headers-rpi2 libomxil-bellagio-dev

***Close Terminal


***REBOOT!!






STEP 4: CREATE YOUR SOURCE CODE BUILD FOLDER:


***Open Terminal:

mkdir FFmpeg_Build

NOTE: Run the following command – even if you are not intending to build the LAME MP3 encoder. It is critical for Checkinstall to work:

sudo mkdir -p /usr/share/doc/lame

***Close Terminal






STEP 5: BUILD AND INSTALL THE H.264 VIDEO ENCODER – x264:


***Open Terminal:

cd FFmpeg_Build

wget https://download.videolan.org/x264/snapshots/x264-snapshot-20180125-2245-stable.tar.bz2

tar jxvf x264-snapshot-20180125-2245-stable.tar.bz2

cd x264-snapshot-20180125-2245-stable

./configure --prefix=/usr --enable-shared --disable-opencl --extra-cflags="-march=armv8-a+crc -mfpu=neon-fp-armv8 -mtune=cortex-a53"

NOTE: The following command (make -j4) will compile the source code. It will only take ABOUT 90 seconds. If you see a "warning" about an "array subscript" during this process, do not be concerned:

make -j4

CRITICAL NOTE: In the following line, the checkinstall command will ask you a few important questions. First, it will ask if you wish to create a default set of package docs – enter "y" for yes. Then it will ask you to write a description for the package. Enter "x264" (no quotes) and then tap the Enter key a second time. It will then list a menu with several options. Enter "3" to choose the "Version" option. Then enter the following version number (checkinstall requires a numerical value for the version or it will fail to create a Debian package): 20180125

sudo checkinstall make install

sudo ldconfig

***Close Terminal






STEP 6: BUILD AND INSTALL THE FRAUNHOFER AAC AUDIO ENCODER – fdk-aac:


***Open Terminal:

cd FFmpeg_Build

wget https://downloads.sourceforge.net/opencore-amr/fdk-aac-0.1.5.tar.gz

tar xzvf fdk-aac-0.1.5.tar.gz

cd fdk-aac-0.1.5

./autogen.sh

./configure --prefix=/usr --enable-shared

NOTE: The following command (make -j4) takes ABOUT 3 minutes to complete:

make -j4

NOTE: FOR THE FOLLOWING CHECKINSTALL COMMAND, PROVIDE THESE INPUTS: y, AAC-FDK [version # will be autodetected]:

sudo checkinstall make install

sudo ldconfig

***Close Terminal






STEP 7: BUILD AND INSTALL THE VP9 VIDEO ENCODER – libvpx:


***Open Terminal:

cd FFmpeg_Build

wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.6.1.tar.bz2

tar jxvf libvpx-1.6.1.tar.bz2

cd libvpx-1.6.1

./configure --prefix=/usr --enable-shared --disable-examples --disable-unit-tests --enable-vp9-highbitdepth

NOTE: The next command will take ABOUT 3 minutes to complete; if you see some warnings about a variable, do not be concerned:

make -j4

NOTE: FOR THE FOLLOWING CHECKINSTALL COMMAND, PROVIDE THESE INPUTS: y, VP9 [version # will be autodetected]:

sudo checkinstall make install

sudo ldconfig

***Close Terminal






STEP 8: BUILD AND INSTALL THE OPUS AUDIO ENCODER – opus:


***Open Terminal:

cd FFmpeg_Build

wget https://archive.mozilla.org/pub/opus/opus-1.2.1.tar.gz

tar xzvf opus-1.2.1.tar.gz

cd opus-1.2.1

./configure --prefix=/usr --enable-shared

NOTE: The following command will take less than 2 minutes:

make -j4

NOTE: FOR THE FOLLOWING CHECKINSTALL COMMAND, PROVIDE THESE INPUTS: y, Opus [version # will be autodetected]:

sudo checkinstall make install

sudo ldconfig

***Close Terminal






STEP 9: BUILD AND INSTALL THE MP3 AUDIO ENCODER (LAME) – lame:


***Open Terminal:

cd FFmpeg_Build

wget https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz

tar xzvf lame-3.100.tar.gz

cd lame-3.100

./configure --prefix=/usr --enable-shared

make -j4

NOTE: FOR THE FOLLOWING CHECKINSTALL COMMAND, PROVIDE THESE INPUTS: y, MP3-LAME [version # will be autodetected]:

sudo checkinstall make install

sudo ldconfig

***Close Terminal






STEP 10: BUILD AND INSTALL THE SUBTITLE RENDERER – libass [mpv will not work without libass]:


***Open Terminal:

cd FFmpeg_Build

wget https://github.com/libass/libass/releases/download/0.13.7/libass-0.13.7.tar.gz

tar zxvf libass-0.13.7.tar.gz

cd libass-0.13.7

./configure --prefix=/usr --enable-shared

make -j4

NOTE: FOR THE FOLLOWING CHECKINSTALL COMMAND, PROVIDE THESE INPUTS: y, libass [version # will be autodetected]:

sudo checkinstall make install

sudo ldconfig

***Close Terminal


***REBOOT!!






STEP 11: BUILD AND INSTALL FFmpeg [mpv will not work without FFmpeg]:


***Open Terminal:

cd FFmpeg_Build

wget https://www.ffmpeg.org/releases/ffmpeg-3.4.1.tar.bz2

tar jxvf ffmpeg-3.4.1.tar.bz2

cd ffmpeg-3.4.1

NOTE: The following stanza will appear to freeze for more than a minute – that behavior is normal:

./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"

CRITICAL NOTE: The following line (make -j4) will compile more than one million lines of source code. It will take ABOUT 25 minutes. This will push your CPU to its limits, so make sure your Raspberry has adequate heat dissipation. See WARNING #1 at the beginning of these instructions for more detail. Just be patient and let it compile without interference. Disregard the frequent purplish-colored "warnings" about "deprecated" items – those are perfectly normal messages. In the unlikely event that your Raspberry locks up or crashes during this step – due to overheating or general system strain – you can try changing the "-j4" to "-j2". By using only 2 of the CPU's 4 cores, you will lower memory usage and heat. This will reduce the overall strain on your system at the expense of roughly doubling the compile time (theoretically increasing to as much as 50 minutes). If your system did lock up or crash, data corruption may have occurred. In such a scenario, you should completely delete the "ffmpeg-3.4.1" folder and re-do this entire section (Step 11) from scratch – preferably with much better cooling! Finally, while the source code is compiling, if the Raspberry's built-in idle settings cause your screen to go blank after 10 minutes of keyboard inactivity, you can *CAREFULLY* tap the SHIFT key to wake your screen back up.

make -j4

NOTE: FOR THE FOLLOWING CHECKINSTALL COMMAND, PROVIDE THESE INPUTS: y, FFmpeg [version # will be autodetected; it will take about 7 minutes for FFmpeg to install]:

sudo checkinstall make install

sudo ldconfig

***Close Terminal


***REBOOT!!






STEP 12: BUILD AND INSTALL MPV [mpv will not work without libass and FFmpeg]:


***Open Terminal:

NOTE: The following 4 lines install OpenGL ES (GLES) and EGL files from the official Raspberry GitHub site. These GPU-related files are essential for mpv:

sudo wget -P /opt/vc/lib https://github.com/raspberrypi/firmware/raw/master/hardfp/opt/vc/lib/libEGL.so

sudo wget -P /opt/vc/lib https://github.com/raspberrypi/firmware/raw/master/hardfp/opt/vc/lib/libGLESv2.so

sudo wget -P /opt/vc/lib/pkgconfig https://github.com/raspberrypi/firmware/raw/master/hardfp/opt/vc/lib/pkgconfig/egl.pc

sudo wget -P /opt/vc/lib/pkgconfig https://github.com/raspberrypi/firmware/raw/master/hardfp/opt/vc/lib/pkgconfig/glesv2.pc



cd FFmpeg_Build

wget https://github.com/mpv-player/mpv/archive/v0.27.0.tar.gz

tar zxvf v0.27.0.tar.gz

cd mpv-0.27.0

./bootstrap.py



***STOP! YOU MUST NOW EDIT THE "wscript" FILE INSIDE THE mpv-0.27.0 FOLDER (located at /home/pi/FFmpeg_Build/mpv-0.27.0). USING FILE MANAGER, RIGHT-CLICK THE "wscript" FILE AND THEN CLICK “Text Editor”. THEN CLICK SEARCH | FIND AND DO A TEXT SEARCH FOR "Raspberry" (no quotes) – don't forget the "p" in Raspberry! ABOUT 70% DOWN THE PAGE, YOU WILL SEE THE FOLLOWING BLOCK OF TEXT. SIMPLY REPLACE IT WITH THE 2ND BLOCK OF TEXT BELOW IT AND SAVE THE FILE. BE EXTREMELY CAREFUL IN THIS STEP – JUST ONE TINY MISTAKE AND MPV WILL NOT WORK. BE SURE TO INCLUDE THE TINY COMMA AT THE END OF THE TEXT BLOCK! IF YOU MAKE A MISTAKE, COMPLETELY DELETE THE mpv-0.27.0 FOLDER AND START ALL OVER AGAIN WITH A BRAND NEW TERMINAL WINDOW AND THE ABOVE "cd FFmpeg_Build" LINE. NOW, CAREFULLY PROCEED AS FOLLOWS:


--------------------------------SELECT THIS BLOCK OF TEXT:
'name': '--rpi',
'desc': 'Raspberry Pi support',
'func': compose_checks(
check_cc(cflags="-isystem/opt/vc/include/ "+
"-isystem/opt/vc/include/interface/vcos/pthreads " +
"-isystem/opt/vc/include/interface/vmcs_host/linux " +
"-fgnu89-inline",
linkflags="-L/opt/vc/lib",
header_name="bcm_host.h",
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"),
check_cc(lib="GLESv2"),
-------------------------------------------------------------


--------------------------------AND CAREFULLY REPLACE IT WITH THIS:
'name': '--rpi',
'desc': 'Raspberry Pi support',
'func': compose_checks(
check_cc(cflags="-isystem/opt/vc/include/ "+
"-isystem/opt/vc/include/interface/vcos/pthreads " +
"-isystem/opt/vc/include/interface/vmcs_host/linux " +
"-fgnu89-inline",
linkflags="-L/opt/vc/lib",
header_name="bcm_host.h",
lib=['mmal_core', 'mmal_util', 'mmal_vc_client', 'bcm_host', 'vchostif']),
# 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(linkflags="-lbrcmGLESv2", lib="EGL"),
check_cc(lib="GLESv2"),
-----------------------------------------------------------------



WHEN YOU ARE DONE EDITING THE wscript FILE AND HAVE SAVED IT, CONTINUE WITH THE FOLLOWING STEPS:



export LIBRARY_PATH=/opt/vc/lib

export PKG_CONFIG_PATH=/opt/vc/lib/pkgconfig

export CPATH=/opt/vc/include

NOTE: When you run the following line, you will see several items that variously say yes / no / enabled / disabled / not found, etc. All of that is normal – many of them are for other systems that have nothing to do with the Raspberry:

./waf configure --prefix=/usr --enable-rpi

NOTE: The following line will compile mpv. It will only take ABOUT 2 minutes. You will see various warnings about deprecations and "VCCOREVER" not being defined – all of that is normal:

./waf build -j4

NOTE: FOR THE FOLLOWING CHECKINSTALL COMMAND, PROVIDE THESE INPUTS: y, mpv [version # will be autodetected; it will take about 1 minute for mpv to install]:

sudo checkinstall ./waf install

sudo ldconfig



WE WILL NOW CREATE MPV'S CONFIGURATION FILE (mpv.conf):

sudo mkdir -p /home/pi/.config/mpv

sudo nano /home/pi/.config/mpv/mpv.conf

WHEN THE NANO EDITOR APPEARS INSIDE TERMINAL, COPY AND PASTE THE FOLLOWING 2 LINES INTO THE EMPTY FILE:


--fullscreen
rpi-background=yes


SAVE THE FILE: PRESS "CTRL + X" TO EXIT OUT OF NANO – THEN TAP "Y" FOR YES – THEN TAP THE ENTER KEY TO ACCEPT THE CHANGE.

NOTE: As you may have noticed, "sudo" was used when we created the mpv.conf parent folder and file. That was done to guarantee that no permissions issues would be encountered. As a result, however, they will now be "owned" by the super user known as "root". Run the following command to change the owner of the parent folder and file to "pi" so that you can quickly edit the mpv.conf file at any time in the future without being told "permission denied" or "can't open file":

sudo chown -R pi:pi /home/pi/.config/mpv

***Close Terminal



WE MUST NOW INCREASE THE RASPBERRY’S GPU MEMORY ALLOCATION TO 128 MB (mpv requires 128 MB to work):

Click the Raspberry Menu | Preferences | Raspberry Pi Configuration | Performance Tab

Change "GPU Memory" from 32 to 128

Click OK

Click YES TO REBOOT!!






STEP 13: BACK UP ALL THE .DEB FILES YOU WORKED SO HARD TO CREATE! THESE ARE FREESTANDING DEBIAN SOFTWARE PACKAGES. AT ANY TIME IN THE FUTURE, THEY WILL LET YOU QUICKLY INSTALL OR RE-INSTALL EVERYTHING YOU DID IN THIS TUTORIAL – IN ONLY ONE MINUTE!


Using File Manager, open the “FFmpeg_Build” folder. Then click Tools | Find Files

In the “File Name Patterns” box, enter “*.deb” (no quote marks – but be sure to include the asterisk and period). Make sure the "Search in sub directories" box is CHECKED and that the "Use regular expression" box is *NOT* checked. Also, make sure nothing has been previously entered or checked under the File Type, Content, and Properties tabs (these settings tend to be "sticky" from prior use and can easily trick you into thinking things are not there when they really are). Once you've verified all that, click the Find button. If you did everything properly, it will find exactly 8 files ending in “.deb”. Simply copy and paste those files to a separate storage device for safe keeping – like a USB thumb drive, hard drive, etc. Appendices 6 and 7 show you how to use the .deb files to quickly install or re-install all 8 programs.






STEP 14: CREATE A PROPER “OPEN WITH” BEHAVIOR ON YOUR RASPBERRY SO THAT YOU CAN QUICKLY OPEN ANY VIDEO OR AUDIO FILE BY SIMPLY DOUBLE-CLICKING IT WITHIN FILE MANAGER:


The mpv media player may (or may not) have already installed an mpv file association in File Manager. This is most likely to occur if you've experimented with other versions of mpv prior to using my tutorial. So if you right-click a media file, you may already see an item for mpv – such as “mpv Media Player”. Do NOT use this – it’s not optimized for our purposes. Among other things, it may cause you to lose “keyboard control” of a video while it’s playing – which is especially problematic if it’s a full-screen video (there will be no way to exit until the video finishes). To avoid all that, you need to create your own custom “Open With” association. The following steps are a one-time process – once you create the file association, mpv will automatically play the video (or audio) any time you double-click it:


1: Right-click any media file whose file type you wish to associate with mpv – such as a video ending in ".mp4"

2: Click “Open With...”

3: Click the “Custom Command Line” tab

4: In the “Command line to execute" box, type “mpv %f” (all lower-case, no quotes)

5: Check “Execute in terminal emulator”

6: Check “Keep terminal window open after command execution”

7: In the “Application name” box, type “MPV” (no quotes)

8: Check “Set selected application as default action for this file type”

9: Click the OK button (and then tap the "q" key to quit when the media file starts playing)

10: Repeat this process for any other file type you wish to associate with mpv – such as .webm, .mov, .mkv, .avi, .wmv, .mpg, .mpeg, .3gp, .ts, .wav, .mp3, .m4a, .opus, etc. Mpv is so versatile, you can even associate it with animated GIFs. From then on, you can simply double-click any of these files and mpv will automatically play them!


IMPORTANT: Be sure that all Terminal windows are closed before you double-click a media file. If you fail to do that, you will probably lose keyboard control of mpv. Mpv uses its own instance of Terminal in order to operate, so having another Terminal window open will confuse it. This is especially problematic if you're watching a video in full-screen mode – because then you will have no way to recover control or even quit out of the video. You will then have to wait until the video finishes on its own before you regain control. But as long as you follow this simple guidance, this problem will never occur.






STEP 15: PIN THE ADVANCED VERSIONS OF THE PROGRAMS YOU JUST CREATED:

NOTE: "Pinning" will prevent your system from inappropriately "upgrading" the advanced programs that my tutorial just created. Otherwise, the Advanced Package Tool (APT) may attempt to overwrite them with the generic versions in the Raspbian repository when you run a system update via "sudo apt-get upgrade" or "sudo apt-get dist-upgrade". Hat tip to "rpdom" for his pinning suggestion!


***Open Terminal:

sudo nano /etc/apt/preferences

WHEN THE NANO EDITOR APPEARS INSIDE TERMINAL, COPY AND PASTE THE FOLLOWING 8 STANZAS INTO THE FILE (OR JUST THE FIRST 3 STANZAS IF YOU DIDN'T BUILD THE 5 ADVANCED ENCODERS):


Package: ffmpeg
Pin: version 3.4.1-1
Pin-Priority: 1001

Package: mpv
Pin: version 0.27.0-1
Pin-Priority: 1001

Package: libass
Pin: version 0.13.7-1
Pin-Priority: 1001

Package: x264-snapshot-20180125-2245
Pin: version 20180125-1
Pin-Priority: 1001

Package: fdk-aac
Pin: version 0.1.5-1
Pin-Priority: 1001

Package: libvpx
Pin: version 1.6.1-1
Pin-Priority: 1001

Package: opus
Pin: version 1.2.1-1
Pin-Priority: 1001

Package: lame
Pin: version 3.100-1
Pin-Priority: 1001


SAVE THE FILE: PRESS "CTRL + X" TO EXIT OUT OF NANO – THEN TAP "Y" FOR YES – THEN TAP THE ENTER KEY TO ACCEPT THE CHANGE.

***Close Terminal






---------
APPENDIX 1: MOST ESSENTIAL MPV KEYBOARD CONTROLS AND OPTIONS:


f key: Toggle the video between full screen and actual size

space bar: Toggle the video (or audio) between pause and play

left and right arrow keys: Rewind and fast-forward by 6 seconds

up and down arrow keys: Rewind and fast-forward by 1 minute

9 and 0 keys: Lower and raise the volume

o key: Make the on-screen display briefly appear to show time remaining, etc.

[ and ] keys: Speed up or slow down the video

q key: Quit out of the video (or audio)


REMINDER: Be sure to close any open Terminal windows before you use mpv, or you will lose keyboard control.


CUSTOMIZE MPV's BEHAVIOR: If you wish to customize things further, you can always modify mpv's configuration file (mpv.conf). The mpv.conf file is a standard text file (but with a ".conf" extension) that can be quickly modified with the standard Text Editor. It's located at /home/pi/.config/mpv (you may have to temporarily click View | Show Hidden in order to see these hidden files and folders in File Manager). In my instructions, I already included 2 of the most useful customizations inside the mpv.conf file:

--fullscreen <---This forces all videos, both large and small, to automatically expand to fill your screen. To prevent any distortion, this option always maintains the native aspect ratio of the video. By design, it will never "stretch" or "squeeze" the video to fit the shape of your monitor or TV. But as long as the video's aspect ratio matches the aspect ratio of your screen, the video will completely and perfectly FILL the screen. For example, if you have a 480p, 720p or 1080p video (all of which would normally have a 16:9 aspect ratio) – and you also have a monitor or TV with a 16:9 aspect ratio – then your entire screen will be filled with active pixels.

rpi-background=yes <---Sometimes, you may watch an old video – or one that's simply not as "wide" as a 16:9 aspect ratio. For example, you might have an old video from a VHS tape with a low resolution of 320 x 240 (a 4:3 aspect ratio). Or you might have a DVD video with a resolution of 720 x 480 (a 3:2 aspect ratio). Either way, these videos are not "wide" enough to perfectly fit the shape of a modern 16:9 display without being stretched or distorted. In those cases, the "rpi-background=yes" option will automatically add black bars to the left and right sides of your screen so that there are no visual distractions in the background!

--loop <---I did NOT add this option in my instructions because many people would not want this particular behavior. But if you're using your Raspberry to power a display at a trade show or other event, for example, this is a great way to make the video automatically play over and over again.

geometry=20%+0+0 <---This mpv.conf line will force a 1080p video to play at only 4% of the total surface area of a 1080p monitor or TV – and it will place it in the upper-left corner of your screen. NOTE: In case you're wondering how 20% becomes 4%, it all comes down to understanding the difference between linear dimensions and surface dimensions. Assuming the native resolution of the video is the same as your screen's resolution, 20% smaller across the X axis AND 20% smaller across the Y axis means the video would only cover 4% of your screen's total surface area (20% x 20% = 4%).

geometry=20%+1536+0 <---And what if I want a tiny video to appear in the upper-right corner of my screen? For this mpv.conf example, simple math is in order: My 1080p monitor is 1920 pixels across. 20% of 1920 is 384. And 1920 - 384 = 1536. That means the upper-left corner of the video should start at 1536 on the X axis and 0 on the Y axis. In both of these examples, tapping the "f" key will instantly toggle the video back and forth between FULL SCREEN and TINY SCREEN. Mpv handles it beautifully in the blink of an eye.

TAKE MANUAL CONTROL OF MPV: The contents of the mpv.conf file affects mpv's "fundamental" behavior. In other words, it will always affect the way mpv behaves when it plays video and audio. But for some options, you can temporarily invoke a behavior on a one-time basis without modifying your mpv.conf file. Generally, this only works for options that begin with 2 dashes (--). For example, let's say you do NOT have the "--loop" option in your mpv.conf file, but you still want to launch a video with that behavior on a one-time basis. To do that, you can manually launch the video inside Terminal (instead of double-clicking it in File Manager as you would normally do). Here are some common syntax examples for manual launching of multimedia files:

EXAMPLE A: This is the MANUAL way to play a video with mpv. Normally, as I just mentioned, you would simply double-click the file and it would automatically start playing – but I'm including these manual examples for the benefit of interested users. In this example, we are NOT invoking any special options (other than what's already in your mpv.conf file). It also assumes that Terminal is currently open inside the same folder as your video:

mpv video.mp4


EXAMPLE B: This manually instructs the video to loop continuously (in addition to whatever else your mpv.conf file may have it do). It also assumes that Terminal is currently open inside the same folder as your video:

mpv --loop video.mp4


EXAMPLE C: This does the same thing as Example B, but it does so for a video that's in a completely different folder than the one Terminal is currently located in (which is normally your "home" folder by default – /home/pi). In other words, in this example, you're using the FULL DIRECT PATH to the video. The full path to a file can be easily obtained by right-clicking any file in File Manager and selecting "Copy Path(s)". This syntax is necessary whenever Terminal and the video are in different locations:

mpv --loop /home/pi/vacations/hawaii/video.mp4


EXAMPLE D: This also does the same thing as Example B, but it places the full path inside standard quote marks. Why is this important? You must do this any time there are SPACES in the file path. That's a Linux thing, not a mpv thing. For example:

mpv --loop "/home/pi/truly awesome vacations/hawaii/video.mp4"


MPV HAS HUNDREDS OF OTHER OPTIONS AND FEATURES: For complete details, please review the extremely thorough manual at mpv's official website.






---------
APPENDIX 2: DOWNLOAD AND RETAIN HIGH-QUALITY VIDEOS FROM HUNDREDS OF WEBSITES – WITH YOUTUBE-DL:

INSTALLING YOUTUBE-DL: Although youtube-dl is available in the Raspbian software repository, it’s nearly a year old. To acquire the very latest version from youtube-dl's official website, enter the following two command lines, one at a time, in the Terminal window:

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl

sudo chmod a+rx /usr/local/bin/youtube-dl



DOWNLOADING MP4 VIDEOS (H.264 / AAC): Let’s say you have your Raspberry hooked up to a high-definition 1920 x 1080 monitor or TV and you wish to download and enjoy a NASA video, at maximum resolution and quality, of two neutron stars colliding – with the screen completely filled-up by the video. Here’s how you do that with youtube-dl:

STEP 1: Identify the URL of the page that contains the video you want. In this example, it’s a YouTube video at the following URL:

https://www.youtube.com/watch?v=x_Akn8fUBeQ


STEP 2: Open the Terminal window and enter the following code (make sure you use a capital “-F”):

youtube-dl -F https://www.youtube.com/watch?v=x_Akn8fUBeQ


STEP 3: You will then see an impressive list of all the different audio and video formats that the YouTube server has available for the NASA video. If you look carefully, you will see there’s a video track with a resolution of 1920 x 1080 that uses the “avc1” codec at 30 FPS (Frames Per Second). “AVC1” is simply another name for the H.264 codec. The Raspberry’s GPU has been specifically optimized to play H.264 video with full-blown hardware acceleration. On the far left column, you will see a “format code” for that particular video format. In this case, it’s code “137”. You will also see a high-quality audio track that’s described as an “m4a” with a sampling rate of 44100Hz. That’s YouTube's terminology for an AAC audio track. It has format code “140”. It's the best choice for this example, since an AAC audio track is specifically designed to work with an H.264 video track when creating an MP4 video. To download the high-resolution video (with sound), you will therefore issue the following command (make sure you use a lower-case “-f”):

1920 x 1080 MP4 – 30 FPS:
youtube-dl -f 137+140 https://www.youtube.com/watch?v=x_Akn8fUBeQ

Once the download is complete, be sure to close the Terminal window or you will lose keyboard control of mpv. Then, simply double-click the MP4 video you just downloaded and mpv will automatically start playing it full screen! If you downloaded a resolution smaller than your screen, you can tap the "f" key to toggle back and forth between actual size and full screen mode.



DOWNLOADING WEBM VIDEOS (VP9 / Opus): If you want a much smaller file size at a surprisingly high quality – albeit with lower resolutions of 720p or 480p – the “VP9” format for video and the “Opus” format for audio are the ones you want. They are the most advanced compression technologies currently available. The two tracks will be automatically combined by youtube-dl (using the FFmpeg engine) and merged into a standard WebM video. Be aware that the Raspberry’s GPU is only designed to provide full hardware acceleration for MP4 videos using H.264 – so a 1080p VP9-based WebM video will push your Raspberry to the absolute limit and will likely result in at least some stutter. That's why I recommend 720p and 480p resolutions for VP9-based videos. They also, of course, should not exceed 30 FPS. Finally, if you wish to share the video with someone else who doesn’t have an advanced player like mpv, it’s best to stick with a standard H.264-based MP4 video for compatibility reasons. For the NASA video, here are the two best command lines if you want smaller file sizes (for example, if you're using a cellular connection and need to conserve your data usage). When it's competently encoded by the uploader, I've been consistently amazed by how good a humble 480p video can look when viewed full screen on my large 24 inch 1080p monitor.

1280 x 720 WEBM – 30 FPS:
youtube-dl -f 247+249 https://www.youtube.com/watch?v=x_Akn8fUBeQ

854 x 480 WEBM – 30 FPS:
youtube-dl -f 244+249 https://www.youtube.com/watch?v=x_Akn8fUBeQ



HIGH FRAME-RATE CAPABILITY: In my testing, I was surprised to discover that the Raspberry’s GPU can handle 1920 x 1080 H.264 video at DOUBLE the normal frame rate – 60 FPS without dropping even one frame! Some newer videos on YouTube are now available in 60 FPS format, and the NASA video is one of them. If you wish to download the 60 FPS version of the above 1080p video, you would simply change the video format code from 137 to 299. In other words, you would use this command line instead:

1920 x 1080 MP4 – 60 FPS:
youtube-dl -f 299+140 https://www.youtube.com/watch?v=x_Akn8fUBeQ



CAUTION: Don't assume the format codes will always be the same. YouTube is quite consistent – but even with them, the available formats can vary from one video to another. For example, I've noticed that YouTube's servers will often place different formats in a queue, prioritizing H.264 over VP9. Even for the mighty Google, encoding video is very computationally intensive and time consuming – so it makes sense for them to quickly get the H.264 version up on their server, and then process the VP9 version an hour or half hour later. Other video sites, however, use completely different format codes and are typically limited to H.264 videos – so for them, you'll want to first run youtube-dl's "-F" option (capital F), as explained above, to see exactly what formats are available. Finally, be aware that most other sites tend to integrate the video and audio tracks into a single pre-packaged MP4 video – so there won't be separate video and audio formats to choose from. YouTube does this as well, by the way. It's usually listed in the last couple lines of their available formats. In YouTube's case, you'll know if everything's already been combined if it says both "avc1" and "mp4a" in the description. In those cases, you would not use the "+" symbol. Instead, you would simply use a single format code.

YOUTUBE-DL HAS MANY OTHER FEATURES AND CAPABILITIES: To learn more, visit youtube-dl's official website.






---------
APPENDIX 3: PLAY ONLINE VIDEOS AUTOMATICALLY WITH MPV (WITHOUT ANY MANUAL DOWNLOADING):

If you want to automatically play the NASA video mentioned in Appendix 2, this simple command line is all it takes:

mpv https://www.youtube.com/watch?v=x_Akn8fUBeQ


NOTE: I had to greatly abbreviate this appendix to free up room on this page. See below for how to access all of my appendices in full.






---------
WOULD YOU LIKE TO ENCODE MP4 OR WEBM VIDEOS WITH FFMPEG? OR DO YOU WANT TO INSTALL EVERY PROGRAM IN THIS TUTORIAL ON ANOTHER RASPBERRY IN JUST A FEW MINUTES? PERHAPS YOU'RE LOOKING FOR TROUBLESHOOTING TIPS? EACH POST IS LIMITED TO 60,000 CHARACTERS, SO I HAD TO FREE UP SPACE ON THIS PAGE BY REMOVING MOST OF APPENDIX 3 AND ALL OF APPENDICES 4, 5, 6, 7, 8, 9 AND 10. FORTUNATELY, ALL OF THE APPENDICES CAN NOW BE FOUND AT THIS SEPARATE POST (WHICH IS STILL PART OF THE SAME THREAD):

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






---------
KEYWORDS: Raspberry Pi 3, RPi3, Pi3, 3B, 3B+, RPi, FFmpeg, mpv, tutorial, 1080p, 60 FPS, MP4, H.264, AAC, WebM, VP9, Opus, x264, LAME, MP3, Fraunhofer, GPU, VideoCore, MMAL, OpenMAX, OMX, video, audio, encoding, decoding, compiling, source code, hardware acceleration
Last edited by RPi_Mike on Tue May 22, 2018 1:27 am, edited 21 times in total.

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

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

Sat Dec 16, 2017 11:00 pm

Wow, this is beautifully done!
Thanks for the tutorial. I'll hopefully get a chance to try this out next weekend.

Can this build coexist with the accelerated vlc build outlined here?
viewtopic.php?f=66&t=195221

RPi_Mike
Posts: 46
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 Dec 17, 2017 7:18 am

treeHouse wrote:
Sat Dec 16, 2017 11:00 pm
Wow, this is beautifully done!
Thanks for the tutorial. I'll hopefully get a chance to try this out next weekend.

Can this build coexist with the accelerated vlc build outlined here?
viewtopic.php?f=66&t=195221

Thanks – I appreciate the kind words.

I'm almost hesitant to weigh-in on your VLC question. Many people use their preferred media player every single day. It's how they use their two most important senses to inform and entertain themselves – through sight and through sound. It can quickly become a fundamental part of their life experience. For obvious psychological reasons, many people will therefore develop a deep emotional attachment to their favorite media player – which also explains why they can get quite upset when one person claims a certain player is better than another. It reminds me of the never-ending "Mac vs. Windows" and "iPhone vs. Android" debates.

I have no association with the mpv and FFmpeg communities, so I can assure you that my feelings on this topic were completely agnostic just a few months ago. I went down the typical path I'm sure many other Raspberry users have traveled – first I tried OMXPlayer, then I tried VLC. I honestly didn't care what player did the job – I just wanted something to work. I wanted what most people want in a media player. I wanted FULL SCREEN NIRVANA. That means HIGH RESOLUTION. That means SMOOTH PLAY with no stuttering from frame drops. That means ANY FILE AND FORMAT will play. Everything I tried came up short, so I Googled some more and stumbled across this thing called "mpv". That didn't work either because of the typical Raspberry-specific roadblocks. But it was the moment I fell down the rabbit hole in a quest to get the most from my Raspberry Pi 3.

The Intel x86 architecture dates back to the 1970s, so it got a giant head-start in the Linux world over ARM-based systems. Although rapid progress continues to be made, the ripple effects of this history continues to haunt the Raspberry, and it's clearly reflected in the absurdly difficult time I had in getting a decent media player to work. Not just "work", mind you – WORK WELL! Many of us in the Raspberry community are quite advanced in the computer world, especially compared to the general population. But the irony is that a barely-literate computer user on Windows or Mac can just download and double-click a simple installer file and be all set in less than ONE MINUTE! They certainly wouldn't have to struggle off and on for several weeks, as I did, to get one program to work!

Since I have now written an extremely comprehensive 6,500-word tutorial on this subject, I freely admit that when it comes to the best media player on the Raspberry, I'm not agnostic anymore! FFmpeg and mpv are truly fantastic programs that work exceptionally well together. When properly customized to meet the unique architectural demands of the Raspberry, the results are nothing less than amazing – especially when you consider that all that "magic" is happening on a $35 device. After great frustration and effort, I finally came up with a solution that does everything I want. How do I know? I can see it with my own eyes!

As to your question of whether my hardware-accelerated FFmpeg / mpv build can coexist with a hardware-accelerated VLC build, the honest answer is WHO KNOWS! The only way for me to test that scenario would be to go through the painstaking process of following someone else's tutorial to theoretically achieve something I've already achieved! That wouldn't be too rational on my part. But if I had to guess, they probably can NOT peacefully coexist. The required dependencies for anything as computationally intense as a hardware-accelerated media player are complex and intertwined – so there's a very good chance that in attempting to install a rival media player, certain software libraries will be overwritten or "updated" in unpredictable ways that will either break my tutorial or simply do weird things to the entire "operating environment" – an environment I like to keep stable, predictable, and pristine. That's why I began with a clean install of Raspbian Stretch. That way I can know there are no hidden assumptions or "accidental tricks" that allowed my method to work. Only in that context can I guarantee that my tutorial will do what it claims. Once someone starts tinkering with something as fundamental as the video and audio dependencies of their system, all bets are off. This would be true whether they do that tinkering BEFORE my build or AFTER my build.

Now, to put my blatantly boastful and partisan hat on for just a moment, here are a few quick observations on the VLC tutorial you referenced:

My tutorial is very lean and mean. It only requires 27 dependencies. But the VLC tutorial requires a whopping 224 dependencies – nearly 10 times as many. And yes, I actually counted them. Of course, even this isn't a fair comparison, since my tutorial provides a SUPERSET of features – a truly capable media player PLUS a full-blown encoding suite. It really is apples and oranges.

The author of the VLC tutorial says that "VLC requires quite a lot of shared libraries. Some may be already installed on your system, but we cannot be sure." He then lists 119 dependencies that must be installed. He then says in the next paragraph that "these libraries will enable us to run VLC, but to compile a new version we also have to add the matching development (-dev) packages". He then proceeds to list an additional 105 dependencies that must also be installed. 119 + 105 = 224 dependencies! Quite frankly, I would be afraid to install such an astonishing array of software packages to get one program to work! Even if it "works", that introduces so much unnecessary complexity and "package baggage" that all kinds of unpredictable things could happen to your system.

He also indicates that "SD video and some 720p video (RPi3) can also be played using software codecs, if you select SDL video output." In other words, there can sometimes be a need to manually change VLC's video output settings from "OpenMAX IL" to "SDL". With my build, however, the optimal hardware – GPU or CPU – is automatically selected on the fly without any user intervention. You just double-click the file and BOOM – it starts playing, no matter what the format or codec. If the codec is supported by the GPU, it will use the GPU. If the codec requires the CPU, it will use the CPU.

Finally, the author indicates that VLC "did not play some 1080p60 videos which are playing well with omxplayer." Here again, I can shamelessly say that my build comes out on top. Not only can my build play *ANY* 60 FPS H.264 video up to 1080p – it will play it flawlessly, full screen, with no dropped frames.

For those who would like to know more about the performance and capabilities of my build, please review the detailed benchmarks under the "Testing Results" section of my tutorial.

gkreidl
Posts: 5574
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

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

Sun Dec 17, 2017 10:34 am

Nice tutorial, but why do you think you have to use a big font everywhere?

WARNING: Do not advice people to run
sudo rpi-update
This will install experimental kernel and firmware and might break your system!

You are installing newer versions of a number of libraries, which may be used by other software as well (kodi, VLC, gstreamer, webkit browsers etc.). There's always a risk that other software depending on these libraries won't work any more. You should at least issue a warning about it.

Except for mpv you have not set the --prefix, which means that the default path /usr/local will be used. This means that there will be two sets of libraries in your system now (the new ones will take preference), as long as you install them using "sudo make install". By creating and installing .deb packages the old packages will be removed and only the new packages will remain (in a different place!). This also may lead to problems with other software. And removing the .deb packages might require to remove other packages as well, which depend on them. The only solution would be to replace them by the default versions again.

Regarding youtube-dl: It's much better to use pip to install and upgrade youtube-dl. The "fake-binary" contains 1000+ modules zipped in .py format which have to be converted each time you run the program. It's much faster to load them as precompiled .pyc files (programs starts about twice as fast). And the pip installation also allows other python software to use youtube-dl as a module (as I do in my youtube-dl-server to speed up video URL extraction).
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

RPi_Mike
Posts: 46
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 Dec 17, 2017 3:22 pm

gkreidl wrote:
Sun Dec 17, 2017 10:34 am
Nice tutorial, but why do you think you have to use a big font everywhere?

WARNING: Do not advice people to run
sudo rpi-update
This will install experimental kernel and firmware and might break your system!

Another poster simply asked for my thoughts on your VLC tutorial and I provided my technical assessment.

I'm sorry you don't like my font-size choice. I have a 1080p monitor hooked up to my Raspberry and the default font size was hurting my eyes, so my only motivation was to make the text a bit easier to read.

I'm reluctant to get into a tit-for-tat with you on each point, because I can already tell from the tone of your first message that you'll find it irresistible to fire back with counter-points to everything I say. I'm simply not here to get into an ongoing argument with anyone. My tutorial stands on its own merits. It's tested and proven to work. Are there certain minor elements in my procedure that a total expert might legitimately quibble with? Probably so! Although if there is such an expert, they haven't taken the time to create a tutorial that actually works like I have!

Nonetheless, I will make a one-time exception and respond to your comments.

Your "WARNING" to me about sudo rpi-update is overly dramatic. It also seems a bit inappropriate to be issuing a "WARNING" to a fellow member of the community who made a good-faith contribution. Are you the Raspberry police? You make it sound as though I was advising people to install some kind of bogus file from a random website. The rpi-update command in my instructions is a built-in feature that comes pre-installed with the Raspberry's official operating system, as sanctioned by the Raspberry Pi Foundation. Among other critical things, the command updates the VideoCore libraries. The VideoCore IV, of course, is the Raspberry's GPU. Having the latest updates for the GPU is essential for my tutorial to work as fantastically well as it does.

It's also ironic that you dwell on the libraries my tutorial installs when your tutorial installs a BLIZZARD of libraries 10 times bigger than mine. Do I agree with your general observation that any installation of software can "break" a system? OF COURSE I DO! Nothing in life is guaranteed, and that certainly applies to *anything* one does on the Raspberry. Everyone should follow common-sense practices and keep a backup of their important data.

But even if a Raspberry "breaks", the worst outcome is to run NOOBS again. Or in my case, I keep a cloned SD card with a fresh install of Raspbian PLUS all the "core" software I use. If anything bad happens, I simply pop out the cloned card and make another clone – and I'm back up and running with a full system in only 10 minutes! For those of you who wish to do this, I highly recommend the free "SD Card Copier" tool that comes with Raspbian.

Beyond all these theoretical concerns – negative events that have never happened to me – I can't help but mention that my system is extremely stable and both FFmpeg and mpv are working great!

Ultimately, I'll leave it to the other readers to decide which tutorial they wish to follow with this simple chart:

–––––––––––––––––––– MY MPV ––– YOUR VLC

REQUIRED DEPENDENCIES:_____ 27 __________ 224

DOES IT WORK PERFECTLY?____ YES _________ NO


Finally, as to your comments on youtube-dl, I'll also leave it to the other readers to make their own judgments. In this case, my installation advice for youtube-dl was taken directly from their official website – written by the actual developers who made the program! It is the FIRST method they advise. The pip method you suggest is the THIRD method listed. Now, I don't necessarily dispute your very specific technical claim. What you say sounds credible – the pip method might lead to a slightly faster load time, although I must say that my copy is very responsive as it is. But since you feel your installation method is "much better", I suggest you take it up with the developers of youtube-dl so that they can follow your sage advice and reverse the order of their suggested installation methods. Here's their official installation instructions in case anyone wants to see it for themselves:

https://rg3.github.io/youtube-dl/download.html

jccj78
Posts: 14
Joined: Sun Dec 17, 2017 3:05 pm

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

Sun Dec 17, 2017 3:57 pm

Very great theoretical contribution RPi_Mike!!!
For a novice like me it has been very helpful.
Thank you.

User avatar
DougieLawson
Posts: 32361
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

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

Sun Dec 17, 2017 4:06 pm

You really don't need to use [size=140], just get your browser to magnify the text if you can't read it using [CTRL] and [+] keys.

Anyone suggesting that brand new users run sudo rpi-update is irresponsible. It can (and has done) break your system so that it's not bootable. If you don't know what it does and how it can break a system then don't recommend it. The stock, standard, safe & tested kernel and bootcode are delivered with apt-get upgrade and apt-get dist-upgrade.

Anyone who has a pressing need to run sudo rpi-update should backup their SDCard and know how to recover their system from that backup in minutes rather than hours. I won't recommend it unless I'm 100% convinced that the experimental kernel and bootcode will solve a problem.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

gkreidl
Posts: 5574
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

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

Sun Dec 17, 2017 4:49 pm

The "warning" was for the users, not for you. You may break your system, if you like, but you should not add this advice it to a general tutorial. Dougie has said everything what has to be said about it above.

Regarding dependencies: the number is not so important, but adding newer versions (not from the repository) is always risky. That's simply violating Debian policy. Of course anybody can do that - and I'm doing it myself sometimes - but people should be aware of the risks.

I don't want to enter any kind of stupid "competition" between your ffmpeg/mpv installation and VLC and so I'll stop here.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

User avatar
fruitoftheloom
Posts: 16450
Joined: Tue Mar 25, 2014 12:40 pm
Location: Bognor Regis UK

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

Sun Dec 17, 2017 5:09 pm

RPi_Mike please can you edit your posts and put text back to standard size for this forum :roll: :roll:
""understanding the theoretical, but not always the end goal""

My other Devices are the ChromeBit CS10, ChromeCast & Huawei Mate 10 Pro SmartPhone

RPi_Mike
Posts: 46
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 Dec 17, 2017 5:14 pm

DougieLawson wrote:
Sun Dec 17, 2017 4:06 pm
I won't recommend it unless I'm 100% convinced that the experimental kernel and bootcode will solve a problem.

For me, the bleeding-edge firmware code solved a very real problem – it proved to be a critical element in getting the FFmpeg / mpv combination to provide maximum performance.

Nonetheless, I have no objection to issuing a simple warning about basic "data safety" – always having a backup for both your data and your operating system itself. Your suggestion is perfectly reasonable.

As a result, I have now included a warning IN ALL CAPS in Step 2 of my tutorial.

PS: I have seen several of your posts over the last few months and greatly respect your technical opinions – you're clearly one of the most technically sophisticated and prolific posters on this forum. What I didn't entirely appreciate, however, was your condescending "lesson" on how to use my browser – complete with exaggerated font effects to amplify your ridicule. I simply thought the default font size was too small and difficult to read, so I made use of the built-in font size tool to make it bigger. I didn't realize that was a cardinal sin.

User avatar
DougieLawson
Posts: 32361
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

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

Sun Dec 17, 2017 5:16 pm

fruitoftheloom wrote:
Sun Dec 17, 2017 5:09 pm
RPi_Mike please can you edit your posts and put text back to standard size for this forum :roll: :roll:
You can always fix it the other way with [CTRL] & [-] to reduce RPi_Mike's antisocial font size to something more readable.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10483
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

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

Sun Dec 17, 2017 6:07 pm

I have/will edite(d) all posts with size =140 (or 125) settings, to turn them back to normal, please don't do this!
wasnt it a hint enough that I edited your post, you really couldn't resist undoing my changes?

Anyone who wants to increase the text size can do so himself with his browser, so I consider increasing the text size impolite, like shouting in public.

If necessary I will make the edit, and then simply lock the thread!

RPi_Mike
Posts: 46
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 Dec 17, 2017 6:44 pm

DougieLawson wrote:
Sun Dec 17, 2017 5:16 pm
fruitoftheloom wrote:
Sun Dec 17, 2017 5:09 pm
RPi_Mike please can you edit your posts and put text back to standard size for this forum :roll: :roll:
You can always fix it the other way with [CTRL] & [-] to reduce RPi_Mike's antisocial font size to something more readable.

I can't believe I'm getting sucked into a debate about font size, but allow me to provide some essential context that makes my initial font size choice seem perfectly reasonable.

Believe it or not, I actually put considerable thought into my initial font size choice – because I'm fully aware that people can get quite worked up about such things. For some, it's like not knowing what a caps lock key is and SHOUTING EVERYTHING IN ALL CAPS. I've never been clueless or obnoxious like that.

So I made a sincere effort from the very start to "get it right" and be respectful. Here's what I did when I made my very first post with my giant tutorial:

Since font sizes often use arbitrary units that vary from site to site, I had no idea what "normal" size was in Raspberry land. So to find out, I selected some text and clicked the "normal" option under the text-size button to get its numerical code. But it didn't do anything – I assume that was because the text was already, by default, in a "normal" size, so the button was simply ignoring my input by design.

At that point, I had no way of knowing what the numerical value for "normal" was. But I noticed that if I clicked "small", it gave me a value of 85. And if I clicked "large", it gave me a value of 150. So I calculated the midpoint and rounded to the nearest multiple of 5. I realize that numerical patterns can be non-linear, but it was all I had to go on. That gave me a theoretical value of 120 for "normal" text. My thought was that "normal" looked too small and "large" looked too big. So I actually went to extreme lengths to select a socially-appropriate font size. I ended up picking a value of 140, which is just a hair above the 135 midpoint between normal and large. In other words, I had every right to see my choice as being "large normal" – well within the bounds of reasonable and a far cry from "antisocial".

Some of you guys obviously didn't see it that way, but it is what it is. It seemed quite unfair to get ridiculed for something I actually made a genuine effort to be courteous about.

RPi_Mike
Posts: 46
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 Dec 17, 2017 8:04 pm

mahjongg wrote:
Sun Dec 17, 2017 6:07 pm
I have/will edite(d) all posts with size =140 (or 125) settings, to turn them back to normal, please don't do this!
wasnt it a hint enough that I edited your post, you really couldn't resist undoing my changes?

I feel I need to defend myself on this one, because it could create the FALSE perception that I was somehow being sneaky or underhanded by deliberately not taking the "hint" and undoing your changes behind your back.

The simple fact is I didn't know they were your changes! All I knew was that my font settings mysteriously changed only minutes after a regular member said they didn't like my font size. So my first thought was that my account had been hacked and that I was being subjected to some kind of retaliation. I also speculated that maybe it was a weird bug and that it was just a coincidence. Either way, I was determined to put my settings back to where I had left them! And yes, I briefly considered the possibility that it was an official of the Raspberry Pi Foundation who was using their legitimate authority as a moderator to change things at their discretion. But I reasoned that if it were a legitimate change, I would have received some kind of official communication to indicate this – an email or private message to inform me that I had unintentionally violated "the font size policy". So although I *FULLY* understand why you might have thought I was being sneaky and couldn't take a hint, the supreme irony is that I thought someone was being sneaky with me!

Anyway, the font size matter is what it is. I've now learned that it's a very sensitive issue on this website and I will not attempt to modify my font size settings ever again. I promise!

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10483
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

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

Mon Dec 18, 2017 9:06 pm

The normal font size is what you get when you DO NOT FIDDLE WITH THE SIZE OPTION, and leave it alone (the default even says "Normal" size).

To aberrant from that you have to put size = tags around the text you want to resize, or use the re-size pulldown menu, so its obvious you are doing something abnormal.
no-one else but you, or a moderator can edit your posts, seems obvious to me, if anyone else could edit your posts it would be like anarchy in here.

You may claim you didn't think you did anything out of the ordinary. But look how many posts there are here that have enlarged text, it is almost none! Yes we have a simple to use re-size option, but it is meant to be used sparingly!

Ill leave it to that.

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

Tue Dec 19, 2017 5:50 am

mahjongg wrote:
Mon Dec 18, 2017 9:06 pm
The normal font size is what you get when you DO NOT FIDDLE WITH THE SIZE OPTION, and leave it alone (the default even says "Normal" size).

To aberrant from that you have to put size = tags around the text, you want to resize, or use the re-size pulldown menu, so its obvious you are doing something abnormal.

FINAL THOUGHTS ON "FONTGATE": I have only one issue with your analysis. I never "put size = tags around the text". Instead, I innocently clicked the built-in text size button and it automatically inserted the tags all by itself! I simply changed the number inside the tag to a smaller and more respectful value – from large (150) to smaller than large (140).

This may seem like a trivial distinction, but I feel it's important because it creates yet another false and unfair impression about me – that I was doing something "abnormal" and "aberrant", to use your words. It makes it sound like I was being sneaky and deviously "hacking" the font size code with some kind of undocumented trick to be "antisocial", as DougieLawson put it the other day.

What makes the "sneaky and abnormal" narrative even more unfair is the giant elephant in the room: The text-size button is a highly visible and built-in tool on the forum. I didn't put it there – the Raspberry Pi Foundation did. Any reasonable person would conclude that the tool, like all tools, is there for a reason – TO BE USED! So, I used it. And I used it in a well-intentioned and thoughtful manner. As I explained earlier in great detail, I even made mathematical calculations to determine the optimal font size. What more could a person do? Given the tremendous length of my tutorial, my only goal was to make my writing as easy on the eyes as possible by default – for everyone – without requiring end-user browser adjustments. That doesn't make my design choice aberrant or antisocial. Quite the opposite: It means I was trying to make things easier to read for everyone by using a tool that was provided to me! Nonetheless, I believe that "when in Rome, do as the Romans do". Now that it's been made abundantly clear that small font sizes are sacred on this site, I will respect that unfortunate cultural norm.

THE PRIESTHOOD: For just a moment, I'd like to step back from the absurdity of a font-size debate and take the 30,000 foot view on all this:

I deeply respect what you guys do and have been quietly reading the excellent commentary and advice on these forums for several months.

I have been watching things on here long enough to be aware of the basic sociology of this site. There's a large number of novices and intermediate-level users on this forum. And then there's a very small but elite "priesthood" of Raspberry gurus that dominate the discussions. These "alpha males" have achieved their status through great knowledge and expertise, and by generating a vast number of posts (numbering in the thousands and tens of thousands per individual). These prolific and technically sophisticated persons have been on here for a long time and would certainly include DougieLawson (5 years), fruitoftheloom (4 years), and gkreidl (6 years).

Given the surprising level of grief I encountered on a single obscure topic like font size, I should hasten to add that my calendrical values are based on standard accounting principles and are therefore rounded to the nearest year. :P

So you have the priesthood. And then there's me. I just got my first Raspberry six months ago. And I joined this forum only eleven DAYS ago – a complete stranger from out of nowhere. The established tribe is understandably suspicious about the newcomer.

This newcomer, however – though not as technically advanced as the priesthood – just made a very significant contribution to the entire community. He is the first person in history to publish a comprehensive, step-by-step tutorial that transforms a standard media player on a $35 computer into a multimedia juggernaut. Quite astonishingly, it plays full screen 1080p video at 60 frames per second without skipping a beat. It even switches between GPU and CPU modes on the fly. Sure, there are "media centers" like Kodi that are quite excellent. But they place the user inside a full-blown "environment". I'm not suggesting there's anything wrong with that approach, but it is a distinct experience from a simple and straightforward media player. THAT is my contribution.

Researching, developing, validating, and writing-up my extremely comprehensive 6,500-word tutorial obviously took dozens of hours. If I were charging standard market rates for my service, it would literally cost thousands of dollars. Yet I DONATED IT to the Raspberry community in an act of philanthropy and good will.

As you can see in the posts, however, the priesthood didn't quite seem to appreciate my efforts. In fact, their reaction was entirely negative. Perhaps they considered it to be an overly bold encroachment upon their established territory. Other than a sarcastic "nice tutorial", there was no acknowledgment of my significant contribution. In fairness, they expressed a legitimate concern about *ONE* experimental line in my entire tutorial; I acted reasonably and updated my instructions to incorporate their caveat. I can't help but note, however, that even the priesthood did not dispute the fantastic performance claims of my tutorial. Instead, they decided to focus on my choice of font size and ridicule me for it! I also found it quite hilarious that they all suddenly appeared out of the woodwork to attack my font size in the space of just a few hours. I can almost imagine them messaging privately among themselves and saying "hey, some dude just came on the board who thinks he's so smart – let's put him in his place!" I can't say I'm surprised, however. From a primatological and evolutionary psychology standpoint, this is pretty standard territorial defense behavior.

I am heartened, however, by the genuine appreciation of the regular members. As you can see in the posts above, one said my tutorial was "beautifully done", while another said "very great theoretical contribution RPi_Mike!!!" And to them I say: THANK YOU!

g4bch
Posts: 7
Joined: Mon Oct 01, 2012 12:06 pm

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

Tue Dec 19, 2017 1:22 pm

Thank you for the detailed ‘How To’. As far as my limited testing has gone so far mpv seems to be working. And I not yet found anything to have been broken.
For anyone having got this far past the font size stuffand contemplating trying this, I did have problems with compiling ffmpeg. Despite having a fan, heatsinks and an official power supply the RPi froze several times. I eventually got it to compile by using –j2 instead of –j4 to give the processor some spare capacity and by turning off the screen blanking. I’m not sure which of those actions cured teh problem, the object was to get it to compile rather that find out exactly why it would not. I did not note the time taken to compile with only 2 cores but it did not seem to take all that long.

Thanks again for teh detailed instructions

Peter

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

Tue Dec 19, 2017 2:56 pm

Mike, it is great and greatly appreciated to have such a well written and sorely needed contribution on what should be a very important subject to to those of us who use their Raspberry Pi’s for multimedia. because MPV is at the moment probably the pre-eminent and best multi-platform media player especially when used as the engine for Smplayer on Windows and Linux. and it does work very well on the Pi, once you, as you eloquently note get past the rather difficult process of compiling from source.. ( my but that’s a long sentence! )

In my opinion, it definitely has not received the attention it merits in the Raspberry forums probably because there are still some easily deployed and very good and serviceable alternatives which I still use, like G. Kreidl’s estimable Omxplayergui,an integral part of his Kweb suite which he scrupulously maintains and recently updated with a web interface with on the fly resizable fonts!!! that makes it particularly well suited to television users playing all local media files in a folder or from a playlist. It pays dividends to read his manual! Another recent media player that has received no attention on the Raspberry forums that also uses omxplayer is Tomxplayer (Tactical omxplayer) which has a very nice interface and is simple to use and set up- just install the deb file from his site:

http://www.meticulus.co.vu/p/tactical-o ... layer.html

It was incidentally given a very enthusiastic endorsement from Martin Wimpress, the main man at Ubuntu Mate. That being said and as you noted MPV brings additional and valuable capabilities, It also has a few minor disadvantages when used on the Pi. Bottom line I think it is nice to have a variety of media players and web browsers in the quiver and available to Pi users. Horses for courses, as they say. Variety is the spice of life etc.,etc


I have been using MPV as the engine for Smplayer on Windows for some time and have been happily using them both on the Raspberry Pi for over a year and one half.. Like you I was impressed with it’s capabilities and astonished at the paucity of reference to it on the Raspberry forums, and that users seemed largely unaware of it. I felt it was too good to keep its many felicities to myself and accordingly made several posts to the forum in the hope this would lead to further and easier access to users and the further development and refinement of it on the Raspbian OS.by users infinitely better qualified than myself ( alas still a linux novitiate with no experience at all in coding or compiling.)


viewtopic.php?f=66&t=148185&p=975000&hilit=mpv#p975000

viewtopic.php?f=63&t=153480



I have frequently made reference to it in my infrequent posts in attempt to proselytise it’s virtues. .When I encountered your post I was actually on the verge of posting an update to some of my previous posts to elucidate on my further experiences and some changes I made to mpv and smplayer configurations, and to pose some questions I hoped could be answered. I was also going to post the dependencies, configurations etc that I found successfully compiled ffmpeg and mpv on a fresh Stretch image, As one who had a weak grasp of such things I felt inadequate to the task .


My experience mirrored your’s eg. mountains of research from disparate sources not all of them applicable to the Pi ,determining the dependencies,figuring out the proper configuration options experiencing numerous compiling failures , going through logs filled with cryptic unfamiliar names trying to figure out what went wrong, checking forums and bug trackers on Git. Oh the fun! My compiling time for ffmpeg was roughly the same as yours. I have a case for my Pi 3 that came with a fan but I never installed it since I found it rarely got particularly hot and I didn’t want the drain on power, but when the ffmpeg compile got going and as temperatures approached 80 I started blowing furiously on the Pi to cool things down!(It worked!)
I would like to find a cheap mini usb fan that I can run externally only when needed.

I know rules are rules and if they aren’t followed it can lead to anarchy but I too felt (that especially to a new contributor) that it was a bit unfair and unwelcoming to belabour the focus on font size to the point that the substance of your important contribution ( I think) ) seems to have been largely ignored rather than welcomed. To tell the truth I sort of appreciated the font size because I am myopic and view my Pi display on a television screen from a distance. But rules are rules! Perhaps you too, got a little testy in your responses to some very valued and senior members of the community (understandable when you obviously put so much work in your tutorial ) At this point I think everyone should just cool it and concentrate on substance. I sort of wish your post had been made to the general section or to the raspbian section of the forum where it would probably have received more attention. By the way that's another rule that is strictly enforced you can’t cross-post the same subject to more than one section.

In your post you mention backing up deb files( a really really good idea) in case ffmpeg. Mpv etc gets overwritten on an update. You can easily lock your compiled version via the gui Synaptic package manager (the very first thing I install on a fresh Raspbian image ) or you can do it by command line (off the top of my head I forgot the command. As a stupid old geezer I like to use a gui when I can.


In my opinion probably seconded by millions of users( unless you are an extreme minimalist) on other platforms the enjoyment and utility of mpv is greatly enhanced by using it as the engine for the smplayer gui rather than standalone. This is even more true on the Pi .Since you configured your ffmpeg with mmal i presume your video output is in the form of an overlay. This is in my opinion the biggest disadvantage of mpv on the Pi. However this disadvantage can be mitigated and even made into something of a virtue via a hack I employ in the mpv.conf file and also in the configuration of smplayer.. My current mpv.conf file reads:


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


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 20% 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 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 fullscreen and a minuscule nearly invisible dot but still retain audio playback. Various configurations options using autofit and geometry are described in mpv's online manual referenced above. I fid it incredibly confusing. I would be very interested in hearing from other users of mpv what other options might be available for viewing mpvs video output in non full screen configurations. This hack allows you multitask, continue browsing, manipulate controls, change configurations etc. While still monitoring the video in a small unobtrusive window


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.





All these configuration options can also be entered in smplayers configuration as well and I do so by going to the tab options/preferences/advanced/mplayer/mpv/ and selecting run mpv in it’s own window and pasting the desired options in the options space. My currently used smplayer options are :

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


which in this case are the same as I use in mpv. If you are using mpv via smplayer the specified configuration in smplayer will tbe used rather than those in the mpv.conf


Using mpv with the smplayer gui brings a number of advantages over standalone mpv, perhaps most noteworthy are the ability to drag and drop web video links or local multimedia links to the smplayer interface and have them play,, an easy gui allowing multiple configuration and control options.. By using the pseudo-window hack I referred to you can switch to the small window and use and change Smplayer’s controls and configuration on the fly. Also Smplayer has it’s own internal youtube code which is even faster to respond than youtube-dl. By going into smplayers preferences/network tab you can select auto which I believes instructs you tube to return the specified video quality by using either youtube-dl or smplayer"s internal code which ever fetches the video first. Smplayer supports youtube and regular playlists,,cycling through aspect ratios although it always seems to find the correct aspect ratio automatically. You can also easily specify only one instance of smplayer so that when you are watching youtube you don’t even have to close the existing window when selecting a new video to watch.


One of my favourite firefox extensions has only very recently become available in the Chromium web store and as such is also now available in Vivaldi browser -namely “ Open With “ (by Geoff Lankow). This extension is designed to permit you to open a web url in another web browser. However it also has the widely recognised off-label utility of being able to add a smplayer or other media player instead of a browser and then if you add open with smplayer by clicking on a button icon it places on the browser and in the right-click context menu to open a video url with smplayer. Sweet ! To use the argot of the young!. Thus I have now configured both Vivaldi and Chromium so that I can open video links in mere seconds with smplayer. Thus when browsing youtube videos for example, I can with one click not only quickly open the video in the currently loaded tab but also the suggested videos beneath or to the side, in smplayer 


Once again a recent version of smplayer with an up-to date internal youtube code is I dont think available in the Raspbian repository (17.5 and above needed). However again it is better and not hard to create your own smplayer deb so as to enable installing the most recent version, by following the easy install instructions contained in the install text of the source file which can be downloaded here: 

http://downloads.sourceforge.net/smplay ... .0.tar.bz2

While you are at it you might also wish to obtain and build a deb for smtube -smplayer's integrateda youtube browser- smtube -which can also run independent of smplayer -using the same procedure.: See :http://www.smtube.org/ It is a very quick uncluttered way of browsing and viewing youtube and can utilise a variety of video engines in addition to smplayer. For example you can use G.Kreidl's omxplayergui as the engine for smtube browser. Omxplayer gui is nice because among it's other virtues unlike mpv and smplayer it is both draggable and resalable. and can be minimized. You can also use the hardware accelerated ffplay player derived from compiling ffmpeg. which is very quick and displays in a non overlay resizable, draggable and minimizable. The version of smtube in the raspbian repository is old and no longer works.


My suggested configuration for smplayer is under the general tab you must specify mpv as the media player and show the path to its executable if not already specified ie. /usr/bin/mpv.
For video output select rpi and for audio alsa for performance threads 4 and auto for hardware decoding. On the most recent versions of smplayer under the network tab select auto for support for video sites. Under the advanced tab select run mpv in its own window and under options I have specified those I noted previously These options would of course vary depending on the individuals preferences and the resolution of their monitor etc. It would be ideal if one could configure mpv and smplayer so that mpv would output its mmal overlay video into smplayers window so as to be dragable and resizable . Mpv has windowed options but i don't think they work with mmal decode. Some discussion of the complexeities involved can be found here:

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

and here

https://github.com/mpv-player/mpv/pull/2723.

G. Kreidl's omxplayergui through some kind of ingenious wizadry managed to put omxplayers overlay output into a resizable dragable pseudo window so perhaps there is hope for mpv on the Pi.




I would be interested in knowing what your mpv configuration file looks like? I gather your video output at the moment is a non-resizable or draggable overlay wihch you can only toggle between full screen or the videos original size?

I presume your compile of ffmpeg yielded the ffplay player component which only happens when you have installed the sdl dependencies which I believe you did. I really like ffplay because it will play videos in a non-overlay infinetly resizable,minimizable draggable window. And is quick to respond. It makes a really nice player for smtube and livestreamer. When I specify mpv as the player for livestreamer I lose keyboard control. Ffplay uses more cpu typically 15-25 % and doesnt have quite the same video quality as smplayer or omxplayergui perhaps it is something like the quality you see on the chromium browser. But it has its own virtues.It has no controls but responds to keyboard and some mouse commands> I made desktop shortcuts for two versions of ffplay. (By the way I also use the desktop shortcut for mpv you must click on properties and specify open and keep open terminal so as to retain keyboard control)

Unfortunately when I use an ffmpeg version greater than the 3.1 version while I can get a good working mpv the ffplay player stuuters badly with high cpu and video rendered like a slideshow.
I note other users have reported not being able to get ffplay to work with versions of ffmpeg 3.2 and above see:


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

I suspect that this has something to do with the fact that ffmpeg dropped support for sdl1 around this time and went to sdl2. But sdl remains installed on raspbian as well as sdl2 because I beleive it is is used for other applications. Any workarounds?


Unfortunately versions of mpv greater than 22 require an ffmpeg 3.2.2 or above Nonetheless,. Mpv versions 22 and below work fine at the moment. But some of the later versions of mpv bring minor fixes to mpv with respect to its utilisation of toutube-dl particularly as it relates to dash video. Since I am using smplayer which has it’s own internal youtube code this hasn’t been a problem to date.



As you mentioned since mmal video is rendered as an overlay if you are in full screen mode it is important to retain keyboard control or you are up the creek without a paddle so to speak. It is the same with Smplayer if you are in full screen and should lose focus 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. 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 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.
Last edited by Gadgetguy on Tue Feb 20, 2018 8:51 am, edited 1 time in total.

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

Tue Dec 19, 2017 3:28 pm

By the way another nice feature of mpv and smplayer is that by toggling the keyboard command o ie oh you bring up via on screen display(osd) in sequence time elapsed /total time .visual progress bar and v to toggle subtitles. Many other niceities too numerous to mention. Incidentally back when I first compiled mpv it wasn't neccessary to update-rpi firmware. Only the later versions of mpv seem to require this update to compile. I did the update bwith some trepidation noting the warning that is given to users of rpi-update, knowing I had more than one sd card bard backed up. I didn't observe any adverse consequences not to say the might be some unnoticed problems that might manifest later.

Another problem I have with some of the mpv versions greater than 21 is that on some of the mpv versions greater than 21 the mpv documentation states that vo-rpi is deprecated and vo-opengl is recommended/ or necessary for the pi.. I was never able to get the vo=opengl to work satisfactorily high cpu dropedd frames etc.

RPi_Mike
Posts: 46
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 Dec 20, 2017 1:42 pm

Gadgetguy wrote:
Tue Dec 19, 2017 2:56 pm
In my opinion probably seconded by millions of users( unless you are an extreme minimalist) on other platforms the enjoyment and utility of mpv is greatly enhanced by using it as the engine for the smplayer gui rather than standalone. This is even more true on the Pi .Since you configured your ffmpeg with mmal i presume your video output is in the form of an overlay. This is in my opinion the biggest disadvantage of mpv on the Pi.

Wow, Gadgetguy! That was a tremendous amount of stuff you wrote about SMPlayer – and a whole bunch of other experiences you've had in the past. Don't get me wrong – I'm truly grateful that you appreciate my "well written and sorely needed contribution". But if at all possible, I'd like to keep this thread focused on its designated topic. That topic, of course, is using my tutorial to build FFmpeg and mpv from source code.

My bigger concern is that less-advanced users might read your exuberant post and think "wow, this SMPlayer sure sounds nifty – it will make RPi_Mike's tutorial even better!!" Unfortunately, it won't do any of that.

As with almost all software in the Raspberry world, a normal user has only one realistic option to acquire SMPlayer – they must run "sudo apt-get install smplayer". That will grab version 16.11.0 from the Raspbian Stretch repository. That version is already more than a year old. And yes, I'm well aware that a user could try building the latest version of SMPlayer from source code – but that's a complicated topic for a separate tutorial in a separate thread. They could also try downloading a pre-built installer from some website. Believe me – I'm well aware of all the possibilities.

Nonetheless, out of curiosity, I just installed the repository's version of SMPlayer. To be blunt, it provides ZERO value to my brand-new build of mpv. All it does is get in the way.

Although it fully recognizes my build of mpv, it simply acts as a file manager without actually doing anything. In other words, if I launch SMPlayer and attempt to open a video inside it, it simply triggers my build of mpv – which then plays the video *OUTSIDE* the SMPLayer GUI. In other words, SMPlayer acts as an "empty middleman" that does nothing. I realize you may have used older, less functional versions of mpv IN THE PAST that "worked great" with SMPlayer. But when it comes to the brand-new version my tutorial builds, historical observations are obviously not relevant. I might add, by the way, that I *ADMIRE* how my build of mpv ASSERTS ITSELF – that it insists on running as a highly efficient overlay, rather than being trapped inside a sluggish GUI environment! That's half the point of mpv.

And yes, there's a chance that if I fiddled around for hours with the older version of SMPlayer – or even the newest version of SMPlayer – I might eventually get mpv to "work" inside the GUI. But that still wouldn't address a much more fundamental issue in my eyes – I don't like the concept of SMPlayer! Even if it did "work".

This is partly because my combination of FFmpeg and mpv does everything I want. But it's also because the "mpv philosophy" is to not get bogged down by the computational overhead of a GUI or any windowed environment. The Raspberry has limited resources, so the whole point of mpv is to have a "pure player" that squeezes every last drop of system power into the only thing that really matters: PLAYING VIDEO! That's partly why my build is able to crank out an amazing 60 frames per second without dropping a single frame. That's also why it's designed to behave as an overlay, rather than inside the "bloatware" of a GUI.

On top of that, many of the "enhanced features" that you claim are unique to the SMPlayer / mpv "combination" are already available in the latest version of mpv by itself – without any help from third-party software. An example would be the on-screen display via the "o" key toggle that you mention. This comes standard with mpv. I'm not saying you're mistaken about your past experiences – I'm just trying to remind the readers that you're talking about past experiences with OLD VERSIONS of mpv that no longer apply to this discussion.

And yes, I know you may be tempted to say "oh, but with SMPlayer it will do sooo much more" – and then you might tick off a long list of things that you adore about SMPlayer. Ultimately, if you want to create a brand new thread and write a crisp, clearly-written, step-by-step tutorial about SMPlayer and all its many advantages, I'd be happy to check it out. But it's definitely not the appropriate "companion" for my turbo-charged build of mpv.

Finally, let me conclude with a long quote from your last posting: "Another problem I have with some of the mpv versions greater than 21 is that on some of the mpv versions greater than 21 the mpv documentation states that vo-rpi is deprecated and vo-opengl is recommended/ or necessary for the pi.. I was never able to get the vo=opengl to work satisfactorily high cpu dropedd frames etc."

This again is a historical observation about one man's experience with outdated versions of mpv, so it's not relevant to this thread. But unfortunately, it creates the false impression that there might be something wrong or broken with newer versions of mpv. In the latest version of mpv that my build creates, there's no issue whatsoever with "vo" or dropped frames. In fact, it automatically selects the correct video output mode – on the fly – without any user intervention.

If you'd like to share additional thoughts with me about SMPlayer or other off-topic subjects, I'd be happy to discuss it with you via Private Message.

jccj78
Posts: 14
Joined: Sun Dec 17, 2017 3:05 pm

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

Wed Dec 20, 2017 7:24 pm

Would it be possible to implement all this in emby server?
Transcode dvb-sat2 on the fly to view home TV over internet? It would be like a dream that Raspberry could do it!

tomf90
Posts: 12
Joined: Sun Dec 10, 2017 5:36 pm

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

Fri Dec 22, 2017 7:04 pm

As a complete novice it was refreshing to find a tutorial on this forum that covers what I needed and explains it clearly.

I don't suppose you could drop me a message explaining how I would be able to use this to stream video from my pi noir cam and audio from my usb mic to a webpage? I know you're explanation would be far more understandable than any of the other stuff i've endured so far in my quest to find out how to do this.

Cheers

jerryrp
Posts: 18
Joined: Sat Dec 23, 2017 7:39 pm

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

Sat Dec 23, 2017 7:47 pm

Great post, thank you!

But for me one thing is not clear: do I have to uninstall all existing versions of mpv, ffmpeg, etc before compiling "my own", or I can install on top of them? Or this new libs/binaries will coexist peacefully with old ones?

RPi_Mike
Posts: 46
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 Dec 24, 2017 4:17 am

jerryrp wrote:
Sat Dec 23, 2017 7:47 pm
Great post, thank you!

But for me one thing is not clear: do I have to uninstall all existing versions of mpv, ffmpeg, etc before compiling "my own", or I can install on top of them? Or this new libs/binaries will coexist peacefully with old ones?

I appreciate your question. There are several things to say about this, but let me start with a quick answer: If you already have older versions of FFmpeg and mpv that you installed from the Raspbian Stretch repository – and then you compile and install my builds after the fact – my builds *should* automatically become the new, "dominant" versions.

My builds are a SUPERSET of the older, generic, non-hardware-accelerated versions that are available in the repository. My builds are also NEWER in both the case of FFmpeg (version 3.4 vs. 3.2.9) and in the case of mpv (version 0.27 vs. 0.23). The 3.2 release branch of FFmpeg came out in October of 2016. And the 0.23 version of mpv came out in December of 2016. But my builds are based on official source code released in October and September of THIS YEAR (2017). So my builds give you versions that are a year newer!

Obviously, because my builds are newer and much better than the stock versions, I had no reason to first install the old versions before I installed mine. After all, I'm just a random dude that researched, developed, validated and wrote a tutorial for free – I'm not a full-blown commercial testing facility that's deliberately trying to create every possible configuration someone might have in order to see what happens! That's why I made very clear in my tutorial that my "guarantee" only applies to a fresh, brand-new, unaltered copy of the Raspberry's current operating system – Raspbian Stretch. I did this on purpose so that I was not making any false assumptions or accidentally achieving success because of something else I had installed a month earlier. If someone has been tinkering with their system before they came upon my tutorial, I have no way to accurately model their likelihood of success.

Nonetheless, as a quick test, I went ahead and installed the old repository versions – and then I re-installed my versions in less than two minutes from the extremely convenient Debian software packages that my tutorial creates (see Appendix 6 for more detail). My results? Everything worked perfectly! My builds became the new, dominant versions. When I went to the Terminal window and entered "ffmpeg -version", it correctly responded with "ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers". And when I entered "mpv -version", it correctly responded with "mpv 0.27.0 (C) 2000-2017 mpv/MPlayer/mplayer2 projects".

Finally, unless you're a total expert, I wouldn't try "uninstalling" the old versions. Many packages are interlinked with other packages, so if you don't go about it properly, you could end up with a mess. Sure, you might free up a few extra megabytes on your system. But even on a small SD card, that's still less than 1/1000 of the total data capacity. Totally not worth it!

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

Sun Dec 24, 2017 7:37 am

Sorry I didn’t mean to hijack your thread and only discussed smplayer because I I found smplayer greatly enhances mpv’s caabilities especoally on the Raspberry Pi where mpv’s screen output is an ovelay. However I will mention it no further in this thread. Could you tell me whether your version of ffmpeg yielded the ffplay component of ffmpeg. I presume it did since you compiled ffmpeg with ffplay’s sdl dependency. If so would you be able to test play a hd video with ffplay and advise whether it plays fluidly without stutter. I and others were unable to get a good working ffplay with a version of ffmpeg higher than the 3.1 series.

I gathered from your tutorial that your video output from mpv only comes in two flavours: full screen and the native size of the video both output as overlays. I wonder if it would be too much to ask if you could try the hack I mentioned whereby you direct mpv, via it’s very easily changed and changed back again configuration file, to output its non- full screen overlay to a window of specified size at a predetermined location on the screen so as to enable multi- tasking and/or access to desktop controls. I suspect this hack which I do find very serviceable and an improvement. could be refined or developed further by someone much more qualified than me.

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 7 guests