I need to draw a box that grows in size horizontally over a video (scaling its width as time goes by)

Since drawbox does not support the 't' (as in time) variable, I'm at a loss here. I've seen some solutions using overlay, but they are fixed width and are rather used to move the box around.

What's the workaround here?

EDIT This is where I got trying to use drawbox and scale:

ffmpeg -y -i c81e728d9d4c2f636f067f89cc14862c.mp4\
  -filter_complex "\
 [0:v][vb]overlay=x=80:y=350" a.mp4

With this I get an error of:

[Parsed_scale_1 @ 0x5596b5c61e40] Error when evaluating the expression 'if(gte(t*20,600),600,t*20)'.
Maybe the expression for out_w:'if(gte(t*20,600),600,t*20)' or for out_h:'20' is self-referencing.

Now, if I set the width to a fixed value, it runs, but then there's the problem that the overlay contains the whole video itself as it is the input of the drawbox filter. I'm not sure how to draw the box and scale it separately from the source video.

  • Use the scale filter after drawing the box. See ffmpeg.org/ffmpeg-filters.html#scale-1
    – Gyan
    May 15, 2020 at 9:40
  • Hi, thanks for the hints. I'm still unable to make it work, I'm quite a noob with ffmpeg still. I've updated my answer, it would be awesome if you could take a look at it! Thanks again
    – Ailef
    May 15, 2020 at 23:48
  • Ok, first upgrade ffmpeg to a current git version from johnvansickle.com/ffmpeg. Then use the color filter to generate a stream with the initial size that you want. Then use scale to resize it. Finally overlay.
    – Gyan
    May 16, 2020 at 6:36
  • Is it only me or, is the reference documentation for drawing in ffmpeg very well hidden out there?
    – matanox
    Mar 22, 2022 at 18:35

1 Answer 1


Thanks to @Gyan comments I've been able to come up with this solution, in case somebody else is interested:


Just note that it is important that you download a current git version of ffmpeg because, from what I understood, previous ones do not support the 't' variable in the scale filter.

  • What would it take for a mere mortal to learn the syntax involved in this drawing technique? could you possibly point me in the right direction? Is there similar syntax for circles and for anti-aliased shapes?
    – matanox
    Mar 22, 2022 at 18:36
  • 1
    Unfortunately ffmpeg syntax is quite convoluted, this question is from 1 year ago and I already forgot almost everything so can't answer your question directly. What can I say is that it requires a lot of trial and error and a lot of reading of this page here: ffmpeg.org/ffmpeg-filters.html
    – Ailef
    Mar 24, 2022 at 9:25

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.