Add Real-Time Timestamp to Video Using FFmpeg
This guide demonstrates how to overlay the current date and time onto a video stream in real-time using the powerful command-line tool, FFmpeg. You will learn the exact command-line syntax, how to format the dynamic timestamp, and how to customize its appearance on your video output.
To burn a real-time timestamp onto a video, you must use FFmpeg’s
drawtext video filter. This filter allows you to render
text dynamically using system fonts and time-expansion variables.
The Basic Command
Here is the standard command to overlay the current local date and time onto a video file:
ffmpeg -i input.mp4 -vf "drawtext=fontfile='/path/to/font.ttf':text='%{localtime\:%Y-%m-%d %H\\\\\:%M\\\\\:%S}':x=10:y=10:fontsize=24:fontcolor=white:box=1:boxcolor=black@0.5" -c:v libx264 -c:a copy output.mp4Parameter Breakdown
-vf "drawtext=...": This flags the use of the video filter graph and calls thedrawtextfilter.fontfile='/path/to/font.ttf': Specifies the path to a TrueType font (TTF) on your system.- Windows example:
fontfile='C\:/Windows/Fonts/arial.ttf' - Linux example:
fontfile='/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf' - macOS example:
fontfile='/Library/Fonts/Arial.ttf'
- Windows example:
text='%{localtime\:%Y-%m-%d %H\\\\\:%M\\\\\:%S}': This generates the real-time timestamp.%Y-%m-%drepresents Year-Month-Day.%H\\\\\:%M\\\\\:%Srepresents Hours:Minutes:Seconds. The extra backslashes are required to escape the colons so FFmpeg does not confuse them with filter parameter separators.
x=10:y=10: Sets the coordinates where the text will be placed (10 pixels from the top-left corner).fontsize=24: Sets the text size.fontcolor=white: Sets the text color.box=1:boxcolor=black@0.5: Draws a semi-transparent black background box (50% opacity) behind the text to ensure it remains readable on light backgrounds.
Applying to Live Streams
If you are capturing a live camera stream or RTSP feed and want to burn the real-time clock onto the output stream, apply the filter in the same way during the transcoding step:
ffmpeg -rtsp_transport tcp -i rtsp://your_stream_url -vf "drawtext=fontfile='/path/to/font.ttf':text='%{localtime\:%Y-%m-%d %H\\\\\:%M\\\\\:%S}':x=w-tw-10:y=10:fontsize=20:fontcolor=yellow:box=1:boxcolor=black@0.4" -c:v libx264 -preset ultrafast -f flv rtmp://destination_urlNote: In this live-streaming example, x=w-tw-10
automatically positions the timestamp in the top-right corner (video
width minus text width minus a 10-pixel margin).