From a video, I want to clip out a part I like. It's roughly from 12:34 to 43:21, so I do:

ffmpeg -i "input.mp4" -ss 12:34 -to 43:21 -c copy "output.mp4"

The result is cut exactly at those timestamps, not at keyframes, so I get a few seconds of audio with frozen image at both ends.

How do I tell ffmpeg to cut at closest keyframes?

I've tried putting -ss in front, like -ss 12:34 -i "input.mp4", this does start the clip at a keyframe, but it makes 12:34 the new 00:00, so -to won't work the same. Now I need to manually calculate the duration of my clip and put the duration after -to, but the calculation is too hard to be the best solution.

The official wiki suggests using -copyts to maintain the original timestamps, but it messes up the timeline, and the progress bar in the player shows a wrong total video length.

There's also a -noaccurate_seek flag which sounds like what I need, but is actually not what it sounds.

(In case it matters, I'm using ffmpeg v6.0, input v=AVC and a=AAC)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.