<p>A colleague just pointed this out to me</p>
<pre><code>-vf &quot;drawtext=text='%{metadata\:timecode}':box=1:boxcolor=black:fontcolor=white:fontsize=48:x=100:y=100&quot;
</code></pre>
<p>Works with both timecode in SEI &amp; MXF timecode track
NB: Doesn't work with ffmpeg 4</p>

CC BY-SA 4.0
2023-02-14T10:00:17.353Z
2023-02-14T10:00:17.353Z
user40592
<p>I have a timelapse video from a GoPro and want to overlay the time of the recording on the current frame. For instance, a frame taken at 9am might show <code>09:00</code>.</p>
<p>It seems like <a href="https://ffmpeg.org/ffmpeg-filters.html#drawtext-1" rel="nofollow noreferrer">the <code>drawtext</code> filter</a> is the way to go. I'm struggling to figure out the right invocation to grab the right time and make that work.</p>
<p>ffprobe shows that there's a <code>timecode</code> attached to each individual stream, but not the input's overall metadata:</p>
<pre><code>Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GX010246.MP4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2022-11-01T23:24:04.000000Z
    firmware        : H22.01.01.12.00
  Duration: 00:00:00.23, start: 0.000000, bitrate: 106869 kb/s
  Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 5312x2988 [SAR 1:1 DAR 16:9], 105367 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
    Metadata:
      creation_time   : 2022-11-01T23:24:04.000000Z
      handler_name    : GoPro H.265
      vendor_id       : [0][0][0][0]
      encoder         : GoPro H.265 encoder
      timecode        : 09:23:30:08
  Stream #0:1[0x2](eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
    Metadata:
      creation_time   : 2022-11-01T23:24:04.000000Z
      handler_name    : GoPro TCD
      timecode        : 09:23:30:08
  Stream #0:2[0x3](eng): Data: bin_data (gpmd / 0x646D7067), 408 kb/s (default)
    Metadata:
      creation_time   : 2022-11-01T23:24:04.000000Z
      handler_name    : GoPro MET
</code></pre>
<p>To make it even harder, this timecode is the <em>end</em> of the recording - when it was saved - so the timestamp on each frame has to be <code>((timecode from metadata) - (clip duration) + (time since start))</code>.</p>
<h2>Some attempts</h2>
<p>This is a start, which overlays the local time when ffmpeg was run:</p>
<pre class="lang-sh prettyprint-override"><code>ffmpeg -i in.mp4 -vf &quot;drawtext=text='%{localtime\:%T}': fontcolor=white@0.8: x=7: y=460: fontsize=96&quot; out.mp4
</code></pre>
<p>This can't find <code>timecode</code>, maybe because it's not defined:</p>
<pre class="lang-sh prettyprint-override"><code>ffmpeg -i in.mp4 -vf &quot;drawtext=text='%{timecode\:%T}': fontcolor=white@0.8: x=7: y=460: fontsize=96&quot; out.mp4
</code></pre>
<p>This tries to reference <code>metadata:s:v:0:timecode</code>, but the reference is invalid somehow, even with <a href="https://stackoverflow.com/a/10729560">the right amount of escaping</a>:</p>
<pre class="lang-sh prettyprint-override"><code>ffmpeg -i in.mp4 -vf &quot;drawtext=text='%{metadata\\\\\\:s\\\\\\:v\\\\\\:0\\\\\\:timecode}': r=29.97 : fontcolor=white@0.8:fontsize=96&quot; out.mp4
</code></pre>
<p>The <a href="https://ffmpeg.org/ffmpeg-filters.html#Text-expansion" rel="nofollow noreferrer">pts</a> function could work, but I can't figure out how to invoke it or pass it the start time </p>
<p>There's also <code>drawtext=timecode=&lt;start timecode&gt;</code>, which seems promising:</p>
<pre class="lang-sh prettyprint-override"><code>ffmpeg -i in.mp4 -vf &quot;drawtext=timecode='00\:00\:00\:00': r=29.97 : fontcolor=white@0.8: x=7: y=460: fontsize=96&quot; out.mp4
</code></pre>
<p>but I also haven't figured out how to put this dynamic data into it:</p>
<pre class="lang-sh prettyprint-override"><code>ffmpeg -i in.mp4 -vf &quot;drawtext=timecode='%{s:v:0:timecode}': r=29.97 : fontcolor=white@0.8: x=7: y=460: fontsize=96&quot; out.mp4
# fails
</code></pre>
<p>Would really appreciate some help with this tricky problem!</p>

<ffmpeg><timecode>
ffmpeg: How to burn in the timecode from a stream's metadata
David Lord
# ffmpeg: How to burn in the timecode from a stream's metadata

(Asked by: username_0 on 2022-11-11)

I have a timelapse video from a GoPro and want to overlay the time of the recording on the current frame. For instance, a frame taken at 9am might show 09:00.
It seems like the drawtext filter is the way to go. I'm struggling to figure out the right invocation to grab the right time and make that work.
ffprobe shows that there's a timecode attached to each individual stream, but not the input's overall metadata:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GX010246.MP4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2022-11-01T23:24:04.000000Z
    firmware        : H22.01.01.12.00
  Duration: 00:00:00.23, start: 0.000000, bitrate: 106869 kb/s
  Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 5312x2988 [SAR 1:1 DAR 16:9], 105367 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
    Metadata:
      creation_time   : 2022-11-01T23:24:04.000000Z
      handler_name    : GoPro H.265
      vendor_id       : [0][0][0][0]
      encoder         : GoPro H.265 encoder
      timecode        : 09:23:30:08
  Stream #0:1[0x2](eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
    Metadata:
      creation_time   : 2022-11-01T23:24:04.000000Z
      handler_name    : GoPro TCD
      timecode        : 09:23:30:08
  Stream #0:2[0x3](eng): Data: bin_data (gpmd / 0x646D7067), 408 kb/s (default)
    Metadata:
      creation_time   : 2022-11-01T23:24:04.000000Z
      handler_name    : GoPro MET

To make it even harder, this timecode is the end of the recording - when it was saved - so the timestamp on each frame has to be ((timecode from metadata) - (clip duration) + (time since start)).
Some attempts
This is a start, which overlays the local time when ffmpeg was run:
ffmpeg -i in.mp4 -vf "drawtext=text='%{localtime\:%T}': fontcolor=white@0.8: x=7: y=460: fontsize=96" out.mp4

This can't find timecode, maybe because it's not defined:
ffmpeg -i in.mp4 -vf "drawtext=text='%{timecode\:%T}': fontcolor=white@0.8: x=7: y=460: fontsize=96" out.mp4

This tries to reference metadata:s:v:0:timecode, but the reference is invalid somehow, even with the right amount of escaping:
ffmpeg -i in.mp4 -vf "drawtext=text='%{metadata\\\\\\:s\\\\\\:v\\\\\\:0\\\\\\:timecode}': r=29.97 : fontcolor=white@0.8:fontsize=96" out.mp4

The pts function could work, but I can't figure out how to invoke it or pass it the start time 
There's also drawtext=timecode=, which seems promising:
ffmpeg -i in.mp4 -vf "drawtext=timecode='00\:00\:00\:00': r=29.97 : fontcolor=white@0.8: x=7: y=460: fontsize=96" out.mp4

but I also haven't figured out how to put this dynamic data into it:
ffmpeg -i in.mp4 -vf "drawtext=timecode='%{s:v:0:timecode}': r=29.97 : fontcolor=white@0.8: x=7: y=460: fontsize=96" out.mp4
# fails

Would really appreciate some help with this tricky problem!

**Tags:** ffmpeg, timecode


---

## 1 answers

### Answer by username_1 on 2023-02-14. Score: 1

A colleague just pointed this out to me
-vf "drawtext=text='%{metadata\:timecode}':box=1:boxcolor=black:fontcolor=white:fontsize=48:x=100:y=100"

Works with both timecode in SEI & MXF timecode track
NB: Doesn't work with ffmpeg 4


---

