Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-13T11:25:35.960Z
Answers.LastActivityDate: 2017-10-13T12:55:36.823Z
Answers.LastEditDate: 2017-10-13T12:55:36.823Z
Answers.UserDisplayName: Константин Ван
Answers.Body: <p>Use</p>
  
  <pre><code>text='timestamp \: %{pts\:gmtime\:0\:%H\\\:%M\\\:%S}'
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-13T08:19:08.960Z
Answers.Text: 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 ***'`
Answers.UserDisplayName: Wayne Chen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-13T08:22:12.303Z
Answers.Text: I'm on Windows. You probably are using the bash shell. You can try skipping the slashes between H M and S.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-13T08:46:13.380Z
Answers.Text: 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!
Answers.UserDisplayName: Wayne Chen
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-06T18:30:53.493Z
Answers.Text: @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.
Answers.UserDisplayName: Pysis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-13T07:48:12.713Z
Answers.LastActivityDate: 2017-07-13T07:48:12.713Z
Answers.UserDisplayName: Gyan
Body: <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>
  
Tags: <ffmpeg><filter>
Title: How to set pts time format when using ffmpeg filter to add timestamp
UserDisplayName: Wayne Chen
ThreadText: # 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**: @username_0  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,
  
  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.
  
  
  ---
  
  