What does ffmpeg's "setpts" filter do exactly?

PTS stands for Presentation TimeStamps. See What is video timescale, timebase, or timestamp in ffmpeg?

The setpts filter evaluates the expression and assigns the value as the timestamp for the current frame it is processing

e.g. setpts=2*N+5/TB where N is frame index starting from 0, and TB is the timebase of the stream. Let's say it is 1/1000, so each PTS unit is 1 millisecond.

So, for each frame, it would go as follows,

N       expression        New PTS    New PTS time
0     2*0+5/(1/1000)       5000        5.000 sec
1     2*1+5/(1/1000)       5002        5.002 sec
2     2*2+5/(1/1000)       5004        5.004 sec
...

Filters which work upon multiple inputs sync by timestamp i.e. in overlay filter, the filter will overlay overlay input with timestamp 5.0 upon main input with PTS time 5.0. If the streams have different starting PTS, this can lead to unexpected output, so timestamps are reset so each stream starts from 0. Of course, if you have a custom sync in mind, then you would modify the setpts expr accordingly.

Another reason is that when a stream has a non-zero starting timestamp, ffmpeg may duplicate frames in -vsync cfr mode to plug the gap from timestamp 0 till that initial timestamp. This is only relevant in a few scenarios.

Tags:

Ffmpeg