How to Use strftime in FFmpeg drawtext Filter

This guide explains how to use the strftime option within FFmpeg’s drawtext filter to overlay dynamic dates and times onto your videos. You will learn how to enable the option, construct the time format using standard helper codes, handle character escaping, and apply these settings in practical command-line examples.

Enabling the strftime Option

By default, the drawtext filter treats the text parameter as a literal string. To display the current system date and time, you must enable the strftime option by setting it to 1. This instructs FFmpeg to parse the text string using the standard C strftime() function.

The basic syntax is:

drawtext=text='[format_codes]':strftime=1

Common strftime Format Codes

You can customize how the date and time appear using standard format codes:

Escaping Colons in FFmpeg

FFmpeg uses the colon (:) to separate different arguments within a filter. Because time formats typically use colons (e.g., HH:MM:SS), you must escape them using a backslash (\:) so FFmpeg does not mistake them for filter separators.

Depending on your operating system terminal, you may need to use a single backslash \: or a double backslash \\:.

Practical Command Examples

Example 1: Standard Date and Time Overlay

To overlay the current date and time in YYYY-MM-DD HH:MM:SS format in the top-left corner of your video, use the following command:

ffmpeg -i input.mp4 -vf "drawtext=text='%Y-%m-%d %H\:%M\:%S':strftime=1:fontcolor=white:fontsize=24:x=10:y=10" -codec:a copy output.mp4

Example 2: Time-Only Overlay with Custom Styling

If you only want to display the time (e.g., 14:30:15) in a larger font at the bottom-right of the video, use this command:

ffmpeg -i input.mp4 -vf "drawtext=text='%H\:%M\:%S':strftime=1:fontcolor=yellow:fontsize=48:x=w-tw-10:y=h-th-10" -codec:a copy output.mp4

Example 3: Date-Only Overlay with a Background Box

To make the date easier to read, you can add a semi-transparent background box behind the text:

ffmpeg -i input.mp4 -vf "drawtext=text='%B %d, %Y':strftime=1:fontcolor=white:fontsize=32:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=50" -codec:a copy output.mp4

In this command: * %B prints the full month name (e.g., “October”). * box=1 enables the background box. * boxcolor=black@0.5 sets the box to black with 50% opacity. * x=(w-text_w)/2 centers the text horizontally.