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

Mark Filipak (ffmpeg) markfilipak at bog.us
Sun Mar 21 23:10:06 EET 2021


On 2021-03-21 13:31, Hassan wrote:

> @Mark: I have tried to modify the setts and setpts options. Below is the
> command:
> ffmpeg -f gdigrab -framerate 60 -offset_x 550 -offset_y 350 -video_size
> 640x480 -thread_queue_size 1024 -i desktop -vf "settb=expr=1/720000,
> setpts=N*12000,fps=60,
> 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 ./test_SD_1.mkv
> However, the seconds never increment and the milliseconds loop in three
> values 0,333,666. Have a set anything incorrect in the command?.

Let's get the basics working, eh?

I think '-framerate 60' may not be needed at all.
These: '-offset_x 550 -offset_y 350 -video_size 640x480 -thread_queue_size 1024' can probably be 
left out for now.
'drawtext' can be left out for now.
Try this:
ffmpeg -f gdigrab  -i desktop -vf "settb=expr=1/720000, setpts=N*12000, fps=60" -c:v libx264rgb 
-preset ultrafast ./test_SD_1.mkv
See if it works.


> I have another challenge. I want to record at FPs higher than 60 FPS, i.e.,
> 120 FPS. For that, i set -framerate 120 and in -vf, I set r=120. However,
> the recording that I get is just 60 FPS. Is it because my LCD has a refresh
> rate of 60hz? Or FFmpeg is not concerned about LCD hardware? How can I
> record at 120 FPS?
> 
> Another question is regarding the working of FFmpeg. Suppose, I am
> capturing a video from a desktop that is playing at 60 FPS. My frame rate
> for capturing is also set at 60 FPS. Is it likely that a frame of video
> appears on LCD and the ffmpeg captures it at a delta of almost a full
> frame, i.e., ~16. mec ? If so, then isn't recording a 60 FPS video with
> -framerate 60 an incorrect choice?
> 
> 
> 
> On Mon, Mar 15, 2021 at 10:52 PM Mark Filipak (ffmpeg) <markfilipak at bog.us>
> wrote:
> 
>> 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