Peder Wessel
Peder Wessel

Reputation: 656

FFMPEG: Create timestamp based on actual creation time

Desired outcome

Add overlay with timestamp for each frame of a video based on the original creation time for the video. E.g. starting at 2022-03-26T15:51:49.000000Z and a second later in the video present 2022-03-26T15:51.50.000000Z

Approach

Creation_time stored in the file already, e.g. when running ffmpeg -i input.mov" it presents creation_time : 2022-03-26T15:51:49.000000Z.

Adding overlay with timestamp to video: ffmpeg -i input.mov -filter_complex "drawtext=text='%{pts\:gmtime\:1507046400\:%d-%m-%Y %T}': x=100 : y=100: box=1" -c:a copy output.mp4

Challenge/ help needed

Need to replace the gmtime\:1507046400 with the actual creation_time. How does one do it?

Sources

Upvotes: 2

Views: 3955

Answers (1)

Rolf of Saxony
Rolf of Saxony

Reputation: 22433

The link I suggested is for a fixed datetime.
For a rolling time use a time offset.
If I pick an arbitary date and time as 2022/2/28 at 12:02:03, calculate the number of seconds for the offset, in this instance 12 x 60 x 60 plus 2 x 60 plus 3 equals 43323.
We fix the date as text, then use the offset for the time.

ffmpeg -i some.mp4 -filter_complex  "[0:v]drawtext=text='2022 02 28 %{pts\:hms\:43323}':x=(w-text_w)/2:y=10:font='Noto mono':fontsize=40:alpha=0.5:box=1:boxborderw=4 [vid]" -map [vid] -map 0:a -f matroska - | ffplay -autoexit -i -

enter image description here

For a video running past midnight, you'll need a variation on that theme.

ffmpeg -i some.mp4 -filter_complex  "[0:v]drawtext=text='%{pts\:gmtime\:1646092780}':x=(w-text_w)/2:y=10:font='Noto mono':fontsize=40:alpha=0.5:box=1:boxborderw=4 [vid]" -map [vid] -map 0:a -f matroska - | ffplay -autoexit -i -

Here the offset is calculated as elapsed seconds since the Unix epoch time (01/01/1970 00:00:00)

enter image description here enter image description here

Upvotes: 2

Related Questions