<h2>Do</h2>

<p>In order to draw <code>Timestamp: 01:25.</code>, you should specify this one to (feed) <code>ffmpeg</code>:</p>

<pre><code>drawtext = text = 'Timestamp\: %{pts\:gmtime\:0\:%M\\\:%S}.'
</code></pre>

<h2>Don't</h2>

<p>If you specify this one to (feed) <code>ffmpeg</code>:</p>

<pre><code>drawtext = text = '%{pts\:gmtime\:0\:%M\\:%S}'
</code></pre>

<p>, it gives <code>Unterminated %{} near '{pts:gmtime:0:%M\'</code> error.</p>

<h2>But in <code>bash</code></h2>

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

<ol>
<li><p><code>\\</code> is escaped to <code>\</code>, and</p></li>
<li><p><code>\:</code> is not escaped but remains without any changes because <code>\:</code> is not an escape sequence.</p></li>
</ol>

<p>So it should be:</p>

<pre><code>-filter_complex "drawtext = text = '%{pts\:gmtime\:0\:%M\\\\\:%S}'"
</code></pre>

<p>i.e. <code>bash</code>'s <code>"\\\\\:"</code> for <code>ffmpeg</code>'s <code>\\\:</code> for getting a single character <code>:</code> displayed.</p>

<h2>Note that</h2>

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

CC BY-SA 3.0
2017-10-13T11:25:35.960Z
2017-10-13T12:55:36.823Z
2017-10-13T12:55:36.823Z
Константин Ван
<p>Use</p>

<pre><code>text='timestamp \: %{pts\:gmtime\:0\:%H\\\:%M\\\:%S}'
</code></pre>

CC BY-SA 3.0
2017-07-13T08:19:08.960Z
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
CC BY-SA 3.0
2017-07-13T08:22:12.303Z
I'm on Windows. You probably are using the bash shell. You can try skipping the slashes between H M and S.
Gyan
CC BY-SA 3.0
2017-07-13T08:46:13.380Z
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
CC BY-SA 4.0
2022-10-06T18:30:53.493Z
@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
CC BY-SA 3.0
2017-07-13T07:48:12.713Z
2017-07-13T07:48:12.713Z
Gyan
<p>I want to add timestamp of current played time to a video, so I use this:</p>

<pre><code>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
</code></pre>

<p>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?</p>

<ffmpeg><filter>
How to set pts time format when using ffmpeg filter to add timestamp
Wayne Chen
# How to set pts time format when using ffmpeg filter to add timestamp

(Asked by: username_0 on 2017-07-13)

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?

**Tags:** ffmpeg, filter


---

## 2 answers

### Answer by username_2 on 2017-07-13. Score: 3 | Accepted answer

Use
text='timestamp \: %{pts\:gmtime\:0\:%H\\\:%M\\\:%S}'

> **Comments:**
> **username_0**: 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 ***'`  
> **username_2**: I'm on Windows. You probably are using the bash shell. You can try skipping the slashes between H M and S.  
> **username_0**: 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!  
> **username_3**: @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.  

---

### Answer by username_1 on 2017-10-13. Score: 6

Do
In order to draw Timestamp: 01:25., you should specify this one to (feed) ffmpeg:
drawtext = text = 'Timestamp\: %{pts\:gmtime\:0\:%M\\\:%S}.'

Don't
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,

\\ is escaped to \, and
\: 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.


---

