videoffmpegvideo-processingpts

Why am I unable to scale a 4-second 60 fps clip down to exactly 1 second?


I'm currently using the setpts filter to speed up or slow down different clips and accuracy is very important to me ( context: I'm concatenating these into a final clip that needs to be perfectly in sync with a separate video.) I've been using this as a general approach:

setpts=(targetDuration/totalFrameCount)*N/TB" -r targetDuration/totalFrameCount

While it's fairly accurate most of the time, I'm wondering if I can get better results. For example, if I attempt to scale a 4-second 60fps clip down to exactly 1 second, i.e.:

ffmpeg -y -i clip_4sec.avi -filter:v "setpts=(1/240)*N/TB" -r 240/1 clip_4sec_scaled_to_1sec.avi

I actually end up with a 992ms clip. Does anyone know why this happening? From my understanding, as long as the target duration is a multiple of frame duration ( 1/60 seconds ) this shouldn't be an issue, correct?

Is there a better approach I can take to improve the accuracy?

Note: FWIW I already double-checked that the input clip has an actual frame count of 240


Solution

  • The source is 60 fps, and its timebase going into and out of the setpts filter is 1/60. This should be set to 1/240 before PTS is altered.

    ffmpeg -y -i clip_4sec.avi -filter:v "settb=1/240,setpts=(1/240)*N/TB" -r 240/1 clip_4sec_scaled_to_1sec.avi
    

    There's likely a bug here with the implementation of -r w.r.t. VFR muxers like AVI.