From it’s introduction by Macromedia in 2003 the flv container has become the de facto file format for both audio and video on the Internet.
Flv files usually contain the following type of audio and video data:
- audio: Nellymoser Asao, Speex or mp3
- video: Sorenson Spark or ON2 VP6
Flv files can also contain H.264 video and AAC audio but those are usually found in the newer f4v container introduced 4 years later in 2007.
To inspect a flv and find out what codec was used to encode the data just use VLC‘s Media Information window:
The sound data in the .flv file can easily be extracted, converted to mp3 and saved in an mp3 file – all server side – using the open source and free FFmpeg tool. FFmpeg works on Linux, OS X and Windows and supports a wide variety of audio codecs for both decoding and encoding.
In our case, when converting .flv to mp3, FFmpeg needs to:
- decode audio data encoded with Nellymoser asao and Speex
- encode it as mp3.
FFmpeg can easily decode Nellymoser asao sound and encode to mp3 but to decode sound encoded with Speex, it needs to be compiled using the 3rd party libspeex library.
The FFmpeg website maintains an exhaustive list of supported audio/video codecs and containers supported.
Installing FFmpeg on Ubuntu 14.04 and 15.04
ffmpeg package has been removed from Ubuntu starting with version 14.04 so the easiest way to install it is to use the Personal Package Archive linked from the official FFmpeg downloads page. Type the following while logged in as root:
sudo add-apt-repository ppa:mc3man/
trusty- media sudo apt-get update sudo apt-get install ffmpeg
FFmpeg will be installed with Speex support.
Installing FFmpeg on Mac OS X
This article covers in detail all the steps needed to install FFmpeg on OS X including Speex support.
Checking the FFmpeg installation
After installing FFmpeg, typing
ffmpeg in the command line/Terminal should bring up the following:
For help type the following:
ffmpeg -h — print basic options
ffmpeg -h long — print more options
ffmpeg -h full — print all options (including all format and codec specific options, very long)
Converting a .flv file to mp3
With FFmpeg installed and properly running from the command line, converting a flv to mp3 is as easy as going to the folder where your .flv file is stored and issuing the following command
ffmpeg -i audio.flv audio.mp3
Where audio.flv is the original flv file and audio.mp3 is the desired mp3 file. The command will work even if the flv file contains both audio and video.
FFmpeg will output the source stream details, output stream details and more:
When the flv already contains mp3 audio
When the audio data inside the .flv is already encoded using mp3, there’s no point in decoding it and reencoding it (a process that takes time), you can just copy the mp3 data straight to an mp3 file using the -acodec copy option:
ffmpeg -i audio.flv -acodec copy audio.mp3
Other FFmpeg options
Using FFmpeg’s options you can also specify the number of audio channels, sample rate, the number of audio frames and more. Check out the FFmpeg documentation for the full list of audio encoding options.