How to get audio files from Youtube videos

how to get audio files from youtube videos

Getting the audio files from youtube videos, whether a music video or an online lecture, is a task frequently done by many youtube users. And in fact, there are actually many ways to do so, you can either use an online tool like listentoyoutube.com or use a firefox addon like flash video downloader. But as a Linux user, I always prefer doing everything myself. And today I will show you a simple way to get the audio file from any youtube vid with some simple commands in Linux.

To get the audio file from a youtube vid, you will need 2 packages:
- youtube-dl : to download the video
- ffmpeg : to record, convert and stream audio and video

These two packages are very popular so you can download them directly from the respo of any Linux distro.

I will take the song Bad Boys by Inner Circle as an example for this post.

The first thing you have to do is download the video with youtube-dl, you just need to run the following command:

youtube-dl -o badboys.flv http://www.youtube.com/watch?v=S9XEGBrA99E

this command will download the video and name it into BadBoys.flv

After the video has been downloaded, we need to figure out the format of the audio file, the audio format of youtube vids are usually .aac, but to be sure, just run this command:

ffprobe badboys.flv

you will have the following output. You can see in the last line the part Audio: aac, this is the audio format of the video.

how to get audio files from youtube videos


After that, you can extract the audio with minimal quality loss with this command:

ffmpeg -i badboys.flv -vn -acodec copy badboys.aac

Note: if the output of the ffprobe command gives another audio file format, remember to change it in the ffmpeg command.
linux tips and tricks