How to Use strftime with FFmpeg drawtext

This guide explains how to use the strftime option within FFmpeg’s drawtext video filter to overlay dynamically formatted date and time stamps onto a video. You will learn the correct syntax, how to handle necessary character escaping, and see practical command-line examples for common timestamp formats.

Understanding the strftime Option

The drawtext filter in FFmpeg allows you to render text onto video frames. By enabling the strftime=1 option, FFmpeg treats the text parameter as a standard strftime format string, allowing you to print the current system date and time directly onto your footage.

Basic Syntax and Character Escaping

Because FFmpeg uses colons (:) to separate filter options, any colon used within your time format string (such as %H:%M:%S) must be escaped with a backslash (\:).

Here is the minimal syntax for overlaying the current date and time:

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

Breakdown of Parameters

  • text='%Y-%m-%d %H\:%M\:%S': The time template. Standard strftime tokens are expanded to current time values. Notice the escaped colons (\:) between hours, minutes, and seconds.
  • strftime=1: Tells FFmpeg to parse the text string using the C library's strftime function.
  • x=10:y=10: Sets the horizontal and vertical pixel coordinates where the text appears (top-left corner in this case).
  • fontcolor=white: Sets the text color.
  • fontsize=24: Sets the size of the rendered text in pixels.
  • fontfile=/path/to/font.ttf: (Optional) Specifies a custom TrueType font file. If omitted, FFmpeg uses a fallback system font.

Adding a Background Box for Readability

To make the timestamp legible over bright or fluctuating backgrounds, enable a semi-transparent background box:

ffmpeg -i input.mp4 -vf "drawtext=text='%Y-%m-%d %H\:%M\:%S':strftime=1:x=20:y=20:fontsize=28:fontcolor=white:box=1:boxcolor=black@0.5:boxborderw=5" -c:a copy output.mp4
  • box=1: Enables the bounding box.
  • boxcolor=black@0.5: Creates a black box with 50% opacity.
  • boxborderw=5: Adds 5 pixels of padding around the text.

Common strftime Specifiers

You can customize the output using standard format specifiers:

  • %Y: 4-digit year (e.g., 2026)
  • %m: 2-digit month (01–12)
  • %d: 2-digit day of the month (01–31)
  • %H: Hour in 24-hour format (00–23)
  • %I: Hour in 12-hour format (01–12)
  • %M: Minute (00–59)
  • %S: Second (00–59)
  • %p: AM or PM designation
  • %B: Full month name (e.g., January)
  • %A: Full weekday name (e.g., Monday)

Real-Time Live Streaming Example

When ingesting a live camera feed (such as via RTSP), the strftime filter prints the actual wall-clock time the frame is processed:

ffmpeg -rtsp_transport tcp -i rtsp://camera.local/stream -vf "drawtext=text='%A, %B %d, %Y - %I\:%M\:%S %p':strftime=1:x=w-tw-20:y=h-th-20:fontsize=20:fontcolor=yellow" -c:v libx264 -preset veryfast -c:a copy output.mp4

In this example, x=w-tw-20:y=h-th-20 automatically positions the timestamp in the bottom-right corner of the video frame with a 20-pixel margin.