How to download and convert Youtube videos to mp3, in Ubuntu Linux

This post describes how to download and convert Youtube videos to mp3, in Ubuntu Linux. Please note that this is not an encouragement to copyright infringement, I use these tools for downloading and listening to videos on my long commute with the London Underground, where no GSM or Wifi signal are available.


youtube-dl  – "is a small command-line program to download videos from and a few more sites."

ffmpeg – "is a complete, cross-platform solution to record, convert and stream audio and video.", required by youtube-dl.

libavcodec-extra-53 – Libav codec library, required by youtube-dl for converting files to mp3.


sudo apt-get install youtube-dl

sudo apt-get install ffmpeg

sudo apt-get install libavcodec-extra-53


The following script (, will download videos based on URLs stored in a text file (tracks.lst):

while read line
  	echo -e "Downloading '$line'..."
	youtube-dl -q --console-title --extract-audio --audio-format=mp3 -o "%(title)s.%(ext)s" $line
done < tracks.lst


  1. Upon first-time use, set the executable file permission: chmod +x
  2. Edit tracks.lst, and add URLs, one per line. E.g.:
  3. Execute: ./

Resulting files should be stored with the name [Youtube Title].mp3, residing in the same folder as the script.

NOTE: If you do not wish to convert files to MP3, remove the "–extract-audio –audio-format=mp3" parameters in the above script.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.