In many scenarios we may need to play media from the terminal. This can be achieved with Mplayer and mpv, two great media players for Linux terminal, this tutorial focuses on them.NOTE: It is important to highlight a bug that prevents several terminal media players from playing as root users by default, for this tutorial, except for installations, please use unprivileged users. Another point to clarify is mplayer requires a lot of troubleshooting to play remote videos on websites secured with SSL. While this tutorial shows how to play media in Linux terminal locally for Mplayer and Mpv, with Mplayer I will show how to play videos on http websites, while with Mpv I will show how to play videos on https websites such as Youtube.To begin lets download mplayer by running:

Playing media in Linux terminal Media Players Utilities

# mplayer What is Kubernetes.mp4

Playing media in Linux terminal Media Players Utilities

A new window will open showing the video (in this case the video “What is Kubernetes’ ‘ from LinuxHint’s Youtube channel.

Playing media in Linux terminal Media Players Utilities

With your keyboard arrows you can manage the video position and you can pause it with your Space key on the keyboard.

Playing remote media from websites from Linux terminal:

Now you’ll see how to play videos from websites in your Linux terminal. The first way using mplayer is almost obsolete and only allows playing videos without SSL certificates, later you’ll see how to play videos on secured websites. To continue we need to edit the mplayer configuration file in the user home we are playing with. With nano or any text editor edit the file located at /.mplayer/config

In my case:

# nano /home/linuxhint/.mplayer/config

Playing media in Linux terminal Media Players Utilities

Within the configuration file add the line:


lirc=no

As shown below:

Playing media in Linux terminal Media Players Utilities

Press CTRL X and Y to save and exit.

Now we can test it:

# mplayer http://www.aemet.es/documentos_d/eltiempo/prediccion/


videos/202002121902_videoeltiempoAEMET.mp4

Playing media in Linux terminal Media Players Utilities

Playing media in Linux terminal Media Players Utilities

And the video shows up.

Another terminal media player is mpv which is based on mplayer, to install it on the terminal run:

Playing media in Linux terminal Media Players Utilities

Once installed to play a video just run:

In this case:

# mpv What is Kubernetes.mp4

Playing media in Linux terminal Media Players Utilities

To play remote media files, for example for Youtube we need a workaround first, on the terminal run:

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

Playing media in Linux terminal Media Players Utilities

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

Playing media in Linux terminal Media Players Utilities

Playing remote videos from a specific timestamp is also possible with Mpv using the following syntax:

# mpv –start=05:00 https://www.youtube.com/watch?v=IMOZCDhH7do

Playing media in Linux terminal Media Players Utilities

The command above will play the specified video form the minute 5. You can edit the start time by editing the –start=05:00 option.

Additional tips:

By pressing the key f, you can make the video Full screen, you can restore the default size by pressing the f again or ESC, these options are the same for Mplayer. By pressing Ctrl and Ctrl – you can increase and decrease the audio speed, it is useful when the audio and video speed don’t match. With keys r and t you can change the subtitles position.

You can find more options for MPV player at its man page or online at https://manpages.debian.org/jessie/mpv/mpv.1. For Mplayer options you also see https://linux.die.net/man/1/mplayer.

Additional terminal media players:

Another option to play media from the Linux console is mpg123, You can install it by running:

Playing media in Linux terminal Media Players Utilities

There are also exclusive music players, without support for videos such as Music Player Daemon.

Conclusion:

Playing videos from terminal is a good solution, yet the default program configurations fail to play most popular video websites such as Youtube, all users from all OS, Windows, MacOS and Linux, for which the mentioned programs are available, report difficulties with customized solutions to achieve terminal remote playing. For ssh sessions the best option remains to copy the media files into the local device to play.

For remote playing videos, troubleshooting process includes editing the /etc/.config/mpv/mpv.conf with “no-ytdl”, if necessary you will need to create mpv’s configuration file. In other cases the no-ydl will need to be disabled to play, this option is used to bypass the  built-in ytdl_hook.lua file which sometimes brings problems. You may also need to downgrade your ytdl, you can achieve it by running “sudo pip install youtube_dl==2017.07.30.1”.

Vlc Player, despite isn’t a terminal video player, remains the best option for remote media playing, if you need help with VLC LinuxHint has 2 clear articles for you to read at https://linuxhint.com/install-vlc-media-player-2-2-x-linux/ and https://linuxhint.com/vlc-media-player-for-linux/.

I hope you found this tutorial on Playing media in Linux terminal useful. Keep following LinuxHint for more tips and updates.

About the author

Playing media in Linux terminal Media Players Utilities

Ivan Vanney

Ivan Vanney has over 2 years as writer for LinuxHint, he is co-founder of the freelance services marketplace GIGopen.com where he works as a sysadmin.