Converting Video Formats with FFmpeg

FFmpeg allows Linux users to convert video files easily between a variety of different formats.
Forcing the Use of a Particular Video Codec

There are a times when you will want to encode a video using a particular codec and file format. FFmpeg lets you choose the codec with which you want to encode by adding -vcodec codec to the command line, where codec is the name of the codec you want to use. So if we want to encode using the MPEG-4 codec at 1,200kbps video bitrate and 128kbps audio bitrate, the command looks like this:

ffmpeg -i InputFile.mpg -ab 128 -b 1200 -vcodec mpeg4 OutputFile.avi

Remove the Audio Stream

Let's say you have recorded a video that has a lot of background noise and undesired commentary, so you decide to remove the audio component of the video completely. To accomplish this, all you have to do is add the -an option to the command line, and FFmpeg automatically removes all audio from the output. Keep in mind that using this option negates any other option that affects the audio stream.

So, in our example, to remove the audio component, we would run the following command:

ffmpeg -i InputFile.mpg -an -b 1200 OutputFile.avi

Remove the Video Stream

Let's say you downloaded a news video from the Net that you want to listen to on your iPod on the way to work, but in order to do that, you have to remove the video component from the output file. FFmpeg allows you to remove the video component of the file completely by adding the -vn option to the command line. Using this option negates any other option that affects the video stream.

So, in our example, to remove the video component and save the audio as a 256kbps MP3 file, we would run the following command:

ffmpeg -i InputFile.mpg -vn -ab 256 OutputFile.mp3

Choose between Multiple Audio Streams to Encode the Output File

Many DVDs have multiple language tracks available, and you can choose in which language you want to watch the video. Having multiple audio tracks is cool if you speak multiple languages and want to be able to watch videos in multiple languages. However, if you don't speak multiple languages, the extra audio tracks are useless and are taking up disk space.

FFmpeg lets you choose which streams you want to keep and ignore the rest. The command-line parameter that allows you to map streams is called -map. So, if in our test file, stream 0 is the video stream, stream 1 is the Spanish audio stream and stream 2 is the English audio stream, and we want to keep the English audio in the output file, we would issue the following command:

ffmpeg -i InputFile.mpg -map 0:0 -map 2:1 -b 1200 OutputFile.avi

In my experience, stream 0 in most video files is usually the video stream, and the remaining streams are the audio streams available with the video.


FFmpeg provides a wide range of options for manipulating and converting video files between a variety of formats. For more information, or to download the latest version of FFmpeg for yourself, please refer to the project Web site.

Suramya Tomar is a Linux system administrator who also likes to program. Visit for more information on his background.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


chelovek84's picture

video conversion

Anonymous's picture

Hi, I have a questions

Anonymous's picture


I have a questions about ffmpeg codification.

I want to encode foreman.avi with this configurations :

- I I I I I ...
- I B P B P B P B I ...
- I B B B B B B B I ...

I know that I have to use the commands -bf and -g...

Can you help me?



Anonymous's picture

This machine Convert FLV AAC H264???/ TO any other??


colix's picture

im tryin to convert a video to mp3 using command ffmpeg -i input filename -vn (ive tried -ab -b to 256 128 64 and also -sameq but nothing) output filename

i am using windows xp, dont

Anonymous's picture

i am using windows xp, dont know anything about linux

never too late to learn somethin beter

Anonymous's picture

Windows is for people who cannot think for themselves.
It is never too late to learn linux.

windows is ok for me

Anonymous's picture

i'm glad someone compiled ffmpeg for windows.

convert video to mp3

Anonymous's picture

i normally use like this:
ffmpeg -i dvd_file.vob -ac 2 -ar 44100 -ab 128k out_file.mp3

soz didnt finish it....:P

colix's picture

soz didnt finish it....:P yeah .... i gets me an error:
Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 29.97 (30000/1001)
Input #0, flv, from '123.flv':
Duration: 00:02:51.30, start: 0.000000, bitrate: 175 kb/s
Stream #0.0: Video: flv, yuv420p, 320x240, 111 kb/s, 29.97 tbr, 1k tbn, 1k tbc
Stream #0.1: Audio: mp3, 22050 Hz, mono, s16, 64 kb/s
WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
Output #0, mp3, to '123.mp3':
Stream #0.0: Audio: 0x0000, 22050 Hz, mono, s16, 64 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Unsupported codec for output stream #0.0


full command line please

Anonymous's picture

show the command line please

maybe it should be like

Anonymous's picture

maybe it should be like this:
ffmpeg -i infile.flv -ac 2 -ar 44100k -ab 128k outfile.mp3
or depends on some ffmpeg version,
ffmpeg -i infile.flv -ac 2 -ar 44100 -ab 128k outfile.mp3

and/or maybe send me that

Anonymous's picture

and/or maybe send me that .flv file to my email gianmhl @ yahoo . com

command for me to find

Anonymous's picture

command for me to find formats is ffmpeg -formats not --formats

I do not like it

ruby's picture

I do not like this software. it can not work for me.
I use iMedia Converter to convert DVD and Videos on Mac.
iMedia Converter for Mac can rip DVD and convert video to sorts of video formats including AVI, FLV, MKV, MP4, 3GP, MTS, M2TS, MOD, WMV, M4V etc. It can also extract audio from video to MP3, WMA, WAV, RA, M4A, AAC, AC3, OGG, MKA, etc.

ffmpeg can do the same thing.

Anonymous's picture

ffmpeg can do the same thing. i used the command line to do it.

i used ffmpeg command line, i

Anonymous's picture

i used ffmpeg command line, i can do the same thing.

mapping right audio languages

typxxi's picture

I don't have any unix linux knowledge, but from my point of view this shouldn't work
ffmpeg -i InputFile.mpg -map 0:0 -map 2:1 -b 1200 OutputFile.avi

the 0:0 is the leading stream, here the video stream
you want to here in future the english stream from 2
(mpeg calls them #0.1 ... where 0 means the inputfile as far as I understand)

You sync the the second stream to the videostream.

ffmpeg -i InputFile.mpg -map 0:0 -map 0:2 -b 1200 OutputFile.avi

if you want spanish a alternate language than this should work

ffmpeg -i InputFile.mpg -map 0:0 -map 0:2 -map 0:1 -b 1200 OutputFile.avi

but this won't work in mp4 (cause mp4 contains only 1 audio stream).

I hope it will work better, 'cause it took a huge amount of time to find these things out.

File Formats

Random Things's picture

Exactly which file formats is FFMPEG compatible with?

it can supports lot of

Anonymous's picture

it can supports lot of formats.

ffmpeg bitrate

ChrisC's picture


In my version of ffmpeg bitrate requires a following 'k' if it is kilobytes.
ffmpeg -i InputFile.avi -ab 128 -b 1200 OutputFile.mpg
ffmpeg -i InputFile.avi -ab 128k -b 1200k OutputFile.mpg


Syntax Error

Anonymous's picture

Where you have "--formats" it should be "-formats".


Anonymous's picture

Thanks a lot for the post. It helped me a lot.

I had 2 scenarios in mind and am wondering if those are possible using FFMPEG:

1) How I can output only part of a video using FFMPEG, example: the output video will start form 10 minutes into the source video and end 15 minutes before the end of the source video.

2) Whether it is possible to output 1 video from 2 source videos in the following manner: output video starts 10 minutes into the first source video and end 15 minutes before the second source video.

I hope you understand what I'm looking for.

I would appreciate any help, or suggestions.


answer to your question 2

Anonymous's picture

if you are using windows, copy the 2 files the use ffmpeg to encode again.

Question about FFMPEG

Anonymous's picture

Hey! Just saw your question about ffmpeg and figured I'd help with what I could. I don't know about part 2, but I know that for duration you do ffmpeg -i InputFile -ss StartTime -t Duration Outputfile. So for example, if the video was 1 hour long, you would do ffmpeg -i InputFile -ss 00:10:00 -t 00:35:00 OutputFile. Hope that was helpful!


Cygwin installation?

Ron Dotson's picture


I was trying to install FFmpeg under Cygwin, but the compilation fails with many, many warnings and a fatal error - a missing header file to define the macro "llrint" as I recall. I copied over the standard.h file from somewhere on the Cygwin installation, but the next fatal error was (as I recall) a missing library routine or something - so obviously my environment or PATH variable aren't set up correctly.

Any pointers as to where I can find out what type of libraries are supposed to be found in what locations in order to get a successful compile and link of FFmpeg?

If so I would appreciate a reply to:
[Note: The email address listed above will self destruct at the first sign of Spam. ;-]
Thank you,


an easier program ?

donate car's picture

I was wondering if there's a program with the basic transf. commands that can be used by those who haven't got experience with it.

there are

Anonymous's picture

here are some of them, mencoder, winff,