Extracting an MP3 From a YouTube Flash (FLV) Download…

My wife likes YouTube.

A *lot*.

I had found out how to make MP3 files from the audio sections of the FLV files, so she wanted to know if I could set things up for her to do this on her own.

Of course I said yes.

So, first step was downloading the video from YouTube. That was pretty easy – I installed the UnPlug add-on for Firefox and tested it. I used to use Ook! Video, but it stopped working for me on YouTube. Maybe they changed the site and broke it, I don’t know. Anyway, Unplug seems to work much better, and soon I had the FLV files I was interested in.

Next step was streaming the audio into an MP3 file – I say streaming because the original FLV file is left unchanged – it does not get converted to an MP3, but rather a new MP3 is made from the audio protion of the video file.

For this, I used ffmpeg at the command line. It worked great, and I was able to create OGG and MPG files as well. The command I ran was:

  • ffmpeg -title “my_title” -i filename.flv -acodec mp3 -ac 2 -ab 128 -vn -y filename.mp3

The -i is the input file, -acodec is the type of audio codec to use, -ac is the number of audio channels, -ab is the encoding bitrate, -vn disables video recording, and the -y option overwrites output files. Plenty of other info is here.

Still, even though it worked fine, it is a little clunky to use for multiple files and is well past what I can expect my wife to manage, so I wrote my first *real* bash shell script – youtube2mp3. The script, which I made executable and placed in /usr/local/bin, basically acts within the current working directory, accepting one input parameter – the output directory location. It runs through and extracts an MP3 file for each FLV file, provided that the MP3 file does not already exist in the output directory. The sanity checking it does is limited to determining if the output path (assumed to be a USB MP3 player) exists (is plugged in), and it looks for Control-C to delete the MP3 file currently being encoded and break out of the script. Anyway, here is the scripţ in all its ugly glory:


# Set variables – interrupt, extension1, extension2, and the audio file name
pluginmsg=”$USER, please plug in the MP3 player and try again. Quitting…”

# Set the output directory, so as not to clutter up the folder full of flv files
if [ -n “$1” ]

# Catch Control-C events to break out of the loop and remove the partial audio file
trap ‘echo “Quitting…”; rm -f $audio; exit $USER_INTERRUPT’ TERM INT

# Loop through the working directory and create from xt2 from xt1
mount | grep -i ${outputdir%/} &> /dev/null # Is the MP3 player mounted?
if [ $? = 0 ]
for filename in *.$xt1

if [ ! -f ${outputdir}$audio ] # Does the mp3 already exist in the output directory?
ffmpeg -title “$title” -i $filename -acodec mp3 -ac 2 -ab 128 -vn -y $audio # Change this if xt2 is not an mp3
mv $audio $outputdir
echo “$pluginmsg” # No MP3 player – try again!
sleep 1
exit 1

exit 0

I tried to write it generic enough it could be easily modified for other file types, etc, etc, etc. I then made a new KDE “Link to Application”, set the working directory as the folder my wife saves her videos to, and passed in the media path for the MP3 player for the command to run – “/usr/local/bin/youtube2mp3 /media/disk”. I also set the desktop link to run as a terminal window, so she could see the progress and any exit messages.

Now, she saves her YouTube vidoes to that folder, plugs in her MP3 player, clicks the script icon on her desktop, and waits while it creates the MP3 files and moves them to her MP3 player. Too easy.

47 Responses

  1. that’s great!
    very useful.
    I already ripped some extra campy stuff I hope to somehow mix a little.
    be the change man 😉 !

  2. Cool – you can also rip to OGG format as well, if you prefer that to MP3.

  3. You are “humble and lovable”… and brilliant. This script is not ugly, but ingenious. My wife listens to a lot of news interviews that primarily are in flash. I told her about your solution and she begged me to set it up for her and she accomplished several runs without a problem. This will allow her time to be utilized much more efficiently, and allow her to listen without being tied down. And since the resulting files are in a suitable format, she can even use RW CD’s to listen to in the car. Maybe its just the chocolate I ate, but I truly love you.

  4. Wow, thanks! I’ll just pick myself up off the floor now….


  5. Wow this is very instructive!

    I didn’t even know it was possible.
    To ogg vorbis format for me.


  6. Glad you liked it.

  7. […] Symbolik.wordpress.com explains how to convert YouTube FLV files into Mp3s by utilizing ffmpeg. As a bonus, the post also provides a nice bash script to convert all FLV files in the same directory to MP3 or OGG format. […]

  8. this is great!! thankssss

  9. Hi,
    you can download youtube videos on
    Here you can also search, watch and download youtue videos.
    All in One 🙂

  10. Hi, Ubuntu here, using:
    – Ubuntu Linux 6.10 (Edgy Eft)
    – FFmpeg version SVN-rUNKNOWN
    – Firefox-Addon “DownloadHelper”

    Thanks for your post, but i still got some probs when using the ffmpeg command … I downloaded a video from Yotube with the help of the Firefox-Addon “DownloadHelper”. Then i tried your command, eg like this:
    ffmpeg -title “Rage-Testify” -i Rage_Against_The_Machine_-_Testify_Music_Video.flv -acodec mp3 -ac 2 -ab 128 -vn -y Rage_Against_The_Machine_-_Testify.mp3

    But Bash answes me:
    Unsupported codec for output stream #0.0


    -ubuntu:~/dwhelper$ ffmpeg -title “Rage-Testify” -i Rage_Against_The_Machine_-_Testify_Music_Video.flv -acodec mp3 -ac 2 -ab 128 -vn -y Rage_Against_The_Machine_-_Testify.mp3
    FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
    configuration: –enable-gpl –enable-pp –enable-pthreads –enable-vorbis –enable-libogg –enable-a52 –enable-dts –enable-libgsm –enable-dc1394 –disable-debug –enable-shared –prefix=/usr
    libavutil version: 0d.49.0.0
    libavcodec version: 0d.51.11.0
    libavformat version: 0d.50.5.0
    built on Sep 20 2006 00:26:15, gcc: 4.1.2 20060906 (prerelease) (Ubuntu 4.1.1-13ubuntu2)
    Seems that stream 1 comes from film source: 1000.00 (1000/1) -> 29.97 (30000/1001)
    Input #0, flv, from ‘Rage_Against_The_Machine_-_Testify_Music_Video.flv’:
    Duration: 00:03:40.0, bitrate: N/A
    Stream #0.0: Audio: mp3, 22050 Hz, mono
    Stream #0.1: Video: flv, yuv420p, 320×239, 29.97 fps(r)
    Output #0, mp2, to ‘Rage_Against_The_Machine_-_Testify.mp3’:
    Stream #0.0: Audio: 0x0000, 22050 Hz, stereo, 128 kb/s
    Stream mapping:
    Stream #0.0 -> #0.0
    Unsupported codec for output stream #0.0

    I don’t know what is wrong, i tried without -title, i tried with different number audio channels (-ac 1 = mono), and with several different bitrates (-ab). Does not work. Might it all work with new Ubuntu, new Addon and recent ffmpeg codec? What did you all use?

  11. ubuntuuser: A quick Google on ‘ffmpeg + flv + “Unsupported codec for output stream #0.0″‘ yielded this link, which should help:


    Try running from the command line the ffmpeg command in the script, and start taking out options and switches. Should work if you have all your codecs installed, so check that you do in Aptitude or Adept Package Manager.

    I run Gutsy, but I do not think 6.10 should present a problem here.

    Good luck!

  12. ubuntuuser, you probably need to install lame. It happened to me too 🙂

  13. […] e colocá-lo no arquivo audio.mp3 (entenda melhor esses comandos lendo o manual do ffmpeg ou com este post, de onde tirei a […]

  14. Thanks a lot that was what I was looking for I’ll try it right now!!



  15. Glad it worked for you, Hash.

  16. Okay you need this ffmpeg svn file name is “FFmpeg-svn-15666.7z” you can get it here -> http://sourceforge.net/project/showfiles.php?group_id=205275&package_id=248632

    then extract the exe and use this in your command prompt
    ffmpeg -i INPUTFLVFILEHERE.flv -ac 2 -ab 128 -vn -y OUTPUTFILEHERE.mp3 and thats it
    i think it worked for me

  17. Ah, ok, this is for Windows. Haven’t been back to this post for a while, so took me a bit to catch on.

    Thanks for the info!

  18. The flv file already has an mp3 stream within itself so i guess if u try this ( ffmpeg -i vid.flv -acodec copy output.mp3 ) it might be faster than using the ffmpeg encoder.

  19. If You don’t like to work on console install AVIDEMUX, load the flash video with it and then go to the menu Sound and Save…

    It is just that easy! Best regards from Switzerland.

  20. Your blog is very interresting for me, i will come back here..

  21. […] Extracting an MP3 From a YouTube Flash (FLV) Download… « Linux Free Trade Zone (tags: mp3 flv ffmpeg linux) […]

  22. I’m gonna try this one for sure.
    Till now I was using http://www.tubeleecher.com

  23. yep awesome method .
    I have had great results also with http://www.tubeleecher.com

  24. yep awesome method .
    Till now I was using http://www.tubeleecher.com

  25. Hey thankee for the free download it was really useful!! ❤

  26. coproc
    I have the same problem as ubuntuuser above, and none of the prescribed solutions helped me. I have LAME installed already, and just installed ffmpeg.
    “Unsupported codec for output stream #0.0”
    I would paste the full output, but that would be redundant. if anyone wants to email me about this, the top line of this message contains the first half of my email address, and the last line contains the rest.

    –Nate (the Great)

  27. great article, thanks for sharing.

  28. thanks a lot man! it helped me to complete a website of youtube video to mp3 generator. 🙂


  29. hii…

    i m using http://www.allgrabs.com/ gre8 site for downloading videos..

    we can also buy youtube downloader script.

  30. ffmpeg -ab 128 won’t work (well, it will work, but not produce the expected result). The bitrate is in b/s (and not in kb/s), so the correct command should read -ab 128000

  31. Made a script for this called my “convertibox” that loops over files in whichever directory it’s in, converts them to mp3, then creates a subdirectory, to which it moves the converted .flv files.
    I just set DownloadHelper to run it each time it completes a download.

    Many thanks for all the support from this page. Reply if you want me to post the script, or just email me.

    -Nate (The Great)

  32. I just get this error message:

    $ /usr/local/bin/youtube2mp3 /Videos/Mp3s
    /usr/local/bin/youtube2mp3: line 9: please: command not found
    /usr/local/bin/youtube2mp3: line 22: trap: “Quitting…”: invalid signal specification
    /usr/local/bin/youtube2mp3: line 22: exit: 13’: numeric argument required

  33. […] My wife likes YouTube. A *lot*. I had found out how to make MP3 files from the audio sections of the FLV files, so she wanted to know if I could set things up for her to do this on her own. Of course I said yes. So, first step was downloading the video from YouTube. That was pretty easy – I installed the UnPlug add-on for Firefox and tested it. I used to use Ook! Video, but it stopped working for me on YouTube. Maybe they changed the site and bro … Read More […]

  34. How about this one-liner?

    for $filename in $(ls -1 *.flv); do ffmpeg -i $filename $filename.mp3 ; done

  35. I am curious to find out what blog system you have been using?
    I’m experiencing some small security problems with my latest website and I would like to find something more safeguarded. Do you have any solutions?

  36. Have you ever thought about creating an e-book or guest authoring on other blogs?

    I have a blog based on the same topics you discuss and would really
    like to have you share some stories/information. I know my subscribers would value your work.

    If you are even remotely interested, feel free to shoot
    me an email.

  37. After I initially left a comment I seem to have clicked the -Notify me when new comments are
    added- checkbox and from now on whenever a comment is added I get
    four emails with the exact same comment. Perhaps there is a way
    you can remove me from that service? Appreciate it!

  38. Good day! This post couldn’t be written any better! Reading through this post reminds me of my old room mate! He always kept chatting about this. I will forward this page to him. Pretty sure he will have a good read. Many thanks for sharing!

  39. Hello There. I found your blog using msn. This is a really well written article.

    I will make sure to bookmark it and return to read more of your useful info.
    Thanks for the post. I’ll definitely comeback.

  40. Superb site you have here but I was wanting to know if you knew of any message boards that cover the same topics discussed
    here? I’d really like to be a part of group where I can get feedback from other knowledgeable people that share the same interest. If you have any suggestions, please let me know. Many thanks!

  41. Hello i am kavin, its my first time to commenting anywhere, when i read this post i thought i could also create comment due to this sensible paragraph.

  42. Excellent beat ! I would like to apprentice even as you amend your web site, how can i subscribe for a weblog website? The account aided me a acceptable deal. I had been tiny bit familiar of this your broadcast provided brilliant transparent concept

  43. Ben markete ekmek almaya gitmiştim, ekmeğin ücretini ödemek için sıraya girdim. Benim önümde de 35 40 yaşlarında bi adam sigara istedi kasiyerden. Kasiyer sigarayı uzattı, adam sigarayı alıp üzerindeki yazıyı okudu. Şöyle yazıyordu sigaranın üzerinde…devamı için: http://www.komikti.com

  44. Marmara üniversitesinde okuduğum dönemde, birgün Matematik dersindeyiz ve bölümde gayet rahat ve sempatik tavırlarıyla dikkat çeken hocamızın derste telefonu çaldı. Hoca Alo Telefondaki Merhaba efendim ben falanca bankadan arıyorum,size bir iki so…devamı için: http://www.komikti.com/viewer.asp?ino=148

  45. Hi my loved one! I wish to say that this article is amazing, nice written and include approximately all significant infos. I’d like to see extra posts like this .|

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: