ffmpeg encode timestamp on a timelapse video

898 views Asked by At

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.

2

There are 2 answers

0
Gyan On BEST ANSWER

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.

0
Julian Daniel On

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