Sunday, 4 December 2011

download youtube video in ubuntu and convert them to mp3 with ffmpeg

I have compiled ffmepg following this article in Ubuntu forums http://ubuntuforums.org/showthread.php?t=786095 I should say this is one awesome guide, i have seen. This reply clarifies a bit more on the instructions on the  link above http://ubuntuforums.org/showpost.php?p=11243462&postcount=1839 . I gathered this shell script from ubuntu forum which automates the converstion of mp4 or flv to mp3 format. Let me explain a bit more about this youtube download in ubuntu. First install youtube-dl with
sudo apt-get install youtube-dl
The update it to latest version by
sudo youtube-dl -U
The download your favourite songs from youtube via
youtube-dl -o "%(stitle)s.%(ext)s" http://some-youtube-url/

This -o option tells youtube-dl to save the downloaded video in alphanumberic title (aka simplified title) with the extension it is downloaded as . Such as flv or mp4, etc.

Once it is downloaded you can use the following one liner bash script to convert flv or mp4 to mp3

for f in *.flv; do /home/ashwin/ffmpeg/ffmpeg -i "$f" -acodec libmp3lame -ab 128k "${f%.flv}.mp3"; done
 and
for f in *.mp4; do /home/ashwin/ffmpeg/ffmpeg -i "$f" -acodec libmp3lame -ab 128k "${f%.mp4}.mp3"; done

replace the path for ffmpeg to the right path as you compiled in your PC. I noticed that previously in natty the codec was mp3 and now in oneirc it is libmp3lame. Why the *&^%$$#$ do they change this. 

No comments:

Post a Comment