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

pdr0 pdr0 at shaw.ca
Mon Mar 15 21:09:02 EET 2021

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.
> Therefore, my questions are as follows:
> 1. Am I using the right method to append timestamps to the recorded
> frames?
> 2. What is the reason that the timestamping on the frames is not correct?
> 3. How can I fix this issue?
> 4. What are the alternate methods to append accurate epoch timestamps to
> each of the recorded frames?
> Please guide me. Thanks.
> -- 
> Regards
> Hassan Iqbal

gdigrab is not very optimized. 

Your hardware might not be fast enough to capture desktop at 60fps,
resulting in dropped frames, and thus wrong times. Look at the console
output for the fps for a rough idea of the processing speed on your system

Sent from: http://ffmpeg-users.933282.n4.nabble.com/

More information about the ffmpeg-user mailing list