[FFmpeg-user] Recorded Frame Timestamps are Inconsistent! How to Fix it?

Mark Filipak (ffmpeg) markfilipak at bog.us
Tue Mar 16 04:49:11 EET 2021


On 2021-03-15 13:43, Hassan wrote:
> Hello,
> 
> I am using ffmpeg on a Windows 10 machine and I want to record the desktop
> at a high frame rate while appending accurate timestamps to each frame.
> I am recording my desktop using the following command:
> 
> ffmpeg -f gdigrab -framerate 60 -i desktop -vf "settb=AVTB,
> setpts='trunc(PTS/1K)*1K+st(1,trunc(RTCTIME/1K))-1K*trunc(ld(1)/1K)',
> drawtext=fontfile=ArialBold.ttf:fontsize=40:fontcolor=white:text='%{localtime}.%{eif\:1M*t-1K*trunc(t*1K)\:d}:box=1:boxborderw=20:boxcolor=black at 1.0:x=10:y=10'"
> -c:v libx264rgb -crf 0 -preset ultrafast output.mkv
> 
> The long text next to -vf flag is used to append timestamp (date and
> current time in milliseconds) on the top left corner of the frame with
> black background.
> 
> The issue is that, ideally, when I am recording at 60 FPS, each subsequent
> frame should have a timestamp with an increment of 16.66 msec. However, the
> timestamp is not incremented as such. Instead, it stays the same on a lot
> of frames and then changes.
> 
> For example, when I break the video into frames, the frame titled
> "img0428.png" has the timestamp 18:44:16.828 (hh:mm:ss.millisec)
> [image: image.png].
> Then until "next 40 frames, it says the same. On file "img0469.png", the
> timestamp changes and becomes 18:44:17.510.
> [image: image.png]
> So, the timestamp changed after 41 frames and the time difference is 682
> milliseconds. Ideally, each of the 40 frames between these two frames
> should carry an incremental timestamp by a step size of 16.66 msec but this
> is not happening.

Hello Hassan,

I don't know anything about 'gdigrab' but I have a lot of experience with frame rate manipulation.

"I am recording at 60 FPS..."
A little higher than 60 fps. Look:

(468 - 428 + 1 frames)/(17510[+/-0.5...] - 16828[+/-0.5...] ms)(1000 ms/s) = 60.029 to 60.206 frames/s.

"...with an increment of 16.66 msec."
The 'gdigrab' timing resolution may not be +/-0.01 ms. For example, it may be +/-0.1 ms or even +/-1 ms.

If you can tolerate setting fps to exactly 60 (you're saving video to disk, you're not streaming to 
the Internet), put this:

settb=expr=1/720000,setpts=N*12000,fps=60,

at the beginning of the filter chain. It will set frame rate to exactly 60fps and will also preserve 
excellent timing resolution (0.013[8..] ms) in any succeeding processing (without affecting the 
final encoder).

Regards,
Mark.


More information about the ffmpeg-user mailing list