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:
#!/bin/bash
####################
# Set variables – interrupt, extension1, extension2, and the audio file name
####################
USER_INTERRUPT=13
xt1=flv
xt2=mp3
audio=${filename%$xt1}$xt2
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" ]
then
outputdir=${1}/
else
outputdir=/dev/dummy/
fi####################
# 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 ]
then
for filename in *.$xt1
do
title=${filename%$xt1}
audio=${filename%$xt1}$xt2if [ ! -f ${outputdir}$audio ] # Does the mp3 already exist in the output directory?
then
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
fi
done
else
echo “$pluginmsg” # No MP3 player – try again!
sleep 1
exit 1
fiexit 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.
Filed under: Apps, FOSS, HowTo, Music…, Open-Source, Programming, Tips…, hacking | Tagged: HowTo

that’s great!
!
very useful.
I already ripped some extra campy stuff I hope to somehow mix a little.
be the change man
Cool – you can also rip to OGG format as well, if you prefer that to MP3.
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.
Wow, thanks! I’ll just pick myself up off the floor now….
^__________^
Wow this is very instructive!
I didn’t even know it was possible.
To ogg vorbis format for me.
;o)
Bluebeetle(one).
http://redirect.alexa.com/redirect?http://bluebeetleone.blogspot.com
Glad you liked it.
[...] 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. [...]
this is great!! thankssss
Hi,
you can download youtube videos on
http://www.downloadyoutubevids.com
Here you can also search, watch and download youtue videos.
All in One
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
See:
-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: 0×0000, 22050 Hz, stereo, 128 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Unsupported codec for output stream #0.0
-ubuntu:~/dwhelper$
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?
ubuntuuser: A quick Google on ‘ffmpeg + flv + “Unsupported codec for output stream #0.0″‘ yielded this link, which should help:
http://www.linuxreality.com/forums/index.php?topic=2253.msg17177
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!
ubuntuuser, you probably need to install lame. It happened to me too
[...] e colocá-lo no arquivo audio.mp3 (entenda melhor esses comandos lendo o manual do ffmpeg ou com este post, de onde tirei a [...]
Thanks a lot that was what I was looking for I’ll try it right now!!
Peace
Harold
Glad it worked for you, Hash.
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
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!
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.
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.
Dietschi: Good tip. Thanks!
Your blog is very interresting for me, i will come back here..
[...] Extracting an MP3 From a YouTube Flash (FLV) Download… « Linux Free Trade Zone (tags: mp3 flv ffmpeg linux) [...]
I’m gonna try this one for sure.
Till now I was using http://www.tubeleecher.com
yep awesome method .
I have had great results also with http://www.tubeleecher.com
yep awesome method .
Till now I was using http://www.tubeleecher.com