Guide

FFmpeg Cheat Sheet: 14 Common Commands for Subtitles, Trimming, GIFs, Remuxing and Encoding

Burning in subtitles, extracting audio, how the position of -ss changes trimming, resizing, GIFs, MKV to MP4 remuxing, VFR to CFR, and basic x264, x265 and SVT-AV1 encoding. Each command comes with what its options mean and the usual mistakes.

FFmpeg has so many options that most people search and copy a command every time. This page collects 14 common jobs, one command each. Every command comes with a one-line description, what its options mean, and the mistakes people often make the first time.

In the commands, in.mp4 and out.mp4 are example file names, and numbers such as CRF 20, the presets and 12 fps are examples too. This page does not publish measured numbers. To pick a CRF for your quality target, use the CRF Recommender and our lab articles.

A few things to know first

  • The basic form is ffmpeg [input options] -i input [output options] output. An option applies to the file that comes right after it, so the same -ss means different things before or after -i (see “Trimming” below).
  • -c copy moves the data as it is without re-encoding, so it is fast and loses no quality. In return, you can't combine it with filters (-vf), and the destination container has to accept the codec.
  • If the output file already exists, FFmpeg asks whether to overwrite it. Put -y early in the command to overwrite without asking, or -n to never overwrite.
  • Wrap paths with spaces in double quotes. FFmpeg interprets commas and colons inside a filter on its own, so it is safer to wrap the whole filter in double quotes (see the Filtergraph syntax lesson).

1. Basic H.264 (x264) encode

The standard recipe for an H.264 MP4, the most widely compatible format. Use it when you want the file to play on any device.

Command
ffmpeg -i in.mp4 -c:v libx264 -crf 20 -preset medium -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart out.mp4

What the options mean

-c:v libx264
Use x264 as the video encoder.
-crf 20
The quality target. Lower means higher quality and a bigger file; 20 is just an example.
-preset medium
Trades encoding time for file size. Slower presets tend to give smaller files at the same quality.
-pix_fmt yuv420p
Sets the pixel format to 8-bit 4:2:0, for playback compatibility.
-c:a aac -b:a 128k
Encodes the audio as AAC at 128 kbps.
-movflags +faststart
Moves the MP4's table of contents (moov) to the front so web playback starts quickly.

Common mistakes

  • Carrying a CRF number over to another codec. x264 at 20 and x265 at 20 are not the same quality. When you switch codecs, find the value for the same VMAF with the conversion chart or the CRF Recommender.
  • Using -pix_fmt yuv420p as it is on HDR or 10-bit sources. Dropping to 8-bit can make the colors look washed out. HDR needs separate handling.
  • Assuming a slower preset alone raises quality. A preset mostly trades time and file size at the same CRF.

Related tools and lessons: FFmpeg Command Builder · CRF Recommender · HandBrake RF to FFmpeg CRF and SVT-AV1 Conversion Chart (Equal-VMAF Measurements) · Encoding with ffmpeg: CRF, GOP, Profile, and Preset Options Explained · CRF vs. 2-pass vs. CQ: What Do You Fix?

2. Basic HEVC (x265) encode

An HEVC MP4 aimed at smaller files than H.264. Use it when the devices that will play it support HEVC.

Command
ffmpeg -i in.mp4 -c:v libx265 -crf 24 -preset medium -tag:v hvc1 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart out.mp4

What the options mean

-c:v libx265
Use x265 as the video encoder.
-crf 24
The same number as x264 does not mean the same quality. 24 is an example.
-tag:v hvc1
Writes the HEVC tag in the MP4 as hvc1. Some Apple devices and QuickTime are known not to read the default tag (hev1).
-pix_fmt yuv420p
8-bit 4:2:0. For 10-bit, use yuv420p10le.

Common mistakes

  • Leaving out -tag:v hvc1, so the file won't play on Apple devices.
  • Not checking whether the viewer's device or browser plays HEVC. Support differs by device and browser.
  • Using the same CRF number as x264 and wondering why the quality differs.

Related tools and lessons: Codec Support Checker · CRF Recommender · Encoding 10-bit HDR10 with x265

3. Basic AV1 (SVT-AV1) encode

The standard recipe for compressing to AV1. The encoder is libsvtav1.

Command
ffmpeg -i in.mp4 -c:v libsvtav1 -crf 32 -preset 6 -pix_fmt yuv420p -c:a aac -b:a 128k out.mp4

What the options mean

-c:v libsvtav1
The SVT-AV1 encoder. An FFmpeg build without it fails with an “Unknown encoder” error.
-crf 32
The quality target. The range and meaning differ from x264 and x265, so treat 32 as an example only.
-preset 6
In SVT-AV1, a lower preset number is slower and more efficient. That is a different sense of direction from x264's named presets.

Common mistakes

  • Using x264-style names such as medium as an SVT-AV1 preset. SVT-AV1 takes numbers.
  • Publishing in AV1 without checking where it will play. AV1 decoding support differs by device.
  • Starting a long video without estimating the encoding time. Run a short section first.

Related tools and lessons: Codec Support Checker · Encoding Time Estimator · Choosing a Preset: The Value That Trades Time for Size

4. Changing the resolution

Shrinks the height to 720 while keeping the aspect ratio.

Command
ffmpeg -i in.mp4 -vf scale=-2:720 -c:v libx264 -crf 20 -c:a copy out.mp4

What the options mean

-vf scale=-2:720
Sets the height to 720 and works out the width from the aspect ratio. -2 tells FFmpeg to round the result to a multiple of 2.
-c:v libx264 -crf 20
Using a filter means the video has to be re-encoded.
-c:a copy
Copies the audio untouched.

Common mistakes

  • Using -1 instead of -2. If the computed value is odd, yuv420p encoding can stop with an error.
  • Enlarging a small video and expecting better quality. Scaling up does not create detail that wasn't there.
  • Combining -c:v copy with -vf. A filter needs re-encoding, so the two can't be used together.

Related tools and lessons: Size and Frame Rate: scale, zscale, fps · Filtergraph Syntax: -vf and -filter_complex · Video File Size & Bitrate Calculator

5. Trimming 1: fast (lossless)

Cuts 30 seconds starting at the 1-minute mark without re-encoding. No quality loss and very fast, but the start may not be exact.

Command
ffmpeg -ss 00:01:00 -i in.mp4 -t 30 -c copy out.mp4

What the options mean

-ss 00:01:00 (before -i)
Jumps straight to near that time in the input file.
-t 30
Keeps only 30 seconds of length from the start point.
-c copy
No re-encoding.

Common mistakes

  • Believing the cut starts at the exact frame you want. -c copy can only cut at keyframes, so the start may slip back to a nearby earlier keyframe. For what a keyframe is, see the GOP structure lesson.
  • Getting audio and video out of sync in the result and not knowing why. You can try adding -avoid_negative_ts make_zero.
  • Removing only -c copy from this command to cut exactly. For an exact cut, name an encoder as in the next entry.

Related tools and lessons: GOP Structure Explained: Keyframe Interval, Closed vs. Open GOP · Timestamps: PTS, DTS, and Timebase

6. Trimming 2: exact (re-encoded)

Cuts from 1:00 to 1:30 with frame accuracy and encodes it anew.

Command
ffmpeg -i in.mp4 -ss 00:01:00 -to 00:01:30 -c:v libx264 -crf 20 -c:a aac out.mp4

What the options mean

-ss, -to (after -i)
Reads the input, discards the beginning, and keeps what lies between those times in the original video.
-c:v libx264 -crf 20
Re-encodes the cut section, so the first frame is exact.
-c:a aac
Encodes the audio anew as well.

Common mistakes

  • Putting -ss before -i but writing -to on the output side. It is read as the time elapsed since the start, so the clip comes out longer than expected. In that case give a length with -t instead of -to.
  • Waiting a long time cutting the end of a long video with -ss after -i, because everything before it is read and thrown away. When you re-encode, FFmpeg matches the exact frame by default even with -ss before -i (you can turn that off with -noaccurate_seek).
  • Re-encoding every time when you only want to cut. If you don't need exactness, use entry 1.

Related tools and lessons: GOP Structure Explained: Keyframe Interval, Closed vs. Open GOP · Video File Size & Bitrate Calculator

7. MKV to MP4 remux (no re-encoding)

Keeps the video and audio as they are and only changes the box from MKV to MP4. No quality loss, and it takes seconds.

Command
ffmpeg -i in.mkv -map 0:v -map 0:a -c copy -movflags +faststart out.mp4

What the options mean

-map 0:v -map 0:a
Takes all video and audio tracks of the input. Subtitles are not included.
-c copy
Copies as is, without encoding.
-movflags +faststart
Moves moov to the front for web playback.

Common mistakes

  • Trying to carry over ASS or PGS subtitle tracks too and getting an error. MP4 can't hold those subtitles as they are. Map only video and audio as above, or convert text subtitles separately.
  • Failing because the file holds a codec that MP4 doesn't accept. Check the track layout first; the checker reads the tracks and tells you whether it can work.
  • Expecting the file to get smaller after remuxing. The data is moved as it is, so the size stays almost the same.

Related tools and lessons: MKV to MP4 Remux Feasibility Checker · Video File Info Viewer · Reading Structure with ffprobe, and What Remuxing Can and Can't Do · faststart: Why moov Needs to Come First

8. VFR to CFR (constant frame rate)

Turns a video with uneven frame spacing into a steady 30 fps. Use it when sync drifts in an editor.

Command
ffmpeg -i in.mp4 -fps_mode cfr -r 30 -c:v libx264 -crf 20 -c:a copy out.mp4

What the options mean

-fps_mode cfr
Duplicates or drops frames so that output frames are evenly spaced. This is the name used since FFmpeg 5.1; older versions use -vsync cfr.
-r 30
The target frame rate. Write 29.97 as 30000/1001.
-c:v libx264 -crf 20
Re-encoding is required because the frames change.

Common mistakes

  • Trying to make CFR with -c copy. It can't work, because frames have to be duplicated or dropped.
  • Picking 30 at random without knowing the source's average frame rate. Check the average and the most common interval with the detector first.
  • Writing 29.97 directly as -r 29.97. Writing it as a fraction is more exact.

Related tools and lessons: Variable Frame Rate (VFR) Detector · Size and Frame Rate: scale, zscale, fps · Timestamps: PTS, DTS, and Timebase

9. Subtitles 1: burning them into the video

Engraves the subtitles into the video's pixels. They show up in any player, but you can't turn them off.

Command
ffmpeg -i in.mp4 -vf "subtitles=sub.srt" -c:v libx264 -crf 20 -c:a copy out.mp4

What the options mean

-vf "subtitles=sub.srt"
Draws text subtitles (SRT, ASS and so on) over the video. It needs a build that includes the subtitle rendering library (libass).
force_style='FontSize=24'
Add it as in subtitles=sub.srt:force_style='FontSize=24' to change styles such as font size.
-c:a copy
Copies the audio.

Common mistakes

  • Using a full path like C:\... on Windows, where the filter misreads the colon and fails. It is easier to keep the subtitle file in the same folder as the video and use just the file name.
  • Trying to read image subtitles such as Blu-ray PGS with subtitles. They are pictures and can't be read that way; use overlay.
  • Trying to fix drifting subtitles with the filter. It is better to correct the subtitle file first and then burn it in.
  • Combining it with scale without thinking about the order. The size of the subtitle text changes.

Related tools and lessons: Burning In Subtitles: subtitles, ass, overlay · Subtitle Sync Fixer

10. Subtitles 2: adding them so they can be turned on and off

Puts the subtitles in the MP4 as a separate track. The video isn't re-encoded, and the player can switch the subtitles on and off.

Command
ffmpeg -i in.mp4 -i sub.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=kor out.mp4

What the options mean

-i in.mp4 -i sub.srt
Two inputs: the video and the subtitle file.
-map 0 -map 1
Takes every track of the first input and the second input (the subtitles).
-c copy -c:s mov_text
Copies video and audio, and converts only the subtitles to mov_text, the text subtitle format MP4 accepts.
-metadata:s:s:0 language=kor
Labels the first subtitle track's language as kor.

Common mistakes

  • Using only -c copy without naming a subtitle format and getting an error that MP4 can't hold SRT. For MP4 you have to convert to mov_text.
  • Expecting ASS fonts, colors and positioning effects to survive. mov_text is known to support only simple styles, so the decoration may be lost. To keep effects, burn them in or use MKV.
  • Thinking it failed because the subtitles aren't showing. Many players don't turn them on by default, so check the subtitle menu.

Related tools and lessons: Subtitle Sync Fixer · Reading Structure with ffprobe, and What Remuxing Can and Can't Do

11. Extracting only the audio

Pulls the sound out into a file without the video. If the audio is AAC, copying is enough; otherwise convert it, for example to mp3.

Command
# AAC → m4a
ffmpeg -i in.mp4 -vn -c:a copy out.m4a
# mp3
ffmpeg -i in.mp4 -vn -c:a libmp3lame -q:a 2 out.mp3

What the options mean

-vn
Leaves out the video stream.
-c:a copy
Pulls the audio out without encoding. Use it like saving AAC audio as .m4a.
-c:a libmp3lame -q:a 2
Converts to mp3. -q:a is the VBR quality value, and lower means higher quality. 2 is an example.

Common mistakes

  • Making an .m4a with -c:a copy when the source audio isn't AAC. The audio codec and the extension have to match. Check the audio codec first.
  • Re-compressing already lossy audio to mp3 and thinking it is the same as the original. It loses a bit more.
  • Not noticing that the file has several audio tracks and only the first came out. Pick a track by number, as in -map 0:a:1.

Related tools and lessons: Video File Info Viewer · Comparing Lossy Codecs: MP3, AAC (LC/HE), and Opus · Audio Compatibility by Container, and How to Check

12. Making a GIF

Makes a 4-second GIF starting at 5 seconds. It builds a palette separately so the colors get muddied less.

Command
ffmpeg -ss 5 -t 4 -i in.mp4 -vf "fps=12,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 out.gif

What the options mean

fps=12
Lowers the frames per second to cut the size.
scale=480:-1:flags=lanczos
Shrinks the width to 480 and keeps the aspect ratio. Lanczos is one scaling algorithm.
palettegen / paletteuse
A GIF has at most 256 colors, so it first builds a palette that fits the video (palettegen) and then converts with that palette (paletteuse).
-loop 0
Saves it to loop forever.

Common mistakes

  • Converting straight to out.gif without a palette. The colors tend to look muddy.
  • Turning a long video into a GIF and being shocked by the size. GIF is an inefficient format. On the web, a short MP4 or WebM often replaces it.
  • Not quoting the filter, so the commas and semicolons are split up by the shell.

Related tools and lessons: Filtergraph Syntax: -vf and -filter_complex · Size and Frame Rate: scale, zscale, fps

13. Saving one or many frames as images

Saves one frame at a given time as an image, or one frame every second.

Command
# one frame
ffmpeg -ss 00:00:05 -i in.mp4 -frames:v 1 frame.png
# one frame per second
ffmpeg -i in.mp4 -vf fps=1 frame_%03d.png

What the options mean

-ss 00:00:05
Jumps to the 5-second mark.
-frames:v 1
Outputs only one video frame.
-vf fps=1
Keeps one frame per second.
frame_%03d.png
%03d is the slot that gets a number: 001, 002 and so on.

Common mistakes

  • Extracting many frames but writing a single file name without the number slot (%03d). The images overwrite each other and only one is left.
  • Saving as JPG and being surprised by the low quality. JPG quality is set with -q:v, and lower means higher quality.
  • Looking at only one representative frame when hunting a quality problem. How to pull several frames from a suspect section is in the Pulling Out Suspect Segments lesson.

Related tools and lessons: Pulling Out Suspect Segments: ffmpeg and Per-Frame VMAF

14. Joining videos

Joins several video files made with the same settings into one without re-encoding.

Command
# list.txt
file 'part1.mp4'
file 'part2.mp4'

ffmpeg -f concat -safe 0 -i list.txt -c copy out.mp4

What the options mean

list.txt
A list file with one file 'name' per line.
-f concat
Uses the concat demuxer, which reads the input from a list file.
-safe 0
Allows “unsafe” names such as absolute paths in the list.
-c copy
Joins without encoding.

Common mistakes

  • Joining files with different codecs, resolutions or frame rates using -c copy. Playback can break. If the settings differ, use the concat filter, which re-encodes.
  • Not escaping a single quote in a file name. Names in the list file follow quoting rules.
  • Not suspecting the timestamps when audio cuts out or goes out of sync at the join. It can happen when the files start at different times.

Related tools and lessons: Timestamps: PTS, DTS, and Timebase · Filtergraph Syntax: -vf and -filter_complex

Where to put -ss: comparing trimming methods

Even for the same “from the 1-minute mark”, the result depends on where -ss goes and whether you use -c copy. The table below summarizes how FFmpeg behaves; the speeds are not values measured on this site.

MethodStart positionNature of the speedWhat -to refers to
-ss before + -c copyMay slip back to a nearby earlier keyframeJumps straight there with no re-encoding, fastOutput time (elapsed since the start). Prefer -t
-ss before + re-encodeFrame-accurate (default behavior)Jumps straight to the start point, fairly fastOutput time (elapsed since the start). Prefer -t
-ss after + re-encodeFrame-accurateReads and discards the beginning, so slower the later the positionA time in the original video
-ss after + -c copyThe state of the start differs by file, so not recommendedReads from the beginningA time in the original video

In short: if you don't need exactness, use “before + copy”. If you do, re-encode, put -ss before -i, and give the end with -t; that way nothing gets confusing.

Good to know: limits

  • The commands here were written for a typical recent FFmpeg build. Depending on the build, an encoder (libsvtav1, libx265) or a filter (subtitles) may be missing; if you get an error, check with ffmpeg -encoders and ffmpeg -filters.
  • Some option names changed between versions (-fps_mode replaced -vsync). With an old FFmpeg, check the documentation for that version.
  • Numbers such as CRF, presets, fps and width are all examples. Quality and file size vary a lot with the content, so for important jobs run a short section first.
  • This page did not measure speed, size or quality itself. For such numbers, see our lab articles and the published data behind our tools.
  • To avoid overwriting your source, give the output a different name from the input, and keep the original before you start.

Frequently asked questions

How do I trim a video without re-encoding?

Put -ss before -i, give the length with -t, and use -c copy (for example: ffmpeg -ss 00:01:00 -i in.mp4 -t 30 -c copy out.mp4). There is no quality loss and it is very fast, but -c copy can only cut at keyframes, so the start may slip back to a nearby earlier keyframe.

What's the difference between putting -ss before -i and after it?

-ss before -i jumps straight to near that time in the input file, and -to is then read as output time (elapsed since the start), so prefer -t. -ss after -i reads and discards the beginning, so it is slower the later the position, and the time refers to the original video. For an exact cut, re-encode, put -ss before -i, and give the end with -t; that way nothing gets confusing.

Does remuxing MKV to MP4 make the file smaller?

No. Remuxing moves the data as it is, so the size stays almost the same. Also, MP4 can't hold subtitle tracks such as ASS or PGS as they are, which can cause an error, so map only video and audio, or convert text subtitles separately.

I get an error with -fps_mode cfr. Why?

-fps_mode is the name used from FFmpeg 5.1 onward; older versions use -vsync cfr. Because it changes frames, re-encoding is required. Some option names have changed between versions, so with an older FFmpeg, check the manual for that version.

What if FFmpeg says the libsvtav1 or libx265 encoder isn't available?

Depending on the build, an encoder (libsvtav1, libx265) or a filter (subtitles) may be missing. Run ffmpeg -encoders and ffmpeg -filters to see what your build has.