C.W.K.
Stream
Lesson 07 of 10 · published

Trimming — Cut Clips Without Re-Encoding (Mostly)

~12 min · trim, cut, seek, ss

Level 0Viewer
0 XP0/73 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

Two flavors of trim

Trimming is FFmpeg's most subtle operation because -ss and -t/-to behave differently depending on position and on whether you're copy-mode or re-encoding.

  • Fast, keyframe-aligned (copy mode)-ss before -i. Demuxer seeks to the nearest preceding keyframe. Output is sub-second to produce. Trim accuracy: ±1 keyframe interval (typically up to 5 seconds).
  • Frame-accurate (re-encode)-ss after -i. FFmpeg decodes from input start, discards frames before -ss, encodes the rest. Trim accuracy: exact frame. Cost: full re-encode.

The hybrid pattern (best of both)

Put -ss both before and after -i: pre-input does fast keyframe seek, post-input does frame-accurate adjustment. Modern FFmpeg makes pre-input seek frame-accurate when re-encoding too, so this hybrid trick is mostly historical — but it never hurts to know.

Specifying time

FFmpeg accepts -ss 90 (seconds), -ss 1:30 (mm:ss), or -ss 00:01:30.500 (hh:mm:ss.fff). -t is duration; -to is end-time. They're mutually exclusive.

Code

Fast trim with copy·bash
# Cut from 1:30 for 30 seconds — sub-second to produce, no quality loss
# Caveat: cut lands on the nearest preceding keyframe (could be ±2-5s off)
ffmpeg -ss 00:01:30 -i input.mp4 -t 30 -c copy out_clip.mp4

# End-time form
ffmpeg -ss 00:01:30 -i input.mp4 -to 00:02:00 -c copy out_clip.mp4
Frame-accurate trim with re-encode·bash
# Slower (full re-encode) but cuts exactly at 1:30.000
ffmpeg -i input.mp4 -ss 00:01:30 -t 30 \
  -c:v libx264 -crf 20 -preset slow -c:a aac -b:a 192k \
  out_clip_exact.mp4

# Hybrid (fast seek + accurate trim — mostly historical, modern FFmpeg
# does this automatically)
ffmpeg -ss 00:01:25 -i input.mp4 -ss 00:00:05 -t 30 \
  -c:v libx264 -crf 20 -c:a aac -b:a 192k \
  out_clip_hybrid.mp4

External links

Exercise

Take a 5-minute video. Cut a 30-second clip three ways and time each: (a) -c copy with -ss before -i, (b) re-encode with -ss after -i, (c) re-encode with -ss before -i. Verify the start frame in QuickTime — is the copy-mode cut precise to your -ss value, or did it snap to a keyframe?

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.