ffmpeg Commands

ffmpeg commands cheatsheet.

Convert, extract, trim, resize, compress and screenshot media from the command line. Tap to copy.

Convert & basics
ffmpeg -i in.mov out.mp4Convert a file to another format
ffmpeg -i in.mp4 out.gifTurn a video into a GIF
ffmpeg -i in.wav out.mp3Convert audio to MP3
ffmpeg -i in.mp4 -vn out.mp3Extract the audio from a video
Trim & resize
ffmpeg -i in.mp4 -ss 00:00:10 -t 5 out.mp4Clip 5 seconds starting at 10s
ffmpeg -i in.mp4 -vf scale=1280:-1 out.mp4Resize video to 1280px wide, keep ratio
ffmpeg -i in.mp4 -an out.mp4Remove the audio track
ffmpeg -i in.mp4 -r 30 out.mp4Change the frame rate to 30fps
Compress & encode
ffmpeg -i in.mp4 -crf 23 out.mp4Re-encode with a quality/size tradeoff
ffmpeg -i in.mp4 -b:v 1M out.mp4Encode at a target video bitrate
ffmpeg -i in.mp4 -c copy out.mkvRewrap without re-encoding (fast)
Frames & info
ffmpeg -i in.mp4 -ss 5 -vframes 1 shot.pngGrab a single frame as an image
ffmpeg -i in.mp4 -vf fps=1 frame_%03d.pngExport one frame per second
ffprobe in.mp4Print media info about a file
Replace in/out filenames with your own. ffmpeg infers formats from the file extension you give it.

The Swiss-army knife for media

ffmpeg converts almost anything with ffmpeg -i input output — the extensions decide the formats. Add -ss and -t to trim, -vf scale to resize, -crf to control quality, and -c copy to rewrap without re-encoding (much faster). Use ffprobe to inspect a file.

Copy versus re-encode: the decision that matters most

Almost every ffmpeg question comes down to one choice. -c copy remuxes — it moves the existing compressed streams into a new container without touching them. It finishes in seconds even on a large file, and there is zero quality loss because nothing is decoded. Use it whenever you are only changing the container, trimming on a clean boundary, or stripping a stream.

Re-encoding decodes and recompresses. It is slow, it always loses some quality, and it is unavoidable when you genuinely need to change something about the picture or sound — resizing, changing codec, adjusting bitrate, applying a filter. The rule of thumb: if you are not changing the pixels or the samples, do not re-encode.

Where -ss goes, and why trims drift

Placing -ss before -i makes ffmpeg seek to that point in the input, which is fast. Placing it after -i makes it decode from the start and discard frames, which is slow but frame-accurate. For most trims, before is what you want.

The complication is keyframes. With -c copy, ffmpeg can only cut at a keyframe, because a cut anywhere else would leave frames with no reference to decode from. Ask for a trim starting at 00:01:07 and the output may begin a second or two earlier or later, at the nearest keyframe. If the exact frame matters, you must re-encode; if speed matters more, accept the drift. That trade-off, not a bug, explains nearly every report of a trim starting in the wrong place.

Quality settings worth knowing

  • -crf sets constant quality for x264 and x265. Lower is better quality and a larger file. Around 18 is visually near-lossless, 23 is the x264 default, and 28 is noticeably compressed. Changing it by 6 roughly halves or doubles the file size.
  • -preset trades encoding time against efficiency, from ultrafast to veryslow. It does not change the target quality, only how much CPU is spent reaching it. slow is a reasonable default when you are not in a hurry.
  • -vf scale=1280:-2 resizes to a width of 1280 and computes the height automatically. Use -2 rather than -1 so the result stays divisible by two, which most codecs require.
  • -an drops audio and -vn drops video — the quickest way to extract one stream.

When extracting audio that is already in the format you want, add -c copy so it is lifted out rather than re-encoded.

Inspect before you convert

Run ffprobe on a file before doing anything else. It reports the container, the codecs, resolution, frame rate, bit rate and duration — which is usually enough to tell you whether a remux will do the job or a re-encode is genuinely needed.

It is also the fastest way to diagnose a file that will not play somewhere: the problem is normally a codec the target device does not support rather than anything wrong with the file. Related references: MIME types for serving media over the web, and file extensions for what a container actually is.

FAQ

How do I extract audio from a video with ffmpeg?
Run ffmpeg -i input.mp4 -vn output.mp3 — the -vn flag drops the video and keeps only the audio.
How do I trim a clip without re-encoding?
Use ffmpeg -i input.mp4 -ss 00:00:10 -t 5 -c copy output.mp4 to copy 5 seconds from the 10-second mark quickly, without quality loss.
What does -c copy do?
It remuxes rather than re-encodes, moving the existing compressed streams into a new container untouched. That makes it near-instant and completely lossless, so use it whenever you are only changing the container, trimming, or removing a stream.
Why does my trimmed clip start at the wrong time?
Because with -c copy ffmpeg can only cut at a keyframe, since frames in between have no reference to decode from. The output starts at the nearest keyframe, which may be a second or two out. Re-encode if you need the exact frame.
What CRF value should I use?
Lower means better quality and a bigger file. About 18 is visually near-lossless, 23 is the x264 default, and 28 is noticeably compressed. A change of roughly 6 either halves or doubles the file size.
Should -ss go before or after -i?
Before -i seeks straight to that point and is fast, which suits most trims. After -i decodes from the start and discards frames, which is slow but frame-accurate.

More cheatsheets