| by Arround The Web | No comments

Playing Media in Linux Terminal (Including Youtube)

This tutorial explains how to play media from the Linux terminal in Linux, including Youtube.

In many scenarios, we may need to play media from the terminal. After reading this tutorial, you will know how to play local media and how to play and download Youtube media from the Linux console.

Except for installation method examples, made on Debian, this content is valid for all Linux distributions.

Playing Media in the Linux Console With Mplayer

The first section of this tutorial explains how to play local media using the Mplayer text mode media player.

Before installing Mplayer, make sure you have pip installed. On Debian based Linux distributions, run the command shown in the screenshot below.

sudo apt-get install python3-pip

Once pip is installed, proceed to install Mplayer by executing the following command:

sudo apt install mplayer

The syntax to play a mp3 file is the following, where <AudioName> must be replaced with the name of the file you want to play.

mplayer <AudioName>.mp3

In my case, I run the following command to play a Pink Floyd song:

As you can see in the following figure, the media starts to play.

Playing videos requires the same syntax. For example, to play a mp4 file, run the following command:

mplayer <VideoName>.mp4

In this example, I will play a mp4 video. A new window playing the video will show up.

Mplayer supports a lot of formats. To play them, just execute mplayer followed by the file you want to play.

How to Play Youtube From the Linux Terminal

This section shows how to play Youtube from the Linux console using two different methods: a text mode interactive one, featured by the ytfzf utility; and a command line one using the mpv media player.

One of the best tools to play Youtube in the Linux console is the interactive ytfzf, which can be installed from repositories.

To install ytfzf on Debian based Linux distributions, execute the following command:

sudo apt install ytfzf -y

Once ytfzf is installed, run it as shown below. This command will execute ytfzf returning a Search prompt.

ytfzf

Type the name of the media you want to play. In my example I type “pink floyd” to list Pink Floyd related media. Type your choice and press ENTER.

Use the keyboard arrows to select the song or video you want to play and press ENTER.

As you can see in the following screenshot, a media playing window shows up.

The second method to play Youtube from the console requires the mpv media player, which is already included by default in many Linux distributions.

Debian based distribution users can install mpv by running the following command:

sudo apt install mpv

Once installed, just execute it followed by the URL of the media to play using the following syntax:

mpv <URL>

For this example, I will play the following Youtube video.

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

With mpv, you also can define the start timing of the media using the following syntax:

mpv --start=<Minutes>:<Seconds> <URL>

In the example below, I will play the same video starting from minute 1:00.

mpv --start=01:00 https://www.youtube.com/watch?v=IMOZCDhH7do

Some mplayer and mpv Tips

By pressing the F key, you can make the video Full screen. You can restore the default size by pressing back F 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.

That’s how you can use the Linux terminal to browse Youtube media, or to play it with a link.

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

Download Youtube Media From the Linux Terminal

The previous examples show how to play local and remote media from the console.

This section explains how to download media to your computer. The youtube-dl tool used in this section is also useful for other sites than Youtube.

To install Youtube-dl on Debian based Linux distributions, run the following command:

sudo apt install youtube-dl -y

Once installed, just execute youtube-dl followed by the URL of the media you want to download.

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

When the download process ends, play the file using any media player you want, like Mplayer, as shown below.

mplayer <FileName>

That’s how you can get music from the terminal to play offline.

Conclusion

Playing media from the Linux terminal is extremely easy, and so comfortable as playing it from the graphical environment. Any Linux user, even if not familiar with the Linux console, can play both local or remote media by following a few steps as described above. The market offers several other alternatives to play music and videos from the console, this article focused on the most popular ones available for every Linux distribution. You can also combine terminal and graphical players to work together, for example, when playing videos, you can define VLC as default player.

Thank you for reading this article explaining how to play media in the Linux console. Keep following us for additional Linux professional content.

Share Button

Source: linuxhint.com

Leave a Reply