ffmpeg: Cómo mover texto desde la parte inferior derecha al centro de la pantalla

ffmpeg: Cómo mover texto desde la parte inferior derecha al centro de la pantalla

Estoy intentando mover un texto desde la parte inferior derecha (fuera del fondo) al centro de la pantalla. El texto negro debe ir exactamente donde está el texto verde.

Esto es lo que he probado:

ffplay -f lavfi -loop 0 -i "color=color=yellow:size=800x400,drawtext=text='Test':fontsize=70:font='Arial Black':fontcolor=green:x=(W-tw)/2:y=(H-th)/2,drawtext=text='Test':fontcolor=black:fontsize=70:font='Arial Black':x=W-(t)*((W+tw)/2)/6:y=x*(H/W):enable='between(t,0,6)'"

gif

Respuesta1

Las matemáticas pueden ser un poco complicadas, pero es posible...

Supongamos que sabemos de antemano: W= 800, H= 400, tw= 170, th= 54.
Podemos precalcular los siguientes parámetros:

alpha = atan2(H, W) = atan2(400, 800)   
sin_alpha = sin(alpha) = 0.4472136 alternately: sin_alpha = H/sqrt(W*W+H*H)  
cos_alpha = cos(alpha) = 0.8944272 alternately: cos_alpha = W/sqrt(W*W+H*H)

tw = 170
th = 54

radius = sqrt((W/2+tw/2)^2 + (H/2+th/2)^2) = sqrt((400+85)^2 + (200+27)^2) = 535.5
step = radius / duration = radius / 6 = 89.249

r = radius - t*step = 535.5 - t*3.57
center_x = W/2 + r*cos_alpha
center_y = H/2 + r*sin_alpha
x = center_x - tw/2 = W/2 + r*cos_alpha - tw/2 = 400+(535.5-t*89.249)*0.8944272-85
y = center_y - th/2 = H/2 + r*sin_alpha - th/2 = 200+(535.5-t*89.249)*0.4472136-27

Comando FFplay:

ffplay -f lavfi -loop 0 -i "color=color=yellow:size=800x400,drawtext=text='Test':fontsize=70:fontfile=ariblk.ttf:fontcolor=green:x=(W-tw)/2:y=(H-th)/2,drawtext=text='Test':fontcolor=black:fontsize=70:fontfile=ariblk.ttf:x=(400+(535.5-t*89.249)*0.8944272-85):y=(200+(535.5-t*89.249)*0.4472136-27):enable='between(t,0,6)'"


Comando FFmpeg para crear test.gif:

ffmpeg -y -f lavfi -i "color=color=yellow:size=800x400:duration=6,format=rgb24,drawtext=text='Test':fontsize=70:fontfile=ariblk.ttf:fontcolor=green:x=(W-tw)/2:y=(H-th)/2,drawtext=text='Test':fontcolor=black:fontsize=70:fontfile=ariblk.ttf:x=(400+(535.5-t*89.249)*0.8944272-85):y=(200+(535.5-t*89.249)*0.4472136-27):enable='between(t,0,6)',split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" test.gif


Reemplazando todas las constantes y usando solo W, H, tw, th:

ffmpeg -y -f lavfi -i "color=color=yellow:size=800x400:duration=6,format=rgb24,drawtext=text='Test':fontsize=70:fontfile=ariblk.ttf:fontcolor=green:x=(W-tw)/2:y=(H-th)/2,drawtext=text='Test':fontcolor=black:fontsize=70:fontfile=ariblk.ttf:x=(W/2+(sqrt((W/2+tw/2)*(W/2+tw/2)+(H/2+th/2)*(H/2+th/2))-t*sqrt((W/2+tw/2)*(W/2+tw/2)+(H/2+th/2)*(H/2+th/2))/6)*W/sqrt(W*W+H*H)-tw/2):y=(H/2+(sqrt((W/2+tw/2)*(W/2+tw/2)+(H/2+th/2)*(H/2+th/2))-t*sqrt((W/2+tw/2)*(W/2+tw/2)+(H/2+th/2)*(H/2+th/2))/6)*H/sqrt(W*W+H*H)-th/2):enable='between(t,0,6)',split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" test.gif


Resultado:
ingrese la descripción de la imagen aquí

información relacionada