I want to add timestamp of current played time to a video, so I use this:

ffmpeg -i video.mkv -filter_complex "drawtext=fontfile=/Library/Fonts/Arial.ttf: 
       text='timestamp: %{pts \: hms}': x=5: y=5: fontsize=16:
       [email protected]: box=1: [email protected]" -c:a copy -c:v libx264 -map 0 output.mkv

This comes out that the timestamp was in hh:mm:ss:mm format, but I want it in hh:mm:ss format. So how can I achieve this goal?

2 Answers 2



text='timestamp \: %{pts\:gmtime\:0\:%H\\\:%M\\\:%S}'
  • It went wrong: [Parsed_drawtext_0 @ 0x7fe6e840fd40] Could not load font "%M\": cannot open resource and [AVFilterGraph @ 0x7fe6e8708020] Error initializing filter 'drawtext' with args 'fontfile ***'
    – Wayne Chen
    Commented Jul 13, 2017 at 8:19
  • I'm on Windows. You probably are using the bash shell. You can try skipping the slashes between H M and S.
    – Gyan
    Commented Jul 13, 2017 at 8:22
  • 1
    Yeah, you are right! On macOS use this: text='timestamp \: %{pts\:gmtime\:0\:%H %M %S}', It seems that \: between H M and S is not allowed. So the ":" has not escaped. I'm wondering how to escape ":". Thanks a lot!
    – Wayne Chen
    Commented Jul 13, 2017 at 8:46
  • @WayneChen Fedora Linux fish I used "...:text=%{pts\\\:hms}" as an example for escaping parameters. I already had to escape single quote character using this: set fileE (echo "$file" | sed 's|\'|\\\\\\\\\\\\\\\'|'), so I would say keep adding slashes carefully until it works interpreted as a literal and not a filter or function parameter/argument separator.
    – Pysis
    Commented Oct 6, 2022 at 18:30


In order to draw Timestamp: 01:25., you should specify this one to (feed) ffmpeg:

drawtext = text = 'Timestamp\: %{pts\:gmtime\:0\:%M\\\:%S}.'


If you specify this one to (feed) ffmpeg:

drawtext = text = '%{pts\:gmtime\:0\:%M\\:%S}'

, it gives Unterminated %{} near '{pts:gmtime:0:%M\' error.

But in bash

But if you're using bash-like shell and a weak quote, "......", to feed it,

  1. \\ is escaped to \, and

  2. \: is not escaped but remains without any changes because \: is not an escape sequence.

So it should be:

-filter_complex "drawtext = text = '%{pts\:gmtime\:0\:%M\\\\\:%S}'"

i.e. bash's "\\\\\:" for ffmpeg's \\\: for getting a single character : displayed.

Note that

If you only want to apply one or more filters to one video stream (e.g, drawtext), you can use -vf instead of using --filter_complex. The latter is reserved for applying filters on multiple streams.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.