When the cut has to land on a specific frame — say, to remove a single frame at a scene transition — stream-copy trimming is not enough, because it snaps to keyframes. Re-encoding trimming decodes the source, picks the exact frame at the requested time, and re-encodes. It is slow, but precise.

The command

ffmpeg -i input.mp4 -ss 00:01:30 -to 00:03:00 -c:v libx264 -c:a aac output.mp4

What it does

The -ss and -to flags are placed after -i, which tells FFmpeg to seek in the decoded frame domain. FFmpeg decodes to the requested timestamps, drops the rest, and re-encodes only the kept segment. Audio is trimmed at the nearest audio frame boundary, which is usually 20 to 40 ms — close enough for most use cases.

When to use it

For broadcast deliverables, precise edits, or any time the cut point matters. The output frame at the cut is exactly the frame at the requested timestamp, not the nearest keyframe. Re-encoding takes longer than stream-copy and loses the original encoding, so prefer stream-copy unless you need the precision.

Video and audio requirements

Any decodable source. Encoding settings default to CRF 23 for H.264 and 128 kbps AAC; adjust with -crf and -b:a for your quality target. For lossless cuts, add -c:v libx264 -qp 0 -preset ultrafast, though the result is much larger.

Things to avoid

  • Using this for rough cuts. It is 50 to 200 times slower than stream-copy and degrades quality by one encode generation.
  • Forgetting that the re-encode changes the file's encoding history. Color space, HDR metadata, and audio loudness can shift; verify if it matters.
  • Trimming AC-3 or EAC-3 audio without the right decoder. FFmpeg will error; install the codec or use stream-copy and accept a less precise audio cut.
  • Expecting the output to be keyframe-aligned. A re-encode produces its own keyframes wherever the preset decides, which may not match downstream workflows.