[FFmpeg-user] Drawtext - complex expression to show feet+frames

Moritz Barsnick barsnick at gmx.net
Tue Apr 11 23:13:53 EEST 2017


On Tue, Apr 11, 2017 at 19:36:36 +0100, Mark Burton wrote:
> New here, hope this is an appropriate question layout...

To start things off, we always prefer to see the (or an example of an)
actual ffmpeg command line and its complete, uncut console output. I'll
show you why below.

> I’ve been trying to learn more about expression evaluation and some
> of the more complex aspects of controlling drawing text.

Good job so far!

> 0+00
> 0+01
> 0+02
> 0+03
> 0+04
> 0+05
> 0+06
> 0+07
> 0+08
> 0+09
> 0+10
> 0+11
> 0+12
> 0+13
> 0+14
> 0+15
> 1+00
> 1+01
> … and so on.

Mathematically, the first part is the frame number divided by 16
(rounded down to integer), the second part the frame number modulo 16 -
is that right?

> Although a single filter expression would be much more useful in the
> long run, I figured it may be easier to break the display into 3
> drawtext filters to get started. One for the feet counter, one for
> the ‘+’ character and one for the frames counter. So far I have the
> feet working almost right, but I’m not getting anywhere with the
> third.

Actually, you can use several expressions in the "text" parameter:
   ...:text=%{eif\:.....\:d}+%{eif\:.....)\:d}

> drawtext=fontsize=80:fontcolor=white:fontfile=$fontFile:text='%{eif\:0+(t/((1/24)*16))\:d}':x=(w/2)-text_w:y=(h-text_h)/2,
> drawtext=fontsize=55:fontcolor=white:fontfile=$fontFile:text='+':x=(w/2)+5:y=(h-text_h)/2" \
[...]
> The first drawtext for the feet value is 99% accurate, but sometimes
> it does not change to the next number of the exact frame it should.

This is where the output from your ffmpeg command comes in handy. It
would/might tell us the actual framerate. My guess is it's 23.976, or
more precisely 24000/1001, and not 24. That would explain the slight
offset.

> Is there a way to use a per frame value instead of ’t’?

You did obviously read the documentation. :-) You seem to have missed
the expression variable "n, frame_num" though.

> Any advice on where to begin with the frames counter. It needs to
> start at 0, count on every frame to 15 and then restart at 0 on the
> next frame.

The frame counter is 'n', it starts at zero, as documented. The rest is
just math, as explained above. This is called a "modulo operation". The
expression evaluation for "text" also supports the modulo operation:
mod(n,16).

To achieve what you desire, I used:
$ ffmpeg .... -vf "drawtext=fontsize=80:fontcolor=white:text='%{eif\:n/16\:d}+%{eif\:mod(n,16)\:d}'" [...]

> Lastly (perhaps I’m dreaming here!) could this theoretically all be
> combined into a single expression with ability to set the starting
> counter to 12+06 for example and have it count accurately from there?
> Had to ask!

Stop dreaming:
"12+6" is 198 (12*16+6) higher, just add that to 'n':
$ ffmpeg .... -vf "drawtext=fontsize=80:fontcolor=white:text='%{eif\:(n+198)/16\:d}+%{eif\:mod((n+198),16)\:d}" [...]

I haven't figured out how to format "12+6" as "12+06" though. Good luck
trying! :) (I know how to fake it, but there may be a proper way with
formatting expressions.)

Cheers,
Moritz


More information about the ffmpeg-user mailing list