Field notes · 2026-11-15
Lossless trim of H.264 MP4 when the cut is not on a keyframe
You have an H.264-in-MP4 clip from a DVR with a few unwanted frames at the ends, but the first needed frame is mid-GOP. Can you cut those frames without re-encoding the whole file?
Answer
Answered by the Tracewind engineering team.
With H.264, a lossless bitstream cut only works cleanly on IDR keyframes. If your in-point sits inside a GOP, a pure copy cannot start on that exact frame: a decoder needs the preceding keyframe and the rest of the GOP. The same limit applies at the out-point if it is not on a keyframe.
A practical no-reencode approach is keyframe-aligned copy. In FFmpeg, place -ss after -i, keep -c copy, and set an end time, for example ffmpeg -i in.mp4 -ss START -to END -c copy -avoid_negative_ts make_zero out.mp4. That seeks to the previous keyframe, so you may keep a short run of frames you did not want, or lose a little after the end. Inspect keyframe times with ffprobe -show_frames -select_streams v:0 and note packets where key_frame=1.
When the leftover frames matter, re-encode only the partial GOPs at each end and stream-copy the intact GOPs in the middle (often called smart render). For trims under a second, re-encoding the whole short clip with libx264 at a high CRF and copying AAC is usually simpler. There is no general frame-accurate lossless delete for arbitrary H.264 frames inside MP4.
Where this question came from
The question is paraphrased from a public post on video (2026-11); the person who asked it has no link to us. Read the original thread