I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.
A few days ago my blog reader, Ankush Agarwal, on the comments of downloading youtube videos with gawk article asked:
I’ve seen tools available to download just the audio from a youtube video, in various formats; but as per your explanation it seems, that the audio is integrated with the video in the .swf file. How can we extract only the audio part and have it converted to a format like mp3?
As I have written a few articles before on how to download YouTube videos with Perl, gawk and VBScript, and how to convert the downloaded flash video files (flv) to divx or xvid, or any other format with ffmpeg, it was very easy to help this guy.
This is a guide that explains how to extract audio tracks from any videos, not just YouTube.
First, lets download the ffmpeg tool (that’s for Windows Operating System. If you are using linux operating system, you can get the ffmpeg tool as a package distribution) and open the ffmpeg documentation in another window.
Lets choose a sample video which we will extract the audio track from. I found some music video clip “My Chemical Romance - Famous Last Words” (http://www.youtube.com/watch?v=8bbTtPL1jRs).
Now, lets download the music video. If you are on a windows machine, you may use my VBScript program to download the video (download vbscript youtube video downloader, read how to use it here), or if you are on linux, you may use gawk program to download the video (download gawk youtube video downloader, read how to use it here).
After downloading the video, I ended up with a file named My_Chemical_Romance_-_Famous_Last_Words.flv.
Once you have downloaded the video, just for the sake of interest, lets find out the audio quality of this You Tube audio video.
The ffmpeg documentation does not tell us about a switch which would just output the audio parameters of the input file. After experimenting a little with the ffmpeg tool, it can be found that by just specifying ‘-i’ switch and the input video file, the ffmpeg will output input streams information and quit.
Here is an example of how it looks:
c:\> ffmpeg.exe -i My_Chemical_Romance_-_Famous_Last_Words.flv Seems that stream 1 comes from film source: 1000.00 (1000/1) -> 24.00 (24/1) Input #0, flv, from ‘My_Chemical_Romance_-_Famous_Last_Words.flv’: Duration: 00:04:27.4, start: 0.000000, bitrate: 64 kb/s Stream #0.0: Audio: mp3, 22050 Hz, mono, 64 kb/s Stream #0.1: Video: flv, yuv420p, 320×240, 24.00 fps(r) Must supply at least one output file
From this information (2nd line in bold) we can read that the audio bitrate of a YouTube video is 64kbit/s, sampling rate is 22050Hz, the encoding is mp3, and it’s a mono audio.
You will be surprised how easy it is to extract the audio part as it is in the video. By just typing:
c:\> ffmpeg.exe -i My_Chemical_Romance_-_Famous_Last_Words.flv famous_last_word.mp3
the ffmpeg tool will extract it to an mp3 audio file!
That’s it! After running this command you should have ‘famous_last_words.mp3‘ file in the same folder/directory where the downloaded video file was!
We can go a little further and look up various audio switches on the documentation of ffmpeg. For example, if we had some fancy alarm clock which can be stuffed an mp3, you might not need the whole 64kbit/s of bitrate. You might want to convert the audio to a lower bitrate, say 32kbit/s.
The Section 3.5 - Audio Options of the ffmpeg documentation says:
`-ab bitrate‘ - Set the audio bitrate in bit/s (default = 64k).
So, by specifying a command line switch ‘-ab 32k‘ the audio will be converted to a lower bitrate of 32kbit/s.
Here is the example of running this command:
c:\> ffmpeg.exe -i My_Chemical_Romance_-_Famous_Last_Words.flv -ab 32k famous_last_word.32kbit.mp3 [...] Seems that stream 1 comes from film source: 1000.00 (1000/1) -> 24.00 (24/1) Input #0, flv, from 'My_Chemical_Romance_-_Famous_Last_Words.flv': Duration: 00:04:27.4, start: 0.000000, bitrate: 64 kb/s Stream #0.0: Audio: mp3, 22050 Hz, mono, 64 kb/s Stream #0.1: Video: flv, yuv420p, 320x240, 24.00 fps(r) Output #0, mp3, to ‘famous_last_word.32kbit.mp3′: Stream #0.0: Audio: mp3, 22050 Hz, mono, 32 kb/s Stream mapping: Stream #0.0 -> #0.0 size= 1045kB time=267.6 bitrate= 32.0kbits/s video:0kB audio:1045kB global headers:0kB muxing overhead 0.000000%
The line in bold indicates that the output audio indeed was at a bitrate of 32kbit/s.
Some other things you can do are - changing the codec of the audio (-acodec option (find all codecs with -formats option)) or cut out a part of the audio (-t and -ss options) you are interested in.
This technique actually involved re-encoding the audio which was already in the movie file. If you read closely the audio option documentation, you will find that the -acodec option says:
`-acodec codec’ - Force audio codec to codec. Use the copy special value to specify that the raw codec data must be copied as is.
If the input video file was from YouTube or it already had mp3 audio stream, then using the following command line, the audio will be extracted much, much faster:
c:\> ffmpeg.exe -i My_Chemical_Romance_-_Famous_Last_Words.flv -acodec copy famous_last_words.mp3
Have fun ripping your favorite music off YouTube! :)
ps. Do you have something cool and useful you would like to accompish but do not have the necessary computer skills? Let me know in the comments and I will see if I can write an article about it!
Did you like this post? Subscribe here:
If you really enjoyed the post, I'd appreciate a gift from my geeky Amazon book wishlist. Books would make me more educated and I could write even better posts. Thanks! :)


(14 votes, average: 3.86 out of 5)
|
|
|


October 28th, 2007 at 8:22 pm
Cool :)
Time to experiment more with ffmpeg…
p.s. the plugin you’re using to detect visitors from google (the search engine) apparently has a bug in it: I’m coming here from Google Reader, yet it mistook me as coming from Google (the search engine).
October 28th, 2007 at 10:19 pm
Yuvi, yeah ffmpeg is neat for neat video conversation stuff.
Thanks for letting me know about this bug. I am going to fix it ASAP.
October 30th, 2007 at 11:14 pm
I found that sometimes time (length) info for an mp3 that I created this way would get hosed up. I’d get a 1:10.45 length from a youtube video (max 10 min or so)., I found that supplying the additional ffmpeg argument “-ss 1:00″ which is used to “set the start time offset” to 1:00 fixes this.
October 31st, 2007 at 4:56 am
For those, who are still getting the error:
Line 73, Char 5: Access is denied. even after adding it to the Trusted list; Try running the script after minimizing the security settings for Trusted sites. It worked beautifully for me, after this change.
October 31st, 2007 at 5:16 am
Thanks, Ankush for figuring this out and telling everyone how to get it working in case of “Access is Denied” Visual Basic Script error. :)
November 3rd, 2007 at 1:24 am
Tubedodger.com allows you view YouTube videos when they are blocked at work or school.
November 9th, 2007 at 11:20 am
TubePress.net is a youtube plugin for wordpress. If you have a wordpress blog and you want to import videos from youtube. Install TubePress.net plugin and here you go, you get the videos posted in your blog ;) Nice, huhh
November 14th, 2007 at 9:41 pm
Any idea how to download Facebook video posts?
November 15th, 2007 at 7:31 pm
That link doesn’t work
November 15th, 2007 at 7:51 pm
Scribs Griswald,
Sure I know. I just can’t do everything. The idea is completely the same - find how the flash player downloads .flv video file, and download that file to your computer.
About your other comment, which link doesn’t work?
November 15th, 2007 at 9:26 pm
Hey there,
Actually there was a link posted by another user but it’s since been deleted. No worries.
And I was just looking for steps in how to do that particular bit of downloading… But I’ll see what i can do with what you’ve explained.
Thanks Peteris!
January 1st, 2008 at 3:01 am
Anybody know a GUI based frontend to ffmpeg or mencoder to encode videos? I came across Winff but it has unexpected results on linux.
January 3rd, 2008 at 11:32 am
Great tutorial! Thanx!
But how can i cut a part of the audio mp3 file of a music video? Let’s say I only want to save a particular part of the song in the video (from minute 2 till 3). How can I do that?
February 3rd, 2008 at 2:37 am
Try MediaCoder for a great GUI for ffmpeg and also other command driven video/audio engines. Does a great job of extracting audio from any video file (including flv of course): www.mediacoderhq.com
Totally open-source, free.
February 6th, 2008 at 12:35 am
in Windows,
using cmdline: ffmpeg -i input1.flv out.mp3
Couldn’t get ffmpeg to work extracting mp3 from
flv…get error:
“seems stream 0 codec frame rate differs from
container frame rate: 1000.00 (1000/1 ) -> 29.97
(30000/1001)”
When I try to extract, up pops a dialog
saying that ffmpeg caused an error in ffmpeg.exe
ffmpeg will now close…if you continue to
experience problems, restart your computer”
? am I alone?
Thanks,
February 11th, 2008 at 1:46 pm
Im having a problem writing the converted audio to cd-rw ive tried a few different burners and all come up with error messages even though the tracks play and they say they are mp3 files !!!!!
any help much appreciated
February 19th, 2008 at 12:37 am
i am normalizing to 20% with cooledit pro after conversion, after i save them they are perfect
April 3rd, 2008 at 7:05 am
If you are “normalizing” the files with another program you are in fact transcoding them and thus wasted the whole point of doing the extraction this way in the first place. If you need to adjust the volume of the mp3s you’ve extracted then use MP3Gain ( http://mp3gain.sourceforge.net/ ) or ReplayGain.
If you want to cut the resulting file down to a particular song/section use mp3DirectCut ( http://mpesch3.de1.cc/mp3dc.html ) which will crop mp3s without transcoding them.
If the mp3s you extract have bogus VBR headers that display about 10x the song length as it really is you can fix them with foobar2000 on Windows. It’s in the [right click menu -> Utils -> Fix MP3 VBR Header]. Don’t know how to do that on Linux.
April 6th, 2008 at 11:48 pm
Thanks for tips, Tripmaster G!
May 16th, 2008 at 10:06 am
YouTubeRobot.com today announces YouTube Robot 2.0, a tool that enables you to download video from YouTube.com onto your PC, convert it to various formats to watch it when you are on the road on mobile devices like mobile phone, iPod, iPhone, Pocket PC, PSP, or Zune.
YouTube Robot allows you to search for videos using keywords or browse video by category, author, channel, language, tags, etc. When you find something noteworthy, you can preview the video right in YouTube Robot and then download it onto the hard disk drive. The speed, at which you will be downloading, is very high: up to 5 times faster than other software when you download a single file and up to 4 times faster when you download multiple files at a time.
Manual download is not the only option with YouTube Robot. You may as well schedule the download and conversion tasks to be executed automatically, even when you are not around. Downloading is followed by conversion to the format of your choice and uploading videos to a mobile device (if needed). For example, you can plug in iPod, select the video, go to bed, and when you wake up next morning, your iPod will be ready to play new YouTube videos.
Product page: 3w.youtuberobot.com
Direct download link: 3w.youtuberobot.com/download/utuberobot.exe
Company web-site: 3w.youtuberobot.com
E-mail: support@youtuberobot.com
July 25th, 2008 at 5:37 pm
[…] How to Extract Audio Tracks from YouTube Videos - good coders code, great reuse (tags: audio codec hacks howto programming Software video youtube ffmpeg tips mp3) […]
August 5th, 2008 at 5:56 pm
for the lazy one: Sound Converter( a.deb on ubuntu), not bad, convert directly to OOG, mp3, FLAC, WAV , basic config, works well on UTube’s .flv’s
August 20th, 2008 at 10:24 am
An even easier way is just type in the youtube into http://vixy.net/ and select output as MP3 only.
Jobs a goodun, only need to download 1 thing.
September 4th, 2008 at 8:48 pm
I am trying to convert an Audio file to MIDI file. What I need in the MIDI file is only the voice track and not the background music etc. I tried various software but was not successful. The process was complex and the output was bad.
Can you please educate what is the best way?
December 11th, 2008 at 7:08 am
Hi,
I have a question that i hope you can answer, or at least point me in the right direction were i can look up the info.
Is there a way to get the server, that serves the .flv or .swf or any other audio+video media content files, to serv the audio stream only?
This way one can enitially listen only to the audio stream, and not waste the bandwidth for the undesired video.
December 11th, 2008 at 11:22 pm
Hi Matthew. I answered your question via email, but I’ll also copy the answer here:
Sure, it’s possible. Except it’s computationally expensive. The solution is to use some kind of a filter that stands before .flv and your web server.
[file.flv] <-> [filter program] <-> [web server] <-> [client]
[client] makes request to [web server]
[web server] runs [filter program]
[filter program] takes [file.flv] and starts extractiju JUST the audio stream and returns data to [web server]
[web server] sends data back to [client]
This program may seem tricky to write but is pretty straight forward! It could be even an ffmpeg (output file specified as stdout)!
You may trade computation, however, for space, i.e., extract mp3’s out of .flv’s as I explained in my article and then just serve the mp3’s!
January 22nd, 2009 at 8:58 pm
[…] by 8bitsofcoffee on January 22nd, 2009 I found this great tutorial by Peteris Krumins here, and thought I would quickly share the steps without getting into technicalities. Check out the […]
February 25th, 2009 at 8:22 pm
i want to know abt how to download from “video.yahoo.com “as seen .
May 12th, 2009 at 8:47 pm
another very good and fast service is the youtube to mp3 service (hq option available)
May 21st, 2009 at 5:24 pm
Thank you…
But i found “Zillatube” program download video quickly, and also easy to play those videos too.
found it at… http://www.zillatube.com
June 1st, 2009 at 8:33 am
At one time YouTube used ffmpeg and its libraries and could not have survived without them. Maybe they still do. I doubt it. I think F. Bellard is a genius. Consider also qemu, tcc, etc.
Small and powerful.
June 8th, 2009 at 5:44 am
Everyone knows how to download the video first then convert it…Sharing that is redundant!
(you can find thousands of web pages telling you how to do that!)
The original question was: How to download ONLY the audio (without having to download the flv video) from sites like YouTube.
If you’ve got the answer to that, then PLEASE share widely.
June 22nd, 2009 at 9:40 am
How to rip audio from YouTube
July 6th, 2009 at 5:54 pm
I did everything, but when I try to take the audio from the video I get this:
Stop_-_Wake_Up_1985.flv: no such file or directory
Yet it’s right there on my desktop! (Or do I need to put it elsewhere? I checked the name carefully to make sure I typed it correctly, too)
Please help.
August 14th, 2009 at 7:45 pm
[…] How to Extract Audio Tracks from YouTube Videos: http://www.catonmat.net/blog/how-to-extract-audio-tracks-from-youtube-videos/ […]
September 27th, 2009 at 1:57 pm
gawk -f get_youtube_vids.awk http://www.youtube.com/watch?v=317eucC
SL3s
Parsing YouTube video urls/IDs…
Getting video information for video: 317eucCSL3s…
Could not get video_url for video: 317eucCSL3s
Please goto my website, and submit a comment with an URL to this video, so that
I can fix it!
Url: http://www.catonmat.net/blog/downloading-youtube-videos-with-gawk/
November 7th, 2009 at 10:22 am
I have a few live concerts that I cannot find cd s for. I want to rip audio from it but it rips it into 1 track which means I cannot skip a song and have to wait till it comes around. I can sit and edit the whole track(sometimes up to 2 hours long but its a battle. any programme that I can use to rip it into specific tracks? I am 51 years old and do not always understand the technical language that you young guys use so please be patient!!!!!!!!!!email address: leondutt@gmail.com
November 26th, 2009 at 10:59 pm
For who is having problem in file conversions try this 2 sites.
www.freefileconvert.comt and
www.convertvideotoaudio.com
The sites are fast and simple to use
December 16th, 2009 at 8:13 pm
You can rip tracks from You Tube with Cool Edit Pro, if the quality track of the video is 320 Kbps you will have a 320 Kbps audio track (If you do everything in the right way). After you do it, compare the size of the audio track you ripped with a original track (downloaded from a digital store) and then compare the sound. Just deppens on the quality audio of the video.
December 29th, 2009 at 5:41 pm
Found a Site to download youtube videos online
http://TubeZen.com
Its one of the best online converter.
No Software needed.
Its Simple, Safe and Easy.
Its 100% FREE.
January 22nd, 2010 at 1:11 pm
I use Youtube Downloader HD
http://www.youtubedownloaderhd.com/
and then edit them in TrakAxPC pro
http://www.trakax.com/software/pc/
January 26th, 2010 at 8:29 am
Anyone know how to set the mp3 Lame library’s output buffer? -bufsize doesn’t do it. ‘Cuz I’m getting:
[libmp3lame @ 0197c010]lame: output buffer too small (buffer index: 9404, free bytes: 388)
Audio encoding failed
… for an error, no matter what I set the bufsize to.
(And Leon, psst, Leon… don’t ever post your email on line. Even if you can avoid spam, you’re going to get billions of spam. Just like this page does.)
February 28th, 2010 at 10:58 pm
I am trying to convert an Audio file to MIDI file. What I need in the MIDI file is only the voice track and not the background music etc. I tried various software but was not successful. The process was complex and the output was bad.
Can you please educate what is the best way?