Cut, Trim & Concatenate in FFmpeg—Without Re‑Encoding

Tue Jun 18 2024

Fast vs accurate seeking, stream copy, and when to use concat demuxer or the concat filter.

Need quick edits without a full render? FFmpeg can copy streams around to cut and join content rapidly. Here’s how to pick the right approach.

Seeking and Trimming

# Quick cut (fast seek, may not be frame-accurate) ffmpeg -ss 00:01:00 -to 00:02:30 -i in.mp4 -c copy clip_fast.mp4 # More accurate trim (seek after input, re-encodes) ffmpeg -i in.mp4 -ss 00:01:00 -to 00:02:30 -c:v libx264 -crf 22 -c:a aac -b:a 128k clip_acc.mp4

Concatenation

# Concat demuxer (same codecs) # list.txt: # file 'part1.mp4' # file 'part2.mp4' ffmpeg -f concat -safe 0 -i list.txt -c copy joined.mp4 # Concat filter (different codecs → re-encode) ffmpeg -i a.mp4 -i b.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" \ -map "[v]" -map "[a]" -c:v libx264 -crf 22 -c:a aac -b:a 128k joined_enc.mp4

Pitfalls

  • Copying around non‑keyframe cuts can cause A/V desync.
  • Mixed properties (fps/size/codecs) require re‑encoding.

When speed matters and sources match, prefer stream copy; otherwise, re‑encode for correctness.