A few days ago I downloaded a video file (.flv) from a website. I wanted to convert the video from .flv to .avi (I know it’s not a free format, but I needed to). I searched over the Internet and found out about FFmpeg. FFmpeg is a command line tool used to convert multimedia files between formats. Not only it converts video files but it also converts audio files.
To make sure FFmpeg is already installed on your GNU/Linux distribution, open the package manager you use and search for ffmpeg. Install it if it’s not already installed. I usually use the Konsole (Kubuntu’s Terminal), so I typed:
$ sudo apt-get install ffmpeg
Ok, now we have the program, but how does it work?
To begin with, open up a terminal. I understand that lots of people are afraid , bored or don’t like using it, but once you get the hang of it, you can perform many useful tasks.
The generic syntax is:
$ ffmpeg [[infile options][`-i' infile]]… {[outfile options] outfile}…
You have to have in mind that options that precede the infile are applied to the the infile and options that are between the infile and outfile are applied to the outfile.
In my case, I had a .flv file and I wanted to convert it to .avi. So the way to do it is:
$ ffmpeg -i infile.flv outfile.avi
Done! Simple as that! You will find the .avi file in the same folder!
Keep in mind that by default, FFmpeg tries to convert as losslessly as possible, attempting to keep the best quality for the output file. It uses the same audio and video parameters for the outputs as the one specified for the inputs.
If you want to see what formats and codecs are available on your PC just type:
$ ffmpeg -formats
FFmpeg supports .3gp, .avi, .mp3, .mp4, .mvi, .rm , .mkv among many others.
- Some video options that you might find useful are:
-b bitrate where bitrate is the video bitrate in bit/s. The default is 200kb/s
-r fps where fps is the frame rate in Hz. The default value is 25Hz.
-s size where size is the frame size. The default in FFmpeg is the same as the source. The format is ‘wxh’. wxh is equal to 160×128. You can use both either wxh or 160X128 (see video options link below for all sizes)
-aspect aspect where aspect is the aspect ratio with values 4:3, 16:9 or 1.3333 or 1.7777.
-vcodec codec where codec is the name of the video codec that you want the FFmpeg to use.
- Some audio options that you might find useful:
-ar frequency where frequency is the audio sampling frequency. The default value is 41000KHz
-ab bitrate where bitrate is the audio bitrate in bit/s. The default is 64k.
-acodec codec where codec is the name of the audio codec that you want the FFmpeg to use.
More details can be found here:
Following are some examples mentioned on ffmpeg documentation.
Example 1:
ffmpeg -i input.avi -b 64k output.avi
With the -b 64k option we set the outfile bitrate to 64kbit/s
Example 2:
ffmpeg -r 1 -i input.m2v -r 24 output.avi
Using the -r 1 we force the frame rate of the input file (valid for raw formats only) to 1 fps and with the -r 24 we set the the frame rate of the output file to 24 fps.
Example 3:
ffmpeg -i test.wav -acodec mp3 -ab 64k test.mp3
In this exampe we can see the use of FFmpeg for audio files. We convert a .wav file to .mp3. As said before using -acodec mp3 we force FFmpeg to use the mp3 audio codec to create the output file. The -ab 64k tells ffmpeg to use an audio bitrate of 64k.
Example 4:
ffmpeg -i video.avi -ar 22050 -ab 32 -s 640×480 video.mp4
Using the -ar we set the audio sampling rate to 22050 Hz. The -ab as i said sets the audio bitrate to 64k and the -s sets the frame size to 640×480. Here instead of 640×480 we could have used vga like this:
ffmpeg -i video.avi -ar 22050 -ab 32 -s vga video.mp4
Remember to see the video options link for all available sizes.
Conclusion: With FFmpeg you can manipulate and convert video and audio files between a variety of formats, fast and easy, with just a simple command. Remember not to hesitate to use the terminal!


convert .flv to .mpg
ffmpeg -i yourfile.flv -ab 56 -ar 22050 -b 500 -s 320×240 yourfile.mpg
convert .3gp to .avi
ffmpeg -i file.3gp -f avi -acodec mp3 *.avi
extract audio .3gp to .mp3
ffmpeg -y -i *.3gp -ac 1 -acodec mp3 -ar 22050 -f wav *.mp3
Convert wma to ogg
ffmpeg -i *.wma -acodec vorbis -aq 100 *.ogg
Convert wma to mp3
ffmpeg -i *wma -acodec mp3 -aq 100 *.mp3
If you have a lot of files to convert run this command in the directory where your wma files reside
convert wma to ogg
for i in *.wma; do ffmpeg -i $i -acodec vorbis -aq 100 ${i%.wma}.ogg; done
convert wma to mp3
for i in *.wma; do ffmpeg -i $i -acodec mp3 -aq 100 ${i%.wma}.mp3; done
Thanks for this useful guide. Helpful indeed
Thanks for this useful tutorial
You really don’t want to use “-acodec vorbis”, instead you should use “-acodec libvorbis”. The first uses the ffmpeg internal vorbis encoder, which currently delivers very poor quality.
I’ve never dealt much with ffmpeg from the command line, I usually opt for WinFF which is a GUI frontend for ffmpeg.
Thank you guys for the useful additions and tips!
WinFF seems very simple and practical btw. I will have a look at it!
will ffmpeg recognise input files *.mpg4
Judging from the supported formats and codecs listed here: http://en.wikipedia.org/wiki/Ffmpeg#Codecs.2C_formats_and_protocols_supported
it shouldn’t have any problem handling the mpeg4 format.
I can’t convert flv to 3gp. Can you help me?
@Roman
Can you paste the command you are using and the error you get?
@tuxhelper
Could you clarify what you’re doing that makes ffmpeg effect all files in the folder?
for i in *.wma; do ffmpeg -i $i -acodec vorbis -aq 100 ${i%.wma}.ogg; done
I understand the ffmpeg -i $i -acodec vorbis -aq 100 part, but how to the other parts of this work?
@tuxhelper
After playing with that a bit, I have a few thoughts to share. My main goal is to take flv files that I’ve ‘borrowed’ from youtube with a stream ripper and convert them to mp3 so I can make mix cd’s and show off for my friends at work. I am a beginner linux user, and the only reason why I’ve learned anything is because linux tends to provide you with plenty of brick walls. For this, I love it.
First, if any of the file names have spaces, it won’t work (or it didn’t for me).
Next, if I’ve interpreted this correctly, which I think I have since I used it to convert three flv files to mp3 as a test, than this should be a little clearer for command line newbies like myself to understand.
for i in *.INPUT; do ffmpeg -i $i OTHER ${i%.INPUT}.OUTPUT; done
INPUT represents the file type you start with. OUTPUT represents the file type you want to convert it to, and OTHER represents any additional commands you want to tell ffmpeg to do along the way.
For example, I tested this by taking 3 random flv files and dropping them into a folder. Since they all had long screwey file names, I renamed them 1.flv, 2.flv and 3.flv. Then I ran this adapted from your suggestion:
for i in *.flv; do ffmpeg -i $i -ab 128k ${i%.wma}.mp3; done
The option in the middle (-ab 128k) isn’t really needed, but since the default quality is 64k, I decided to up that to something that sounds less like getting a call from someone in a crowded bar and more like music.
The result is that the 3 flv files in the working directory were converted to mp3 at 128k. Obviously in this case, the video was discarded. The original files are intact, and the new files created are named 1.flv.mp3 etc.
So ripping you line apart,
for i in *.wma; do ffmpeg -i $i -acodec vorbis -aq 100 ${i%.wma}.ogg; done
[for i in *.wma; do ffmpeg -i $i] tells the system to perform the ffmpeg command on all *.wma files in the working directory. [-acodec vorbis -aq 100] Are the particular options for ffmpeg to use. In your case, you select the codec and I think -aq 100 means audio quality 100% but I’m not sure. In my example, I just chaged the bitrate. [${i?.wma}.ogg tells the system how to name the new files. Poop.wma will become Poop.wma.ogg.
It took a little playing around to get you info to work for ripping audio out of flv files, but that’s mainly because I don’t really know much about the command line yet. Again, the one thing that really snagged up the process was the filenames
If there are any spaces in the filenames, it seems like it won’t work.
Thanks again for the help, and I hope my experience with this may help someone else.
@Pete
Am glad this post could be of help to you. Am even gladder that you shared your experience and added all these useful additions to it.
thank you for your comment!
A workaround is to replace spaces in names by another character. Here is a simple command to replace spaces by (for instance) underscores:
for i in *.wma; do mv “$i” `echo $i | tr ‘ ‘ ‘_’`; done
Cheers,
A.
Another after thought. Since youtube puts everything up at 64k, by setting ffmpeg to 128k does nothing but make the files twice the size.
To fix the problem with spaces in the filenames, you can quote the names, as follows:
for i in *.wma; do ffmpeg -i “$i” -acodec vorbis -aq 100 “${i%.wma}.ogg”; done
hi,
just downloaded the latest version of ffmpeg, but when i’m trying convert flv to mp3 i have “unknown encoder mp3″ in result???
@Yura
Hi, try using “-acodec libmp3lame” instead of “-acodec mp3″ and see if it works.
hi i am using ffmpeg for conversion .
file wont be stored if their is any white space in folder
like New folder
let me know if u have solution for this
Thanks
@khan
Sorry for running a bit late, vacations =)
AFAIK the white space “bug” is a known situation in the bash world. I think the best possible solution is to just avoid naming folders like that.
Sorry for not being able to help more on this one. Don’t know if there is any specific workaround for ffmpeg, maybe someone else can help.