[FFmpeg-user] stream copy frame accuracy

t cadeparker at zoho.com
Mon Jun 1 18:21:36 CEST 2015


I know this might not be possible, but I'd at least appreciate understanding what's going on.

I have a video with forced keyframes every 2 seconds. Ideally, I was hoping I'd be able to get frame-perfect slices without having to re-encode. For example:

ffmpeg -ss 00:00:00 -i original.mp4 -t 2 -c copy slices_0.mp4
ffmpeg -ss 00:00:02 -i original.mp4 -t 2 -c copy slices_1.mp4
ffmpeg -ss 00:00:04 -i original.mp4 -t 2 -c copy slices_2.mp4
...

This doesn't quite seem to work.

Digging more into it, it looks like the first slice is frame-accurate, but everything after that has a slight offset (it might have other problems, but I'm just focusing on this for now). The first frame appears ok:

# same output
ffmpeg -ss 00:00:03 -i original.mp4 -vframes 1 o.png && md5 o.png
ffmpeg -ss 00:00:00 -i slices_1.mp4 -vframes 1 1.png && md5 1.png

But everything after that, is off:

# not the same output
ffmpeg -ss 00:00:04 -i original.mp4 -vframes 1 o.png && md5 o.png
ffmpeg -ss 00:00:01 -i slices_1.mp4 -vframes 1 1.png && md5 1.png

Whatever I do, I get the same result. If I look at the PTS for the original for frame 60, I get 2.002000 (instead of 2). But, even if I use this for my slice, I get the same offset.

What's going on?

(Probably not realted, but I'm also curious why the first frame of 0_slices.mp4 has an offset PST/DST, even though the original doesn't)




More information about the ffmpeg-user mailing list