需要使用 ffmpeg 的这种类型的动画

需要使用 ffmpeg 的这种类型的动画

该动画是在 premier pro 中生成的,但我想在 ffmpeg 中创建它:

在此处输入图片描述

答案1

这将是一行带有我在评论中描述的选项的内容:

 ffmpeg -f lavfi -t 1.5 -i color=size=700x500:color=Black -loop -1 -filter_complex "[0]drawtext=text=This is the 1st Text:font=Arial Black:y=(h-line_h)-15:x=(w)-t*((W+tw)/2)/1.5:fontcolor=green:fontsize=50[Part1];[0]drawtext=text=This is the 1st Text:font=Arial Black:y=(h-line_h)-15:x=(W-tw)/2:fontcolor=green:fontsize=50[Part1_];[0]drawtext=text=This is the 2nd Text:font=Arial Black:y=(h-line_h)-15:x=(w)-t*((W+tw)/2)/1.5:fontcolor=green:fontsize=50[Part2];[0]drawtext=text=This is the 2nd Text:font=Arial Black:y=(h-line_h)-15:x=(w-tw)/2:fontcolor=green:fontsize=50[Part2_];[0]drawtext=text=This is the 3rd Text:font=Arial Black:y=(h-line_h)-15:x=(w)-t*((W+tw)/2)/1.5:fontcolor=green:fontsize=50[Part3];[0]drawtext=text=This is the 3rd Text:font=Arial Black:y=(h-line_h)-15:x=(w-tw)/2:fontcolor=green:fontsize=50[Part3_];[Part1][Part1_][Part2][Part2_][Part3][Part3_]concat=n=6:v=1:a=0[Final]" -map [Final] -compression_level 6 -loop 0 "My Text.gif"

我还制作了一个批处理脚本,用于创建“png”、“webp”和“gif”动画。请将以下代码保存到记事本中,然后使用您想要的名称保存它,但扩展名为 *.bat:

@echo off

set FileName=Text Animation
set BackgroundColor=black
set BackgroundSize=700x500
set TextColor=green
set TextBorder=pink
set TextFont=Arial Black
set TextSize=50
set Speed=1.5
set Text1=This is 1st Text
set Text2=This is 2nd Text
set Text3=This is 3rd Text

if exist "palette.png" del /q "palette.png"

cls
echo.
echo  Creating PNG Animation...
ffmpeg -f lavfi -t %Speed% -i color=size=%BackgroundSize%:color=%BackgroundColor%,format=pix_fmts=yuva420p -loop -1 -filter_complex  "[0]drawtext=text=%Text1%:font=%TextFont%:y=(h-line_h)-15:x=(w)-t*((W+tw)/2)/%Speed%:fontcolor=%TextColor%:borderw=1:bordercolor=%TextBorder%:fontsize=%TextSize%[Part1];[0]drawtext=text=%Text1%:font=%TextFont%:y=(h-line_h)-15:x=(W-tw)/2:fontcolor=%TextColor%:borderw=1:bordercolor=%TextBorder%:fontsize=%TextSize%[Part1_];[0]drawtext=text=%Text2%:font=%TextFont%:y=(h-line_h)-15:x=(w)-t*((W+tw)/2)/%Speed%:fontcolor=%TextColor%:borderw=1:bordercolor=%TextBorder%:fontsize=%TextSize%[Part2];[0]drawtext=text=%Text2%:font=%TextFont%:y=(h-line_h)-15:x=(w-tw)/2:fontcolor=%TextColor%:borderw=1:bordercolor=%TextBorder%:fontsize=%TextSize%[Part2_];[0]drawtext=text=%Text3%:font=%TextFont%:y=(h-line_h)-15:x=(w)-t*((W+tw)/2)/%Speed%:fontcolor=%TextColor%:borderw=1:bordercolor=%TextBorder%:fontsize=%TextSize%[Part3];[0]drawtext=text=%Text3%:font=%TextFont%:y=(h-line_h)-15:x=(w-tw)/2:fontcolor=%TextColor%:borderw=1:bordercolor=%TextBorder%:fontsize=%TextSize%[Part3_];[Part1][Part1_][Part2][Part2_][Part3][Part3_]concat=n=6:v=1:a=0[Final]" -map [Final] -y -compression_level 6 -plays 0 -f apng "%FileName%.png" 1>nul 2>nul

echo.
echo  Creating WEBP Animation...
ffmpeg -i "%FileName%.png" -loop 0 -c:v libwebp_anim -y "%FileName%.webp" 1>nul 2>nul

echo.
echo  Creating GIF Animation...
ffmpeg -i "%FileName%.png" -vf palettegen=reserve_transparent=1 -y "palette.png" 1>nul 2>nul
ffmpeg -i "%FileName%.png" -i "palette.png" -lavfi paletteuse=alpha_threshold=128 -gifflags -offsetting -y "%Filename%.gif" 1>nul 2>nul

if exist "palette.png" del /q "palette.png"
exit

接下来,您可以尝试一下此选项并查看结果,例如,要获得透明背景而不是黑色,请使用 BackgroundColor=#[电子邮件保护]您也可以使用 HTML 代码...

set FileName=Text Animation
set BackgroundColor=black
set BackgroundSize=700x500
set TextColor=green
set TextBorder=pink
set TextFont=Arial Black
set TextSize=50
set Speed=1.5
set Text1=This is 1st Text
set Text2=This is 2nd Text
set Text3=This is 3rd Text

相关内容