How to Download YouTube Video and Convert it to Mp3
So you stumble across the music that you like in YouTube, but you don’t want to listen to it in YouTube because it will suck the battery of your device and you can’t turn off your screen because the song will stop. So here goes the instruction that will allow you to download the video from YouTube and strip the Audio out.
Step 1. Download YouTube Downloader
This is a free open source program called youtube-dl, which allows you to download the video from YouTube. You can follow the instructions on how to install it. I have homebrew installed on my mac so I type the following command in the command prompt.
brew install youtube-dl
Step 2. Download the song that you like using youtube-dl
Find the song that you like, and copy the song from the URL, then use the following command to download the song.
youtube-dl "https://youtu.be/pBYndbX2szU"
In the example above, I am using my video as an example video that you want to download. The song should start downloading once you hit enter as shown in the following picture.
Note that the video extension can varies, depends on the quality of the video uploaded by the author. Most of the time it is .MKV, but it can also be .webm or some old one is a flash video.
Once the script is completed you will have the song located in the folder where you have executed the script.
Step 3. Strip the Audio
Now that you have the downloaded video, you can try to play it using your favourite media player like VLC or Quicktime video. VLC might be the best, as you will not have to worry about the different codec the video have been encoded in. Download the stripaudio bash script.
Extract it, and change the permission to be executable using the following command
chmod 755 stripaudio
You can double check using ls -la command to make sure that the script is now executable. This script is using ffmpeg library to strip the audio from the video file. Now you can execute the script with the following command
./stripaudio youtubevideo.mkv
The above command is assuming the video file name is youtubevideo.mkv. You can just answer “Y” on the prompt. Once the script is complete the audio file should be located in the same folder as the video file with the same name but with mp3 extension.
You can watch the whole process in the following youtube video:
I hope you enjoy the music that you have downloaded, and if you want to split the audio file into multiple mp3, you can follow my previous post on how to automatically split audio file or you can watch the video below:
Thank you for reading until the end, and hit the subscribe if you like what I did, this will encourage me to do more.