How to add an arbitrary, formatted timestamp to a video with FFMPEG?

14,105

This was answered in the (currently) third answer down in this question. The answer is that the deprecated strftime expansion option allows formatting, and accepts an undocumented basetime parameter (in units of microseconds since the UNIX epoch) to set the initial timecode.

Share:
14,105
Neil M.
Author by

Neil M.

Jack of many trades, master of none.

Updated on June 04, 2022

Comments

  • Neil M.
    Neil M. almost 2 years

    I am calling ffmpeg from a custom tool to concatenate video files while overlaying a timestamp in the output. The output video needs to have a timestamp starting at an arbitrary time. The format must be a 12-hour clock with seconds and meridiem, e.g. 10:34:59 AM or 6:13:09 PM. Here's the full command I'm using right now:

    ffmpeg\bin\ffmpeg.exe -y -i "concat:input.mod" -ss 00:00:00 -t 00:02:17 
    -an -vcodec libx264 -profile:v baseline -level 13 -b:v 2000k -vf 
     "drawtext=fontcolor=white:fontsize=16:fontfile="/Windows/Fonts/arial.ttf":
    box=1:[email protected]:x=(w-text_w-10):y=(h-text_h-5):
    timecode='02\:36\:17\;00':rate=30000/1001" output.mp4
    

    This outputs a 2 minute, 17 second duration video beginning at the start of the input file. The output video has a timecode in the bottom-right corner beginning at the time 02:36:17 and ending at 02:38:34. What I want is exactly this, but instead of printing "02:36:17;00" on frame 0 and counting up from there, it should print "2:36:17 AM" on frame 0 and count up from there.

    I have tried using the localtime function to output formatted time, but the time value it uses is the time that the drawtext filter is called. It doesn't take a parameter for an arbitrary time.

    I have also looked at the pts function, which seems to allow an arbitrary offset but only supports two formatting options, neither of which is the clock format I need.

    What is the proper way to add a timestamp with an arbitrary starting time and format using ffmpeg?