Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ffmpeg's "setpts" filter do exactly? [closed]

Tags:

ffmpeg

I was looking for a very long time and everywhere I look it's just like it was something obvious, a common knowledge. What does the "setpts" filter of ffmpeg do exactly? Why would you want to reset it to zero with setpts=PTS-STARTPTS ? Thanks.

like image 726
ed22 Avatar asked Oct 06 '19 21:10

ed22


People also ask

What is Setpts?

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.

What is PTS ffmpeg?

PTS is presentation timestamp, the time at which the frame ought to be presented i.e. shown. If you divide each frame's timestamp by 2 (0 -> 0, 0.5 -> 0.25, 1 -> 0.5, 1.5 -> 0.75, 2 -> 1...), then you are running through the sequence of frames in half the time i.e at twice the speed.

How does the filter in FFmpeg work?

The filter first passes on preroll amount of frames, then it buffers at most buffer amount of frames and waits for the cue. After reaching the cue it forwards the buffered frames and also any subsequent frames coming in its input. The filter can be used synchronize the output of multiple ffmpeg processes for realtime output devices like decklink.

What is setpts in FFmpeg?

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/TBwhere N is frame index starting from 0, and TB is the timebase of the stream.

How to increase the speed of a video using FFmpeg?

setpts. The FFmpeg wiki has a good explanation of what setpts does: To double the speed of the video, you can use: ffmpeg -i input.mkv -filter:v "setpts=0.5*PTS" output.mkv. The filter works by changing the presentation timestamp (PTS) of each video frame.

How does the setpts filter work?

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/TBwhere 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.


2 Answers

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.

like image 110
Gyan Avatar answered Dec 17 '22 07:12

Gyan


When trimming values you can often run into issues where the start isn’t from 0 anymore. So when using the -ss and -t flag you might want to be re setting that

like image 21
Michael Goodrum Avatar answered Dec 17 '22 07:12

Michael Goodrum