In my last post I highlighted how you can download youtube videos using a great tool called youtube-dl
In this post we will be covering a few things.
- Downloading youtube videos and later converting them to mp3
- Downloading videos directly as mp3
We will be making use of ffmpeg and youtube-dl for our case.
Just so that you know that you will need to install youtube-dl first on your Ubuntu box. If you haven’t read my previous article please read that from here
You will also need to install ffmpeg. You can install it using the command below
- sudo apt-get install ffmpeg x264 libav-tools libvpx-dev libx264-dev
Downloading video from youtube and converting them to mp3 using ffmpeg
Lets download a video from youtube now. Considering that you are in /home/user/videos directory and you have write permissions to this folder, run this command
- # youtube-dl "http://www.youtube.com/watch?v=C-2MmguSO4w"
Your video will now be stored under /home/user/videos as C-2MmguSO4w.mp4
You can also specify a file name when using youtube-dl as shown below
- # youtube-dl -o myvideo.mp4 "http://www.youtube.com/watch?v=C-2MmguSO4w"
Depending on your download speed it can take a while to download this video.
Just in case if you got error saying “Unable to download” then you would like to read my previous post.
Now we have C-2MmguSO4w.mp4 to work with. Lets convert it to mp3
- # ffmpeg -i C-2MmguSO4w.mp4 -f mp3 -ab 192000 -vn C-2MmguSO4w.mp4.mp3
The above command will convert our mp4 file to a mp3
-ab 192000 in above command means that our mp3 should be encoded at 192Kbps for great quality
-vn means that do not include video
-i means input file name
To know more about ffmpeg command read more here
Downloading videos as mp3 using youtube-dl
Now that we have seen how to mix ffmpeg and youtube-dl together to convert to desired format. We can do pretty much the same stuff with youtube-dl by itself.
Allow me to show you how this is done
Use this command
- # youtube-dl --extract-audio --audio-format=mp3 "http://www.youtube.com/watch?v=C-2MmguSO4w"
And that’s it your video will be downloaded as mp3 now.
I hope that this helps. If you found any error in any of the commands above please let me know as I am also riding on a learning curve and it will be great help if you can offer any improvement to whatever I came up with above.