0

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}': [email protected]: 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}': [email protected]: 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 : [email protected]: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=<start timecode>, which seems promising:

ffmpeg -i in.mp4 -vf "drawtext=timecode='00\:00\:00\:00': r=29.97 : [email protected]: 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 : [email protected]: x=7: y=460: fontsize=96" out.mp4
# fails

Would really appreciate some help with this tricky problem!

1 Answer 1

0

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

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.