Adding a timestamp on frames captured using FFmpeg
15,341
Solution 1
I got it working. Just posting it here :
ffmpeg -i input -vf "drawtext=fontfile=/Windows/Fonts/Arial.ttf: text='%{localtime}': x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1: fontsize=30" -r 25 -t 5 image%03d.png
Solution 2
Another approach that get's you timestamps with millisecond granularity is
ffmpeg -i input.mp4 -vf drawtext="fontsize=60:fontcolor=yellow:text='%{e\:t*1000}':x=(w-text_w):y=(h-text_h)" output.mp4
Related videos on Youtube
Author by
coder3521
#SOreadytohelp I am an application developer. Bit new to programmers world working in .net ,C# . I also like to work in Python.
Updated on September 18, 2022Comments
-
coder3521 almost 2 years
I am trying to capture frames using FFmpeg and add current timestamp on to it.
Below code is working fine for a Linux PC :
ffmpeg -i input -vf "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text='%{localtime}': x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1" image%03d.png
But same is not working for Windows because of:
- The filter applied in the
-vf
option. fontfile=/usr/share/fonts/TTF/Vera.ttf
is not valid for Windows PC.- Some other things are also invalid.
I tried editing and removing it with some other option but nothing worked.
- I need to add time stamp on the images captured using FFmpeg in Windows.
- How could I add timestamp to it accurate to milliseconds - don't need a date in the timestamp.
What I have tried so far is:
text='%{localtime\:%X}%{pts\:hms}'
The above prints local time and the pts. I need to add both and print, so that I could get it exactly correct.
Any kind of help would be appreciated. I am cracking my head for this from last couple of hours.
-
Gyan over 8 yearsCan you post full command that you last tried with its console output? I was able to do it in Windows, with the same text expression and with a valid path to a font file.
-
coder3521 over 8 yearsYa thanks . . I figured it out . only thing i was mistaking is valid path to the font file . But now i need the timestamp correct to milliseconds . will post my working code..
- The filter applied in the