ffmpegtimelapse

ffmpeg encode timestamp on a timelapse video


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.


Solution

  • 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.