| name | ffmpeg |
| description | ffmpeg command-line tool for video, audio, and image processing. Use when converting, transcoding, trimming, extracting audio, resizing, scaling, cropping, concatenating, or muxing media files; when working with .mp4/.mkv/.webm/.mov/.mp3/.wav/.gif; when changing bitrate, codec, framerate, resolution, sample rate, or channels; when streaming or recording; or when the user asks for any media manipulation. |
ffmpeg
ffmpeg is the canonical CLI for media processing. Most operations follow the same shape:
ffmpeg [global_options] -i input.ext [input_options] ... [output_options] output.ext
i flags are inputs. Last positional argument is the output.
- Order of options matters - flags apply to the next input/output, or globally if placed before any input.
- Use
-y to overwrite without prompting, -n to never overwrite, -hide_banner to suppress the version banner.
Convert / Transcode
ffmpeg -i input.mp4 -c:v libvpx-vp9 -c:a libopus output.webm
ffmpeg -i input.mkv -c:v libx264 -c:a aac -movflags +faststart output.mp4
ffmpeg -i input.mov -c copy output.mp4
ffmpeg -i input.m4a -c:a libmp3lame -q:a 2 output.mp3
ffmpeg -i input.mp4 -vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
Trim / Cut
ffmpeg -ss 00:00:30 -i input.mp4 -t 60 -c copy output.mp4
ffmpeg -i input.mp4 -ss 00:00:30 -to 00:01:30 -c:v libx264 -c:a aac output.mp4
Extract Audio / Strip Video
ffmpeg -i input.mp4 -vn -c:a copy output.m4a
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3
ffmpeg -i input.mp4 -an -c:v copy output_silent.mp4
Resize / Scale
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
ffmpeg -i input.mp4 -vf scale=720:-1 output.mp4
ffmpeg -i input.mp4 -vf scale=iw/2:ih/2 output.mp4
ffmpeg -i input.mp4 -vf scale=640:480 output.mp4
Change Bitrate / Quality
ffmpeg -i input.mp4 -c:v libx264 -b:v 2M output.mp4
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium output.mp4
ffmpeg -i input.mp4 -c:a aac -b:a 128k output.mp4
ffmpeg -i input.wav -c:a libmp3lame -q:a 2 output.mp3
CRF vs bitrate: use -b:v (bitrate) when file size matters, -crf (constant rate factor) when quality matters.
Change Codec / Container
ffmpeg -i input.mp4 -c:v libx265 -c:a aac output.mp4
ffmpeg -i input.mkv -c copy output.mp4
ffmpeg -i input.mp4 -movflags +faststart -c copy output_web.mp4
Concatenate
echo "file 'part1.mp4'" > list.txt
echo "file 'part2.mp4'" >> list.txt
echo "file 'part3.mp4'" >> list.txt
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
ffmpeg -i "concat:part1.mp4|part2.mp4|part3.mp4" -c:v libx264 -c:a aac output.mp4
Common Filters
Filters are chained with -vf (video) or -af (audio), each step separated by commas. Reference a labeled output with [label].
ffmpeg -i input.mp4 -vf "crop=iw-200:ih-200:100:100" output.mp4
ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black" output.mp4
ffmpeg -i input.mp4 -vf "transpose=1" output.mp4
ffmpeg -i input.mp4 -vf yadif output.mp4
ffmpeg -i input.mp4 -vf vidstabdetect=shakiness=5 -f null -
ffmpeg -i input.mp4 -vf vidstabtransform=smoothing=10 output.mp4
ffmpeg -i input.mp4 -vf "drawtext=text='Hello World':fontsize=48:fontcolor=white:x=20:y=20" output.mp4
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=2,fade=t=out:st=22:d=2" output.mp4
ffmpeg -i input.mp4 -af "volume=0.5" output.mp4
ffmpeg -i input.mp4 -af "volume=2.0" output.mp4
ffmpeg -i input.mp4 -af "loudnorm=I=-16:TP=-1.5:LRA=11" output.mp4
Thumbnail / Frame Extraction
ffmpeg -ss 00:00:05 -i input.mp4 -frames:v 1 -q:v 2 thumb.jpg
ffmpeg -i input.mp4 -vf fps=1 frame_%04d.png
ffmpeg -i input.mp4 -vf "fps=1,scale=160:90,tile=10x10" sprite.png
Probe Media
ffmpeg -i input.mp4 -hide_banner
ffprobe -v quiet -print_format json -show_format -show_streams input.mp4 | jq .
Common Gotchas
-ss before -i is fast but loses frame accuracy. Put it after -i for accuracy.
-c copy is fast and lossless but only works when inputs share codecs/parameters. Re-encode when they don't.
libx264 is GPL - use libx264rgb or -c:v h264_videotoolbox (macOS), h264_nvenc (NVIDIA), h264_qsv (Intel) for hardware encoders.
- Container matters:
.mp4 doesn't support opus audio, .webm doesn't support aac. Use mkv for mixed-codec muxing.
libmp3lame is the standard MP3 encoder. -q:a is VBR (0–9, lower = better), -b:a is CBR (e.g. 192k).
aac encoder is the default in ffmpeg; use -c:a aac_mf for higher quality on modern ffmpeg.
- For web playback, add
-movflags +faststart to MP4 outputs so the moov atom is at the start of the file.
-crf 0 is lossless, -crf 51 is worst, -crf 18 is visually lossless, -crf 23 is default. Lower = better quality, larger file.
- For previews/scrubbing,
-ss 0.5 -frames:v 1 is much faster than starting at frame 0.
- When extracting audio from a video with multiple audio tracks, use
-map 0:a:0 to pick the first audio track explicitly.
ffmpeg -version shows the build configuration (which codecs are available, hardware accel support, etc.).