Search code examples
ffmpeg

ffmpeg timelapse resets PTS on frame size change


I have 601 sequential images, they change size and aspect ratio on frame 36 and 485, creating 3 distinct sizes of images in the set.

I want to create a timelapse and shave off the first 200 frames and only show the remaining 401, but if I do a trim filter on the input, the filter treats each of the 3 sections of different sized frames as separate 'streams' with their own reset PTS, all of which start at the exact same time. This means the final output of the below commmand is only 249 frames long instead of 401.

How can I fix this so I just get the final 401 frames?

ffmpeg \
-framerate 60 \
-i "./%07d.jpg" \
-filter_complex "
 [0]scale=1000:1000[in1];
 [in1]trim=start_frame=200[in2];
 [in2]setpts=PTS-STARTPTS
 " \
-r 60 -y trimmed.webm

Filters like setpts=N/(60*TB) or setpts=PTS-SETPTS after the scale to try and fix the frame times also seem to change nothing.

If I remove the trim and pts reset, the timelapse exports all 601 perfectly. If I remove the pts reset and leave the trim, it exports 449 frames starting on frame 0.

There's no errors or warning associated with the problem, other than the debug states the input reaches EOF on frame 449. (which is 485-36, the two section lengths, for some reason)

I understand pre-processing the image sizes is a way to fix this, but I'd like to understand why this isn't possible in one command.

version 6.0-6ubuntu1, but also happens on 6.1 and 5.1.

Even if I whittle it down to the bare minimum, it still incorrectly exports 450 frames:

ffmpeg -i "./%07d.jpg" -filter setpts=PTS-STARTPTS -y tpad.webm


Solution

  • When a video stream changes parameters mid-stream, ffmpeg reconfigures the filtergraph because only a few filters can reliably adapt to the variation. So you have to tell ffmpeg to avoid reconfiguring the filtergraph. You will still need to scale the images to a consistent size.

    Additionally, if you want to skip initial set of images, just start ingesting the images from the desired start point.

    ffmpeg \
    -reinit_filter 0 \
    -start_number 200 \
    -framerate 60 \
    -i "./%07d.jpg" \
    -vf "scale=1000:1000" \
    -y trimmed.webm