ffmpeg making flashing / blinking text

Viewed 19

I'm trying to use ffmpeg to add blinking / flashing text to a short movie file.

The code attached works for blinking text every 10th frame BUT the text only comes up for a single frame, so it's not very readable. I'd like it to hold for, say, 4 frames. I wonder if theres some kinda fancy combo using between as well as enable?

I'm semi new to this so my brain stopped when trying to come up with a solution.

ffmpeg -i input.mov -vf "drawtext=text='TEXTY':enable= (not (mod(n\,10)) )" output.gif
2 Answers

To do 4 frames on, 6 frames off, you need say ON when the mod value is <4:

0   1   2   3   4   5   6   7   8   9
ON  ON  ON  ON  OFF OFF OFF OFF OFF OFF

So your enable expression should read:

enable= lt(mod(n\,10)\,4)

Thanks @kesh for a most excellent solution which combines less than and mod. For anyone that wants to understand this and isn't mathematically inclined (like me!), here's my understanding. Please shout if you think I'm mistaken in anything.

Kesh's solution:

enable= lt(mod(n\,10)\,4)

enable tells ffmpeg when to display the text

lt returns True if the first argument is less than the second.

mod returns the remainder when you divide the frame number (by 10 in this case)

SO whenever lt returns True the text gets drawn on screen.

frame 1:  1 mod 10= 1 (which is less than 4) so lt says TRUE
frame 2:  2 mod 10= 2 (which is less than 4) so lt says TRUE
frame 3:  3 mod 10= 3 (which is less than 4) so lt says TRUE
frame 4:  4 mod 10= 4 (which is not less than 4) so lt says FALSE
frame 5:  5 mod 10= 5 (which is not less than 4) so lt says FALSE
.
.
frame 9:  9 mod 10= 9 (which is less than 4) so lt says FALSE
frame 10:  10 mod 10= 0 (which is less than 4) so lt says TRUE
frame 11:  11 mod 10= 1 (which is less than 4) so lt says TRUE
Related