ffmpeg commands cheatsheet.
Convert, extract, trim, resize, compress and screenshot media from the command line. Tap to copy.
ffmpeg -i in.mov out.mp4Convert a file to another formatffmpeg -i in.mp4 out.gifTurn a video into a GIFffmpeg -i in.wav out.mp3Convert audio to MP3ffmpeg -i in.mp4 -vn out.mp3Extract the audio from a videoffmpeg -i in.mp4 -ss 00:00:10 -t 5 out.mp4Clip 5 seconds starting at 10sffmpeg -i in.mp4 -vf scale=1280:-1 out.mp4Resize video to 1280px wide, keep ratioffmpeg -i in.mp4 -an out.mp4Remove the audio trackffmpeg -i in.mp4 -r 30 out.mp4Change the frame rate to 30fpsffmpeg -i in.mp4 -crf 23 out.mp4Re-encode with a quality/size tradeoffffmpeg -i in.mp4 -b:v 1M out.mp4Encode at a target video bitrateffmpeg -i in.mp4 -c copy out.mkvRewrap without re-encoding (fast)ffmpeg -i in.mp4 -ss 5 -vframes 1 shot.pngGrab a single frame as an imageffmpeg -i in.mp4 -vf fps=1 frame_%03d.pngExport one frame per secondffprobe in.mp4Print media info about a fileThe 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
-crfsets 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.-presettrades encoding time against efficiency, fromultrafasttoveryslow. It does not change the target quality, only how much CPU is spent reaching it.slowis a reasonable default when you are not in a hurry.-vf scale=1280:-2resizes to a width of 1280 and computes the height automatically. Use-2rather than-1so the result stays divisible by two, which most codecs require.-androps audio and-vndrops 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.