YouTube, FFMPEG, and MP3 Conversion

By  on  
Rod Stewart and Ron Wood

Yesterday I published a quick post about a basic MPEG -> FLV video conversion method using FFMPEG. Today I want to share another great usage of FFMPEG: stripping a video's audio and creating an MP3. As an added bonus, I'll be ripping the audio from a great YouTube video using youtube-dl, a python script with loads of options for downloading YouTube videos.

The youtube-dl Shell Script

#command
davidwalsh83$ youtube-dl.py http://www.youtube.com/watch?v=tlWpnLdPwvk

#output
[youtube] Setting language
[youtube] tlWpnLdPwvk: Downloading video webpage
[youtube] tlWpnLdPwvk: Extracting video information
[youtube] tlWpnLdPwvk: URL: http://www.youtube.com/get_video?video_id=tlWpnLdPwvk&t=vjVQa1PpcFMZ4TkTSYXamGxmLZq-ot2l8Jx-HiNAf0I=&el=detailpage&ps=
[download] Destination: tlWpnLdPwvk.flv
[download] 100.0% of 18.78M at   53.98k/s ETA 00:00

The initial install of youtube-dl was tough but only because I'm not well-versed with the permissions side of Unix. I eventually figured it out but if you have trouble installing youtube-dl or simply want to use its advanced options, check out youtube-dl's documentation. youtube-dl also provides an option to read a text file with a list of videos and will do a batch download. Note: youtube-dl allows you to set an output file name but it didn't appear to be working. If you'd like a more simple method, Mark Sanborn wrote a great post on ripping YouTube videos using wget.

The FFMPEG Shell Script

davidwalsh83$ ffmpeg -i tlWpnLdPwvk.flv RodStewartMaggieMay.mp3

As I did with youtube-dl, I chose the most basic usage of FFMPEG. FFMPEG's documentation provides you a list of all of the possible conversion options if you need them.

The Result

[audio:RodStewartMaggieMay.mp3]

Use the video player above to listen to the result. The video I chose is a live version of Maggie May by Rod Stewart recorded at Royal Albert Hall in the Knightsbridge area of the City of Westminster, London, England. The video is from Rod's One Night Only DVD which I HIGHLY recommend. This is the best version of Maggie May that exists (my opinion but, as you know, when is my opinion not correct?) Enjoy!

Recent Features

  • By
    CSS Filters

    CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...

  • By
    CSS 3D Folding Animation

    Google Plus provides loads of inspiration for front-end developers, especially when it comes to the CSS and JavaScript wonders they create. Last year I duplicated their incredible PhotoStack effect with both MooTools and pure CSS; this time I'm going to duplicate...

Incredible Demos

  • By
    DWRequest: MooTools 1.2 AJAX Listener & Message Display

    Though MooTools 1.2 is in its second beta stage, its basic syntax and theory changes have been hashed out. The JavaScript library continues to improve and become more flexible. Fellow DZone Zone Leader Boyan Kostadinov wrote a very useful article detailing how you can add a...

  • By
    Fading Links Using jQuery:  dwFadingLinks

    UPDATE: The jQuery website was down today which caused some issues with my example. I've made everything local and now the example works. Earlier this week, I posted a MooTools script that faded links to and from a color during the mouseover and mouseout events.

Discussion

  1. Fabian

    Python ftw.

  2. Your FFmpeg code needs the -vn option so it doesn’t render the video. I believe it will be faster with the following code:

    $ ffmpeg -i tlWpnLdPwvk.flv -vn -acodec copy RodStewartMaggieMay.mp3

    All youtube flv audios are encoded in mp3 format, so a simple copy will reduce some unneeded tasks..

  3. Cool..working !!

  4. Of course it works!

  5. down my app http://www.bytesdesign.com.br/YouRiper.exe

    it’s is open source and coded in PHP

    …down the video files and convert into mp3

  6. Thanks for your work on these tools. I use them a lot and they work great!

  7. Juan Maia

    GREAT STUFF!

  8. Hey david,

    Very cool tips here…

    Great! very helpful…

    Thanks

  9. Thanks…this works for me

  10. David I would like to thank you personally for posting these great tools, they helped me a lot to grow my ringtones community and continue to do so!

  11. Did youtube modify their FLV files so that ffmpeg gives a “Unknown Format” Error ?

  12. Thanks, it worked for me. ;)

  13. How can i use this script with php?

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!