Tutorials

FFmpeg cheat sheet — 20 commands I use weekly

· Tutorials

20 FFMPEG commands I use weekly — convert, trim, concat, overlay, extract audio, generate GIFs, optimize for web. Copy these and skip the docs dive.

FFmpeg cheat sheet — 20 commands I use weekly

20 FFMPEG commands I use weekly — convert, trim, concat, overlay, extract audio, generate GIFs, optimize for web. Copy these and skip the documentation dive.

Conversions

1. Convert MP4 to WebM (better compression)

-crf 30 is the quality (0-63, lower = better). -b:v 0 lets CRF drive the bitrate.

2. Convert MP4 to GIF (with palette)

# Right way (palette-generated, 80% smaller): ffmpeg -i input.mp4 -vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif

The palette step is what makes GIFs look good at small sizes. Without it, GIFs use a 256-color global palette and look terrible.

3. Convert video to images (for thumbnails)

# One frame every 10 seconds: ffmpeg -i input.mp4 -r 1/10 frames/frame%04d.jpg

Trimming

4. Trim by start/end time (no re-encoding)

-c copy skips re-encoding — instant, no quality loss. The catch: cuts only at keyframes, so the trim might be off by ~1 second.

5. Trim with re-encoding (precise)

Accurate to the frame, but slower (re-encodes the entire clip).

6. Trim first 30 seconds

-t 30 = duration (30 seconds from start).

Concatenation

7. Concatenate two videos (same codec)

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

-c copy is instant. Works only if all videos have the same codec, resolution, and framerate.

8. Concatenate different codecs (re-encode)

Slower but works across different video sources.

Audio

9. Extract audio from video

-vn = no video. -q:a 4 = MP3 quality (0-9, lower = better, 4 is good default).

10. Replace audio in video

Keeps the video stream, replaces the audio. Useful for re-dubbing or fixing bad audio.

11. Concatenate audio files

Instant, no re-encoding.

ansaribilal.com — technology, tested in public.