Overview of the Basic Syntax

The syntax for FFmpeg commands as described in the official documentation is as follows.

ffmpeg [global options] {[input options] -i input_url} ... {[output options] output_url} ...

Let’s look at a concrete example.

ffmpeg -y -i input.mp4 -c:v libx264 -c:a aac output.mkv
PartDescription
ffmpegThe command itself
-yGlobal option (overwrite output file without confirmation)
-i input.mp4Input file specification
-c:v libx264Output option (specify video codec as libx264)
-c:a aacOutput option (specify audio codec as AAC)
output.mkvOutput file (container is automatically determined from the extension)

Global Options

Global options affect the entire command. Write them before the input and output specifications.

OptionDescription
-yOverwrite the output file without confirmation if it already exists
-nSkip if the output file already exists (do not overwrite)
-loglevel quietMinimize log output
-hide_bannerHide the version and other banner information

Specifying Input (-i)

Input files are specified with the -i flag (official).

ffmpeg -i input.mp4 output.avi

To specify multiple inputs, use -i multiple times.

ffmpeg -i input.mp4 -i audio.wav output.mkv

Important rule: Input options must always be written immediately before -i. If written after -i, they are interpreted as output options.


Specifying Output

Output files are written at the end of the command (any argument not starting with - is treated as an output URL).

ffmpeg -i input.mkv output.mp4

Automatic Output Format Detection

According to the official documentation, the output format is “normally guessed from the file extension.”

The format is normally auto detected for input files and guessed from the file extension for output files.

ExtensionAuto-selected container
.mp4MP4 (MPEG-4 Part 14)
.mkvMatroska
.aviAVI
.movQuickTime
.webmWebM
.mp3MP3
.wavWAV

If the format cannot be determined from the extension, specify it explicitly with the -f option.

ffmpeg -i input.mp4 -f matroska output

Option Ordering Rules (Most Important)

The official documentation states the following about ordering rules.

As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times.

In other words, options are applied to the file that immediately follows them.

The Difference Between Input and Output Options

The same -ss (seek) option has different meanings depending on whether it is written before or after -i.

# -ss specified on the input side (specifies the decode position of the input; fast but sometimes imprecise)
ffmpeg -ss 10 -i input.mp4 output.mp4

# -ss specified on the output side (specifies the start position of the output; precise but decodes the entire input)
ffmpeg -i input.mp4 -ss 10 output.mp4

Do Not Mix Input and Output

# NG: Input and output are interleaved
ffmpeg -i input.mp4 output1.mp4 -i input2.mp4

# OK: All inputs first, then all outputs
ffmpeg -i input.mp4 -i input2.mp4 output.mp4

Specifying Codecs (-c, -c:v, -c:a)

The -c option specifies the encoder or decoder.

OptionTargetExamples
-c:vVideo codec-c:v libx264, -c:v libvpx-vp9, -c:v copy
-c:aAudio codec-c:a aac, -c:a libmp3lame, -c:a copy
-cAll streams-c copy

The especially important copy:

ffmpeg -i input.mkv -c copy output.mp4

-c copy copies streams as-is without re-encoding. It is described as “extremely fast with no quality loss” in the official documentation.


Stream Selection (-map)

By default, FFmpeg “automatically selects the best streams” (official).

Use -map to select explicitly.

# Output video stream 0 and audio stream 0 from the first input
ffmpeg -i input.mp4 -map 0:v:0 -map 0:a:0 output.mp4

Common Syntax Mistakes

Mistake 1: Writing Global Options After Everything Else

# NG: -y was written at the end
ffmpeg -i input.mp4 output.avi -y

# OK: Global options go at the beginning
ffmpeg -y -i input.mp4 output.avi

Mistake 2: Writing Output Options Before the Input

NG (-c:v libx264 is interpreted as an input option and causes an error):

ffmpeg -c:v libx264 -i input.mp4 output.mp4

OK (codec specification goes after -i):

ffmpeg -i input.mp4 -c:v libx264 output.mp4

Mistake 3: Forgetting to Specify an Output File

NG (causes an error because there is no output):

ffmpeg -i input.mp4 -c:v libx264

OK:

ffmpeg -i input.mp4 -c:v libx264 output.mp4

Practice: Syntax Verification Commands

The following are minimal commands that actually work.

ffmpeg -i input.mp4 output.avi
ffmpeg -y -i input.mp4 -c:v libx264 -c:a aac output.mkv
ffmpeg -i input.mp4 -c copy output.mkv

For codec details and specific conversion recipes, see “Convert Video to MP4 (H.264/AAC) with FFmpeg”.


Tested with: ffmpeg 6.1.1 / Ubuntu 24.04 (GitHub Actions runner) Primary sources: ffmpeg.org/ffmpeg.html — Synopsis / Detailed description