2

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)

1 Answer 1

0

If you want frame accurate seeking, try putting your -ss flag after your input file.

So something like this:

ffmpeg -i original.mp4 -ss 00:00:04 -vframes 1 -f image2 0.png.

Putting the ss flag before the input file is going to be a 'rough guess' in terms of PTS, but has to snap to an I-frame to work. It happens much more quickly than putting the ss flag after your input file, but at a cost of being less accurate.

When you put the ss flag after the input file, FFmpeg will decode from the beginning of the file all the way through until your -ss time starts. It then dumps all of the information before the ss time... So it takes much longer, but it should be accurate.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .