How to download, convert and play videos from the terminal.

Youtube-dl screenshot

youtube-dl allows you to configure video downloads from different sites.

Most of us are used to using programs with a graphical interface. However, there is a large number of programs that are used from the terminal and that are very useful.

In this post we analyze two tools to download, convert and play videos. Youtube-dl takes care of the video, audio and subtitle downloads, while FFmpeg takes care of the conversion and playback.

Downloading videos with youtube-dl

Youtube-dl is a tool written in Python that allows you to download YouTube videos. Also, it works with similar sites such as Dailymotion, Photobucket, Facebook, Yahoo, Metacafe, and Depositfiles.

The youtube-dl application Supports resuming of interrupted downloads. Therefore, if you close the terminal or lose the connection, youtube-dl can be re-run with the same video url. The unfinished download will resume, as long as there is a partial download in the current directory.

Other features of the program are:

  • Allows bypass geographic restrictions, as a result we will be able to download videos that would only be possible to watch using a VPN.
  • It can select between different formats Of video.
  • Possible choose between different video qualities available.

In general, it is preferable to use the url that Youtube shows us in the share menu, instead of the one we see in the browser bar.

Download and install youtube-dl.

Although the program is in the repositories, that version gives some problems. It is best to download it from the project page.

We use this command:
sudo wget -O/usr/local/bin/youtube-dl

We give you the necessary permits

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

The basic download command is:
youtube-dl url_video

Youtube videos are in different formats, it is possible to view them with the command
youtube-dl -F url_video

The output of this command is a list with the different formats and qualities with a numeric identifier. Once selected we do:
youtube-dl -f N url_video
Where N is the identifier number.

In case we want to download a playlist, the corresponding command is:
youtube-dl -cit url_lista

To download only the audio
youtube-dl -x url_video

Meanwhile, if we want to download it in mp3 format
youtube-dl -x --audio-format mp3

Unless instructed otherwise, youtube-dl downloads the files to your personal folder. It is important, for a matter of neatness, to use a specific folder. For example, the Videos folder.

Before downloading the video, use the command

cd Vídeos

In case your distribution does not include this folder you can create it with:

mkdir Vídeos

Then run the above command.

Working with downloaded videos

To start working with the downloaded videos, we must bear in mind that the title formats used by Youtube are not compatible with the Linux terminal commands. So we are going to cheat using the graphical interface for once.

  • First: We hover over the downloaded file.
  • Second: click on Properties.
  • Third: We change the name to a simple one and press Enter.
Screenshot of the properties of a video downloaded with youtube-dl

To work with FFmpeg you have to modify the title of the downloaded file with youtube-dl.

FFmpeg is a set of open source codecs and tools for working with multimedia files. We can find it in the repositories of all Linux distributions.

To start learning about this tool, let's see some basic commands:

In case you want to get information from the video
ffmpeg -i nombre_del_archivo -hide_banner

The last part of the command is to prevent FFmpeg from displaying information about the versions of the programs used.

Convert a video to frames
ffmpeg -i video.flv fotograma%d.jpg

Although it is a video site, YouTube makes a good repository for audiobooks and music. To start taking advantage of them, this command that converts downloaded files into mp3 format can be useful.

ffmpeg -i nombre_video -vn -ar xxx -ac x -ab xxx -f xxx nombre_audio

-ar Sets the audio sample rate in Hz.
-ac Sets the number of audio channels.
-ab Sets the audio bit rate
-f Set the format

These are generally suitable parameters for conversion,
ffmpeg -i video.formato -vn -ar 44100 -ac 2 -ab 192 -f mp3 audio.mp3

Convert between video formats
ffmpeg -i nombre_video.formato nombre_video.formato

For example, to convert a video from the .flv format to the .mpg format we do:
ffmpeg -i video.flv video.mpg

It is also possible to add audio to a video. The merge is achieved as a result of this command:
ffmpeg -i audio.formato -i video.formato resultado_mezcla.formato

Increase playback speed
ffmpeg -i video.mpg -vf "setpts=0.5*PTS" archivo.formato

On the contrary, to reduce the playback speed we do:
ffmpeg -i video.mpg -vf "setpts=4.0*PTS" archivo.formato -hide_banner

Finally we can play a file
ffplay nombre_video

The content of the article adheres to our principles of editorial ethics. To report an error click here.

Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.