Skip to content

ffmpeg

The ffmpeg command is the core tool for converting, encoding, decoding, and processing audio and video.

Synopsis

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

Most Common Options

OptionDescription
-i urlInput file URL
-c[:stream] codecCodec for a stream (copy, libx264, aac, etc.)
-c:vVideo codec shorthand
-c:aAudio codec shorthand
-c:sSubtitle codec shorthand
-codecsList all codecs
-encodersList all encoders
-decodersList all decoders
-filtersList all filters
-formatsList all formats
-bsf[:stream] bitstream_filterApply a bitstream filter to a stream
-map [-]input_file_id[:stream_index][:sync_file_id[:sync_stream_index]]Manual stream mapping
-t durationRestrict transcoded/captured audio/video to duration
-ss positionSeek to position (before -i = fast, after = accurate)
-to positionStop writing at position
-f fmtForce input/output format
-yOverwrite output files without asking
-nNever overwrite output files
-loglevel loglevelSet logging level
-hide_bannerHide startup banner
-statsPrint encoding progress

Codec Copy Mode

Use -c copy to copy streams without re-encoding (fastest, lossless):

bash
# Copy all streams (fastest possible)
ffmpeg -i input.mkv -c copy output.mp4

# Copy video, re-encode audio
ffmpeg -i input.mkv -c:v copy -c:a aac output.mp4

# Copy audio, re-encode video
ffmpeg -i input.mkv -c:v libx264 -preset fast -crf 22 -c:a copy output.mp4

Encoding Quality

bash
# CRF range: 0 (lossless) to 51 (worst)
# 18-23: perceptually lossless / high quality
# 23-28: good quality for streaming
# 28-35: smaller files, visible artifacts
ffmpeg -i input.mp4 -c:v libx264 -crf 22 output.mp4

Preset (Encoding Speed)

PresetSpeedUse Case
ultrafastFastestLive streaming, real-time
superfast
veryfast
faster
fastHigh-quality encoding
mediumDefault
slow
slowerBest compression
veryslowSlowestArchive/master files
bash
ffmpeg -i input.mp4 -c:v libx264 -preset veryslow -crf 18 output.mp4

Hardware Acceleration

bash
# NVIDIA NVENC
ffmpeg -i input.mp4 -c:v h264_nvenc -preset p7 -cq 23 output.mp4

# Intel VAAPI (Linux)
ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i input.mp4 \
  -c:v h264_vaapi output.mp4

# macOS VideoToolbox
ffmpeg -i input.mp4 -c:v h264_videotoolbox -b:v 6M output.mp4

Input/Output Options

bash
# Limit duration
ffmpeg -i input.mp4 -t 60 output.mp4

# Limit output size
ffmpeg -i input.mp4 -fs 10M output.mp4

# Seek to position (before input = faster seek)
ffmpeg -ss 01:30 -i input.mp4 -t 30 -c copy output.mp4

# Multiple inputs
ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac output.mp4

# Skip input streams
ffmpeg -i input.mkv -map 0:v -map 0:a:1 -c copy output.mp4

Released under the MIT License.