<div dir="ltr">Hello,<div><br></div><div>Hope all is well. Please bear with me on this. I hope this is the right place for these questions.</div><div><br></div><div>I want to record the video of a live stream on a desktop using FFmpeg on Windows 10 PC (Specs: Intel i7-4790 CPU @ 3.60GHz, RAM: 16GB, HDD 1TB 7200 RPM). </div><div>I also want to capture the timestamp when each frame is recorded by the FFmpeg with the highest accuracy possible.</div><div>One top of the head solution is to use <i>-vf</i> filter in FFmpeg command to append the timestamp on each frame while recording the desktop. A sample command is shown below:</div><div><br></div><div>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@1.0:x=10:y=10'" -c:v libx264rgb -crf 0 -preset ultrafast output.mkv<br><br></div><div>The -vf text inspiration is taken from the post <a href="https://stackoverflow.com/questions/47543426/ffmpeg-embed-current-time-in-milliseconds-into-video">here</a>.</div><div><br></div><div>However, there are few caveats with the above approach:</div><div>1. When I am recording at full HD resolution, the timestamps appended are not continuous on each frame. For instance, at 60 FPS, each subsequent timestamp on each frame should be 16.6 msec apart. But, what I am getting is that multiple frames have one static timestamp and then it increments by several milliseconds on the next. </div><div><i>It shows that there are accuracy issues with this approach and some processing overhead. </i></div><div><i><br></i></div><div>2. An alternate method I tried is to reduce resolution and only capture the area of interest of the screen. So, instead of 1920x1080, I capture the 640x240 area of the screen by applying offset. As a result, at least I started getting an incremental timestamp on each frame that was 14 to 18 msec apart.</div><div><i>This approach shows that by reducing the processing, things can become better. It also shows that appending timestamps on frames may have its own processing overhead. Thus, they are still not accurate enough for me.</i></div><div><br></div><div>3. The third caveat is that in the worst case, I am wondering, if a frame arrives at the monitor at t1 and FFmpeg captures it at t2, the delta between the two times t2-t1 could be 16.6 msec (in worse case). Again, I am not sure if this is the case but intuitively it makes sense and I would appreciate any insights on it. </div><div><br></div><div>So given the above issues, I am convinced that overlaying timestamp on the frame while recording will induce error in the timestamp and it will compromise accuracy. However, if someone has a solution to capture timestamps using the command only then I am eagerly looking forward to using it.</div><div><br></div><div><b>PROPOSED APPROACH:</b></div><div>I am wondering how can I modify the code of FFmpeg to capture the timestamp along with the frame number as soon as FFmpeg captures the frame rendered on the LCD and then send that timestamp~frameNo data in bulk to a file. This way:</div><div>i) I will be able to mitigate the overhead of overlaying timestamps on the frame, </div><div>ii) I will be able to record at a higher resolution, and </div><div>iii) most important, I will be able to achieve higher accuracy.  </div><div><br></div><div>The third caveat is still not addressed and I am looking forward to reducing that error by half by recording at 120 FPS while capturing timestamp from code using the proposed approach.</div><div><br></div><div>I am looking for help with the following:</div><div>a) 

How feasible is this approach?

</div><div>b) How can I achieve this, as I am new when it comes to diving into FFmpeg code? A detailed approach would be great.<br></div><div>c) Are there any better alternate solutions to get highly accurate time stamps for each frame?</div><div>d) Any insights on the third caveat would be great to have.</div><div><br></div><div>I really appreciate for reading to the end. I am looking forward to the solutions. </div><div>Thank you.</div><div><br></div><div><br></div><div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Regards<br>Hassan Iqbal<br></div></div></div></div></div>