Bash: Script to convert .flv to mp3

Flash Video (.FLV) is currently a very popular format of online videos, inparticular youtube. This post explains how to use a simple script to extract the sound from a flash video file and turn it into an mp3.

In order for the script to work you will need to download ffmpeg (to decode the video) and lame (to encode the mp3). This can be achieve in ubuntu by opening a terminal and running the following or alternatively you can use your package manager GUI to search and download the packages for you.

sudo apt-get install ffmpeg lame

You then need to create a new file named “” and paste the following into it using your preferred text editor (which hopefully isn’t VI). Save the file and then change the file permissions so that it is executable (by running:`chmod a+x` in the terminal or via the gui in you file browser)

# this script should convert files from FLV to WAV and then to MP3
echo " "
echo "  Welcome to FLV to MP3 converter!  version 0.1"
echo " "
infile_name="[email protected]"
# exit if the user did not enter anything:
if [ -z "$infile_name" ]; then
    echo " "
    echo "You did not tell me the file name, so I will exit now."
    echo " "
echo " "
ffmpeg -i "$infile_name" -acodec pcm_s16le -ac 2 -ab 128k -vn -y "${infile_name%.flv}.wav"
lame --preset cd "${infile_name%.flv}.wav" "${infile_name%.flv}.mp3"
rm "${infile_name%.flv}.wav"
echo " "
echo "OK. I'm done! Have fun!"
echo " "

You should now be able to convert a flashvideo into an mp3 by running the following command (changing the filenames to fit your purpose):
sh videofilename.flv

Extra: Youtube
In linux it might be worth noting that youtube downloads the flv’s to your /tmp folder and you can easily copy them or convert to mp3’s (Ensure video is completly finished loading).

Also there is an application called ‘youtube-dl’ which can be installed from the repositories

sudo apt-get install youtube-dl

and then run using


Of course it’s up to your moral guidance to decide what you can and can’t download.


  1. Iker

    I think your script is great but example is wrong:
    shell> sh videofilename.flv mp3audiofilename.mp3
    shell> sh videofilename.flv

  2. mat

    @Iker fixed it thanks.

  3. Martin

    Great script! Thanks!

  4. Martin

    Here an other solution:

    ffmpeg -i “video.flv” -f mp3 -acodec copy “video.mp3”


    ffmpeg -i “video.flv” -f mp3 -ab 160000 -acodec libmp3lame “video.mp3”


  5. beigubfd

    I recommend Avdshar Audio Converter which can Batch convert FLV downloaded from the internet or from other source to MP3 for playing FLV on many audio players.

  6. dave clark

    I recommend Avdshare Audio Converter to convert FLV to MP3 quickly.

  7. James

    Convert video to MP3 online for free

Leave a Comment

Your email address will not be published. Required fields are marked *