Aug 19

How to do a timecode overlay with ffmpeg

Category: Linux,multimedia   — Published by goeszen on August 19, 2013 at 5:35 pm

In case you wonder if it is possible to bake a visual timecode reading into a video... it is possible! And depending on your version/build of ffmpeg (or avconv, respectively) it is dead simple.

In case you are unfamiliar with the video-filter (-vf) switch of ffmpeg (docs here), go over to this page to see some examples of how to, for example, embed the current time and date into the video portion of a video file. That will get you started on understanding how a text-overlay works.

With -vf you can overlay all sorts of text onto the video. Normally, more recent versions of ffmpeg/ avconv can even substitute dynamic variables with metadata from the video itself, that's called expansion and is explained here in the docs.

This way, you can, for example, have the current frame count baked into the video, at a position you specify. And timecode is just that. As text, you would then enter "%{n}" and %{n} will be replaced with the current n=number of frames during transcode/video-filtering and overlaid onto the video.

In case your version of ffmpeg doesn't understand the expand syntax properly (like minde), here is a witty script that compiles an insanely long CLI command for you but forces ffmpeg to properly do what you'd expect - until the clean expand works for us all.

But in case you've got a version of ffmpeg that does understand expand, it surely also understands the "timecode" switch or "key" (if you get "Key 'timecode' not found", you don't have it), and that's exactly what you're looking for: use a command like

-vf drawtext="fontsize=15:fontfile=/Library/Fonts/DroidSansMono.ttf:\

P.S. Ah, and forget about the stone-age solution suggested here to burn timecode into a video... Arg. Although it's an interesting approach to use a subtitles file containing timecode.

3 Responses to “How to do a timecode overlay with ffmpeg”

  1. Nick L. EMT-P says:

    Can you search the text and jump to the video using this method? For example, search all video where tempature is 68 degrees? Or more useful, jump to video where clerk did a void on a POS that outputs text?

  2. Katz says:

    Can you help me with a way to burn in timecode from the original ? i'm trying to figure it out by myself but i cant. Thanks in advance.

  3. goes says:

    Well, you probably mean displaying the original timecode of the video, the tc that's already embedded into the video-stream, right? Mh, can't help you with that as I haven't dug that deeply into it and had no need for such an application so far. But my take would be to extract the actual timecode start value/offset, and then start the counter of the overlay from there. This way, the display wouldn't be linked to the internal tc really, but the display and internal tc would run in sync, at least. But you have to figure that out on yourself, sorry.

Leave a Reply