Skip to main content

Overview

ffmpeg is a powerful command-line tool for converting, processing, and streaming multimedia content. It serves as the main workhorse of the FFmpeg project, capable of transcoding between virtually any audio and video format.
ffmpeg is described as a “Universal media converter” and can handle complex filtering, format conversion, and stream manipulation tasks.

Basic Syntax

ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...

Common Global Options

-y
boolean
Overwrite output files without asking
-n
boolean
Never overwrite output files
-f
string
Force container format (auto-detected otherwise)Example: -f mp4
-c
string
Select encoder/decoder. Use copy to copy stream without reencodingVariants:
  • -c:v - Video codec
  • -c:a - Audio codec
  • -c:s - Subtitle codec
  • -c:d - Data codec
-codec
string
Alias for -c option

Input/Output Options

-t
duration
Stop transcoding after specified durationExample: -t 30 (30 seconds), -t 00:05:00 (5 minutes)
-to
time
Stop transcoding at specified timeExample: -to 00:10:00
-ss
time
Start transcoding at specified time (seek)Example: -ss 00:01:30
-sseof
time
Set start time offset relative to end of file

Stream Mapping

-map
string
Set input stream mappingFormat: [-]input_file_id[:stream_specifier][?]Examples:
  • -map 0 - Map all streams from first input
  • -map 0:v:0 - Map first video stream from first input
  • -map 0:a - Map all audio streams from first input
  • -map -0:a:1 - Exclude second audio stream
-map_metadata
string
Set metadata information of output file from input fileFormat: outfile[,metadata]:infile[,metadata]
-map_chapters
integer
Set chapters mapping from specific input file

Video Options

-r
string
Override input framerate or convert to given output framerateExample: -r 30 (30 fps), -r 24000/1001 (23.976 fps)
-s
string
Set frame size (WxH or abbreviation)Examples: -s 1920x1080, -s hd720
-aspect
string
Set aspect ratioExamples: -aspect 16:9, -aspect 1.7777
-pix_fmt
string
Set pixel formatExample: -pix_fmt yuv420p
-vn
boolean
Disable video recording
-vcodec
string
Alias for -c:v (select video codec)Examples: -vcodec libx264, -vcodec copy
-vf
string
Apply video filtersExample: -vf "scale=1280:720,fps=30"
-b:v
string
Set video bitrateExample: -b:v 2M (2 Mbps)
-q:v
number
Use fixed quality scale for video (VBR)Range: 0-31 (lower is better quality)

Audio Options

-an
boolean
Disable audio recording
-acodec
string
Alias for -c:a (select audio codec)Examples: -acodec aac, -acodec libmp3lame
-af
string
Apply audio filtersExample: -af "volume=0.5,aresample=48000"
-ar
integer
Set audio sampling rateExample: -ar 48000 (48 kHz)
-ac
integer
Set number of audio channelsExample: -ac 2 (stereo)
-b:a
string
Set audio bitrateExample: -b:a 192k (192 kbps)
-q:a
number
Use fixed quality scale for audio (VBR)

Advanced Options

Filter Graphs

-filter_complex
string
Create a complex filtergraphExample:
-filter_complex "[0:v]scale=1280:720[v1];[1:v]scale=1280:720[v2];[v1][v2]overlay"
-lavfi
string
Alias for -filter_complex

Hardware Acceleration

-hwaccel
string
Use hardware accelerationExamples: cuda, qsv, vaapi, videotoolbox
-hwaccel_device
string
Select hardware device for acceleration

Stream Specifiers

Stream specifiers allow you to precisely target specific streams:
  • v or v:0 - First video stream
  • a or a:0 - First audio stream
  • s or s:0 - First subtitle stream
  • 0:v:1 - Second video stream from first input
  • 0:a:0 - First audio stream from first input

Real-World Examples

Basic Format Conversion

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

Extract Audio from Video

ffmpeg -i input.mp4 -vn -c:a copy audio.m4a

Trim Video

ffmpeg -i input.mp4 -ss 00:00:30 -t 00:00:10 -c copy output.mp4

Resize Video

ffmpeg -i input.mp4 -vf scale=1280:720 -c:a copy output.mp4

Change Video Bitrate

ffmpeg -i input.mp4 -b:v 2M -c:a copy output.mp4

Combine Audio and Video

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 output.mp4

Create Thumbnail

ffmpeg -i input.mp4 -ss 00:00:05 -vframes 1 thumbnail.jpg

Convert to GIF

ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -t 5 output.gif

Add Watermark

ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=10:10" output.mp4

Concatenate Videos

1

Create file list

Create a text file list.txt:
file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'
2

Concatenate

ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4

Stream Copy (Fast)

ffmpeg -i input.mkv -c copy -map 0 output.mp4
Using -c copy performs a stream copy without re-encoding, which is much faster but may have format compatibility limitations.

Performance Options

-threads
integer
Set number of threads for encodingExample: -threads 4
-preset
string
Set encoding preset (speed vs compression trade-off)Values: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow
-tune
string
Tune encoder for specific content typeExamples: film, animation, grain, stillimage

Debugging Options

-v
string
Set logging levelValues: quiet, panic, fatal, error, warning, info, verbose, debug, trace
-report
boolean
Generate a report with detailed encoding information
-benchmark
boolean
Add timings for benchmarking
-progress
string
Write program-readable progress information to URL

Source Code Reference

The main option parsing logic is implemented in:
  • /home/daytona/workspace/source/fftools/ffmpeg_opt.c:1622 - Options array definition
  • /home/daytona/workspace/source/fftools/ffmpeg_opt.c:1424 - Usage information
For a complete list of options, run ffmpeg -h full or visit the official FFmpeg documentation.

See Also

Build docs developers (and LLMs) love