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:
       fontcolor=yellow@0.9: box=1: boxcolor=blue@0.6" -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?



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
    Jul 13 '17 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
    Jul 13 '17 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
    Jul 13 '17 at 8:46


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, privacy policy and cookie policy

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