I am trying to add a text to a video using ffmpeg and python.
I tried to do this in the following ways, but it didn’t work.
first
(
ffmpeg
.input(in_video)
.filter('drawtext',
fontsize=30,
fontfile=r"D:projectspythoneditor_botdownloadsCandara.ttf",
text='test test test.',
x='if (eq(mod(t\, 15)\, 0)\, rand(0\, (w-text_w))\, x)',
y='if (eq(mod(t\, 10)\, 0)\, rand(0\, (h-text_h))\, y)')
.output(f'output-final.mp4')
.run()
)
second
fil = fr"drawtext=text='test test test':fontsize=30:fontfile=':projectspythoneditor_botdownloadsCandara.ttf':x='if (eq(mod(t, 15), 0), rand(0, (w-text_w)), x)':y='if (eq(mod(t, 10), 0), rand(0, (h-text_h)), y)'"
(
ffmpeg
.input(in_video)
.output(f'output-final.mkv', filter_complex=fil)
.run()
)
But by running this command
ffmpeg -i v1.mp4 -filter:v drawtext="fontsize=30:fontfile=candara.ttf:text='testtest test.':x=if(eq(mod(t,15),0),rand(0,(w-text_w)),x):y=if(eq(mod(t,10),0),rand(0,(h-text_h)),y)" -c:a copy -c:v libx264 -preset slow -crf 18 V13.mkv
In the terminal, what I want is done exactly
thanks