Free lesson

Trimming: fast copy or precise transcoding

Trimming: fast copy or precise transcoding — Automate simple video editing with FFmpeg. Stream copy does not decode frames; Decode and encode the desired five seconds; Accepting the cut. Practical assignment: Trimming: fast copy or precise transcoding.

Demo edition. The materials are undergoing editorial review.

Topics covered

  • Stream copy does not decode frames
  • Decode and encode the desired five seconds
  • Accepting the cut

Stream copy does not decode frames

Stream copying transfers encoded packets without video filtering or new compression. It is fast and useful for compatible remuxing, but does not promise arbitrary frame-exact cuts. Inter-frame codecs require reference frames, and seeking may retain packets before the requested point. The teaching source must exceed seven seconds; the command requests five seconds after position two. Inspect opening content, sound and actual duration. Lack of recompression loss does not imply a precise cut. MKV is a working container here, but actual stream compatibility still needs checking. For an exact spoken-word/frame boundary choose transcoding in the next step. Do not combine -vf with -c:v copy because filters need decoded images. Preserve the source even when the remux opens successfully; it may begin with unintended content.

ffmpeg -n -ss 2 -i originals/clip-a.mp4 -t 5 -map 0:v:0 -map "0:a:0?" -c copy work/a-copy.mkv

Decode and encode the desired five seconds

Use H.264/AAC transcoding for a more precise baseline cut. With -ss before input, default accurate seeking during transcoding decodes and discards excess material after the nearest seek point. -t 5 means output duration, not absolute end position five; starting at two gives approximately seconds two through seven. Inspect frame granularity, audio and encoder delay rather than promising arbitrary microsecond precision. The build needs libx264 and AAC. CRF 20 is an exercise starting point, not a universal reference. Audio is mandatory in this step, so a missing stream fails instead of silently producing a mute lesson. We set 48 kHz/stereo for later consistency, not to repair bad source audio. Keep output in work and use another name for subsequent experiments.

ffmpeg -n -ss 2 -i originals/clip-a.mp4 -t 5 -map 0:v:0 -map 0:a:0 -c:v libx264 -crf 20 -preset medium -pix_fmt yuv420p -c:a aac -ar 48000 -ac 2 work/a-cut.mp4

Accepting the cut

Compare a-copy and a-cut with the original at the desired passage. Check first/last words, accidental black opening and audio synchronization. ffprobe describes approximate duration, not word completeness. The fictional cut log expects five seconds; a few audio samples differ from a missing second of speech. If a whole second is missing, inspect source length, seek settings and early-EOF diagnostics. For silence check mapping and source rather than increasing volume on an audio-free file. Save command, FFmpeg version and observed review separately from expectations. A correctly named output is insufficient. The next lesson needs a cut with defined boundaries and known parameters, not the first command that happened to succeed. Retain diagnostic failures separately from accepted outputs until their cause is understood.

Practical assignment

Trimming: fast copy or precise transcoding

Continue to learning

Course outline

  1. Inspect files and define a CLI project
  2. Trimming: fast copy or precise transcoding
  3. Normalize clips and join without accidental gaps
  4. Audio level and subtitle filters
  5. Batch execution, validation and safe reruns
  6. Verify delivery and hand off a reproducible CLI project