extract mp3 audio track from youtube video

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, 320x240, 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!


October 28, 2007, 20:22

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 28, 2007, 22:19

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.

terminal mxga Permalink
October 30, 2007, 23:14

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.

andrew ndaba Permalink
May 08, 2011, 17:18

this is very confusing and complex for an ordinary user or should I say for a person that's not a computer freak or IT tech...

October 31, 2007, 04:56

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 31, 2007, 05:16

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 03, 2007, 01:24

Tubedodger.com allows you view YouTube videos when they are blocked at work or school.

November 09, 2007, 11:20

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

Scribs Griswald Permalink
November 14, 2007, 21:41

Any idea how to download Facebook video posts?

Scribs Griswald Permalink
November 15, 2007, 19:31

That link doesn't work

November 15, 2007, 19:51

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?

Scribs Griswald Permalink
November 15, 2007, 21:26

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 Peter!

January 01, 2008, 03:01

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 03, 2008, 11:32

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 03, 2008, 02:37

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.

Phil D'Agostino Permalink
February 06, 2008, 00:35

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

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?


skipper Permalink
February 11, 2008, 13:46

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

oxygen Permalink
February 19, 2008, 00:37

i am normalizing to 20% with cooledit pro after conversion, after i save them they are perfect

Tripmaster G Permalink
April 03, 2008, 07:05

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 06, 2008, 23:48

Thanks for tips, Tripmaster G!

steveking Permalink
May 16, 2008, 10:06

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

reine Permalink
August 05, 2008, 17:56

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

TechGuy08 Permalink
August 20, 2008, 10:24

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.

Suraj Permalink
September 04, 2008, 20:48

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?

Matthew Permalink
December 11, 2008, 07:08


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 11, 2008, 23:22

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!

girjesh shukla Permalink
February 25, 2009, 20:22

i want to know abt how to download from "video.yahoo.com "as seen .

Monday Permalink
May 12, 2009, 20:47

another very good and fast service is the youtube to mp3 service (hq option available)

Josh Permalink
May 21, 2009, 17:24

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

qnx Permalink
June 01, 2009, 08:33

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.

Specific Permalink
June 08, 2009, 05:44

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.

July 06, 2009, 17:54

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.

Sujan Permalink
September 27, 2009, 13:57

gawk -f get_youtube_vids.awk http://www.youtube.com/watch?v=317eucC
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/

leon Permalink
November 07, 2009, 10:22

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

Salvio Permalink
November 26, 2009, 22:59

For who is having problem in file conversions try this 2 sites.

www.freefileconvert.comt and

The sites are fast and simple to use

Cool Edir Pro Permalink
December 16, 2009, 20:13

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 29, 2009, 17:41

Found a Site to download youtube videos online


Its one of the best online converter.
No Software needed.
Its Simple, Safe and Easy.
Its 100% FREE.

cormac Permalink
January 22, 2010, 13:11

I use Youtube Downloader HD

and then edit them in TrakAxPC pro

Arkadia Permalink
January 26, 2010, 08:29

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 28, 2010, 22:58

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?

tara Permalink
March 14, 2010, 22:50

I am not using windows. I use a macbook with safari etc. Anyone know how I can just get the audio track not the entire video from a youtube video.

mansky Permalink
April 14, 2010, 15:31

if i were rich, i'd send you money. your ffmpeg helped me extract audio from a video file. thanks man.

coli Permalink
May 01, 2010, 04:59

i know this isnt tha place for it...but how do i gt tha video 2 play witout the 'unregistered copy' pic on it

Some Dude Permalink
May 03, 2010, 01:04

Thank you, this helped me a lot.

John Permalink
June 29, 2010, 01:13

A suggestion for converting Youtube to MP3 is Makeitmp3.com. Give it a try it has worked for me

sur Permalink
August 26, 2010, 12:21

Can I use ffmpeg just to extract audio from any flv file.

When I watch a video on youtube, a local version of it saved in /tmp folder. One could save this file for later use. I am wondering how would one use ffmpeg to extract the audio from such 'flv' file where you do not know the audio file name.

sur Permalink
August 26, 2010, 12:23

Btw, Thanks for maintaining such a useful blog. :)
keep up the good work.

sur Permalink
August 26, 2010, 13:11

found the soln to my query..

$ffmpeg -i video.flv -acodec copy video.mp3

the above command will extract the audio from video.flv file and save it as video.mp3.

fornard Permalink
August 31, 2010, 11:29

hi this so good , but i found this software {audio converter extractor max} , and found it on this site http://www.softwaremile.com
i can extract all my audio cd's , and can convert it in the same time ,i can convert any video and audio files also

dhanel Permalink
February 02, 2011, 04:27

i saw few websites which converts directly into mp3 without download it.. do have any idea how they do it?

vid2mp3 Permalink
July 14, 2011, 21:29

you can try VID2MP3 Converter (http://vid2mp3.co), it can download multiple youtube videos and convert them to mp3 files at the same time.

Thad E Ginathom Permalink
October 23, 2011, 09:41

I just realised that you posted this instructions almost exactly four years (and two days) ago --- and it is just the information I needed today :)

Do you use SoX? I discovered it just a few days ago, and if I had used it (soxi just for content information) it would have given me what I needed to know without googling for youtube and bitrate The output is neater and easier to read. I think it handles the audio only, though, unlike ffmpeg

October 23, 2011, 15:19

Oh goodness, 4 years and 2 days ago.

I hadn't heard about SoX before. For everyone who's interested, here is what SoX is: http://sox.sourceforge.net/. Good find!

Mike Permalink
January 03, 2012, 20:09

have you found a way to demux youtube video with just video id . much the same idea as this starts extractiju JUST the audio stream and returns data to [web server]
[web server] sends data back to [client] with out converting the audio from aac on youtube. whats the point of converting to another lossy audio like mp3. for better audio you can use this ffmpeg -qscale 8 command. is there anyway you could get the string of stream #01 or audio and use ffmpeg set param=-vn for just audio. thanks for the info and most of all sharing.

Mike Permalink
January 03, 2012, 20:13

yes i have used sox command line program for years now. great program if enjoy using the command line.

Mike Permalink
January 03, 2012, 20:54

for ones that don't know what the ffmpeg command
-qscale 8 does it tells ffmpeg to use vbr on audio

Red Five Permalink
May 02, 2012, 20:24

Often, YouTube FLVs not only have a fairly low bitrate, but they also have low sample rates as well. I like to use the -ab and -ar switches together. I think YT usually downsamples files to 64Kbps and 22050Hz, so increasing the bitrate and sample rate to at least 160Kbps (I usually start at 192Kbps) and 44100Hz respectively removes much of the high-frequency distortion in most YT vids and at least gives the illusion of a higher-quality audio file.

September 18, 2012, 19:10

======= USE LINUX =======

arshan Permalink
May 01, 2013, 19:15

hey, it's a great article, though i hv a question about it.I'm currently working on a project which involves audio extraction and i'm using java for the purpose.I was wondering if it was possible to use these commands from within a java program ,also it would be a great help if you could give me a tutorial on how to do that if possible.Thanks in advance.

telugu wap Permalink
October 06, 2016, 08:20

Peter Krumins, your post is useful. can you point me to a resource on how to download .mp3 from youtube url using JAVA? how does these online tools work? thanks in advance..

January 11, 2018, 23:14

for ones that don't know what the ffmpeg command
-qscale 8 does it tells ffmpeg to use vbr on audio

Leave a new comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "lcd_34": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.