MPV is a really powerful video player, and you can basically play any media format or any video directly from the internet (as long as YouTube-dl can play it). You just have to download and install a few packages on your distribution, and you are good to go.
It even supports SponsorBlock extension with the help of a Lua script. In this tutorial, I will show you the step-by-step procedure of watching online videos on the MPV player. I’m assuming you have already installed MPV on your system, if not, you can follow this guide. Finally, let’s get started!
Download and install yt-dlp and Python3
yt-dlp is a fork of good old Youtube-dl. The development of YouTube-dl is halted by the developers without giving any reasons, so I’m going to use the properly maintained package yt-dlp. You can install it by typing the following in your Terminal, irrespective of your distribution :
sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp sudo chmod a+rx /usr/local/bin/yt-dlp
If you have any Arch-based distribution installed, then you can install it directly from the AUR using your favourite AUR helper :
yay -S yt-dlp
If you want to use SponsorBlock enabled in your YouTube videos, you have to install the python3 package too, install it with your distribution’s package manager :
# In Ubuntu and Debian-based distribution sudo apt update && sudo apt install python3 # In Fedora Workstation sudo dnf install python3 # In Arch based distribution sudo pacman -S python3
Install SponsorBlock Lua script
This part is completely optional, but you can set we are going to copy the script from GitHub into our scripts directory so that MPV can access it to skip sponsors. First, clone then using the Git command :
git clone https://github.com/po5/mpv_sponsorblock
Now, let’s move the contents of this directory to the scripts folder. In the Terminal, type :
mv ~/mpv_sponserblock/sponserblock.lua ~/.config/mpv/scripts/
Also move the directory which contains the python file into the scripts folder, type :
mv ~/mpv_sponserblock/sponserblock_shared ~/.config/mpv/scripts/
Let’s enable the SponsorBlock script, you have to edit the SponsorBlock Lua script, and open it in your preferred text editor :
# Vim editor users vim ~/.config/mpv/scripts/sponsorblock.lua # Nano editor users nano ~/.config/mpv/scripts/sponsorblock.lua
As you can see, in the 17th line, I’ve set the categories ‘sponsor’, ‘selfpromo’, and ‘outro’ to get skipped automatically, but you can set it as per your preference (as mentioned in the 14th line).
I’ve also set local_database to be turned off because it was throwing some error and I have not figured out the solution yet. You can try playing some videos before disabling this category.
Press the escape key to exit the insert mode if you are using vim and then type :wq to save and exit out of vim, if you are using nano then press Ctrl+O and Ctrl+X to save and exit respectively.
Set up the mpv.conf file
Because we are using Yt-dlp instead of YouTube-dl, we have to make a slight edit to our mpv.conf file. Open the file with your favourite text editor by typing the following command :
# For Vim Users vim ~/.config/mpv/mpv.conf # For nano Users nano ~/.config/mpv/mpv.conf
Add the following lines :
# Youtube Support script-opts=ytdl_hook-ytdl_path=#PATH ytdl-format=bestvideo[height<=?720][fps<=?30][vcodec!=?vp9]+bestaudio/best
In the above script, I have specified the default video quality of the player to be set as 720p30fps, however, you can set it as per your preference. Note that you have to change the #PATH variable mentioned in the above command, you can find the path of yt-dlp by running :
Try playing a YouTube video in MPV
There are two methods through which you can play any online video in MPV, you can type in the Terminal :
Or you can drag-and-drop the link to Player’s Interface, the first method is recommended because you can view any errors in the terminal if MPV has trouble playing any file.
What makes MPV really powerful is its reliance on Lua scripts, anyone can develop them, and you can choose what features you want to have in your video player. Playing the videos in MPV has a lot of advantages over a web browser because it saves you a lot of system resources that a web browser will use. Also, you will also save yourself from a lot of trackers which track you on different websites.