1

I have a video that is a timelapse (generated by a GoPro, if that matters) with images every 5 seconds. I want to encode a timestamp onto it. Previously I've used a command like this one to get a timestamp burned in

# Convert the date to EPOCH. This will be used to set the time for the draw text
# method.
EPOCH=$(date --date="${STARTDATE}" +%s)

# we assume that the STARTDATE is in UTC 0000, Zulu time, GMT and that we want
# to convert it to the local time on the computer.
ffmpeg -i "${INPUT}" -vf drawtext="fontsize=30:fontcolor=yellow:text='%{pts\:localtime\:${EPOCH}}':x=(w-text_w) - 10:y=(h-text_h) - 10" -vcodec libx265 -crf 28 "${OUTPUT}"

The issue is that the timestamps generated by this progress as if it is a normal video, stamping a 30 minute timelapse as if it were 25 seconds. What I want are timestamps that match the timelapse.

I've looked at the drawtext docs. I thought rate might be the key, but 1/5 and 150 both produce errors like this one:

Parsed_drawtext_0 @ 0x10c607370] Failed to parse expression: (h-text_h) - 10 r=1/5 

I figure I might need to multiply the current frame value to get the correct time, but I don't know how to do that.

Kyeotic
  • 19,697
  • 10
  • 71
  • 128
  • Multiply the timestamps before, and restore them after. `setpts=PTS*10,drawtext,setpts=PTS/10` where 10 is the ratio of `actual interval/interval in video` – Gyan Nov 02 '22 at 15:59
  • @Gyan Sorry, I'm confused on where that goes in the command. I tried putting that around the drawtext flag and got `Failed to configure input pad on Parsed_drawtext_1`. – Kyeotic Nov 02 '22 at 16:28
  • Before and after the drawtext filter in your existing command. – Gyan Nov 02 '22 at 18:42
  • @Gyan OK, I got that working, using an interval of `setpts=PTS*150,drawtext,setpts=PTS/150` since its 30fps with a 5s interval, `30*5=150`. I think this all looks good, if you put that up as an answer I will accept it. – Kyeotic Nov 02 '22 at 19:26

2 Answers2

0

The pts function will just use the stored timestamp. You will have to modify the timestamp before the drawtext filter and restore the original value afterwards i.e.

setpts=PTS*10,drawtext=...,setpts=PTS/10

where the factor 10 is the ratio of realtime between frames and their display interval in the timelapse video.

Gyan
  • 85,394
  • 9
  • 169
  • 201
0

Our Junior School has a Raspberry Pi capturing frames every 10 minutes in the hydroponics lab.

I use the following command to pull the image file creation time from the metadata of each photo and burn that in the top left corner of my timelapse - assuming your clock is correct, that should do the trick!

ffmpeg -y -r 24 -export_path_metadata 1 -pattern_type glob -i './*-00Z.jpg' -vf "drawtext=fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf:x=20:y=20:fontsize=40:fontcolor=yellow:text='%{metadata\:DateTime\:def_value}'" -c:v libx264 video-file.mp4

The resulting video looks something like this: Sample frame from student hydroponics lab timelapse, showing timestamp in top left corner