旋转滤镜中的输出宽度和高度初始化为输入的W/H,而不是自动计算以显示旋转后的整个图像。请改用以下方法:
ffmpeg -y -i in.png -i test_sq.png \
-filter_complex "[1]scale=279:279,setsar=1,rotate=PI/6:c=none:ow=rotw(PI/6):oh=roth(PI/6)[s]
[0][s]overlay=423-w*sin(PI/6)/(sin(PI/6)+cos(PI/6)):259,scale=hd720[out]" \
-map "[out]"-pix_fmt bgra out.png
对于非正方形的图片,
ffmpeg -y -i in.png -i test_sq.png \
-filter_complex "[1]scale=279:279,setsar=1,rotate=PI/6:c=none:ow=rotw(PI/6):oh=roth(PI/6)[s]
[0][s]overlay=423-ih*sin(PI/6):259,scale=hd720[out]" \
-map "[out]"-pix_fmt bgra out.png
对于非正方形的图像,且旋转角度为负数:
您将需要手动提供原始图像的高度值 ih
。
ffmpeg -y -i in.png -i test_sq.png \
-filter_complex "[1]scale=279:279,setsar=1,rotate=-PI/6:c=none:ow=rotw(-PI/6):oh=roth(-PI/6)[s]
[0][s]overlay=423:259-iw*sin(PI/6),scale=hd720[out]" \
-map "[out]"-pix_fmt bgra out.png
您需要手动提供原始图像的宽度(iw
)。
对于没有内置alpha通道的图片,在rotate
滤镜之前插入format=bgra
。