How to Print Unix Epoch Timestamp on Video with FFmpeg
This article explains how to overlay a running Unix epoch timestamp
onto each frame of a video using FFmpeg. You will learn how to burn
either the real-time system clock (wallclock time) or a calculated epoch
timestamp relative to the video’s start time directly into the video
track using the drawtext video filter.
Method 1: Print Real-Time System Epoch (Wallclock Time)
If you are capturing a live stream or want to print the exact time
the video is being processed by your system, you can use the
localtime or gmtime functions inside the
drawtext filter.
Use the following command to burn the current Unix epoch timestamp (in seconds) onto the video:
ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:text='%{localtime\:%s}':x=10:y=10:fontsize=24:fontcolor=white:box=1:boxcolor=black@0.5" -codec:a copy output.mp4How it works:
drawtext: The filter used to overlay text on the video.fontfile: The path to a TrueType (.ttf) or OpenType (.otf) font on your system (e.g.,/usr/share/fonts/truetype/dejavu/DejaVuSans.ttfon Linux orC\\:/Windows/Fonts/arial.ttfon Windows).text='%{localtime\:%s}': This fetches the local system time and formats it using%s, which is the standard strftime format for the Unix epoch (seconds since January 1, 1970).x=10:y=10: Positions the text 10 pixels from the top-left corner.fontcolor=white:box=1:boxcolor=black@0.5: Sets the text color to white and places a semi-transparent black background box behind it for readability.
Method 2: Print Relative Epoch (Starting from a Specific Date/Time)
If you are processing a pre-recorded video and want the timestamp to
start from a specific Unix epoch representing when the video was
recorded, you should use mathematical evaluation based on the video’s
timestamp (t).
Use this command to define a custom starting epoch:
ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:text='%{eif\:1700000000+t\:d}':x=10:y=10:fontsize=24:fontcolor=white:box=1:boxcolor=black@0.5" -codec:a copy output.mp4How it works:
1700000000: Replace this number with your desired starting Unix epoch timestamp.+t: Adds the current relative time of the video frame (in seconds) to your starting epoch.eif\:...\:d: Evaluates the expression as an integer (dformat) to prevent decimal places from showing on the screen.
Adding Milliseconds to the Epoch Timestamp
If you need high-precision timestamps that include milliseconds, you can combine the relative time calculation with decimal formatting:
ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:text='%{eif\:1700000000+t\:d}.%{eif\:(t-floor(t))*1000\:d\:3}':x=10:y=10:fontsize=24:fontcolor=white:box=1:boxcolor=black@0.5" -codec:a copy output.mp4How it works:
%{eif\:1700000000+t\:d}: Prints the integer epoch seconds..: Prints a literal decimal point.%{eif\:(t-floor(t))*1000\:d\:3}: Extracts the fractional part of the current video time, multiplies it by 1000 to convert to milliseconds, and formats it as a 3-digit padded integer.