我试图实现动画文字叠加。我发现了这个线程: ffmpeg moving text drawtext
但是,当我运行此代码时:
ffmpeg -i VideoInput.mp4 \
-vf "drawtext=enable='between(t,12,15)':fontfile=myfont.otf:text='Test test': \
x='if(lt(t-t2+1\,0)\,x1+(x2-x1)*(t-t1)/(t2-t1-1)\,x)': \
y='if(lt(t-t2+1\,0)\,y1+(y2-y1)*(t-t1)/(t2-t1-1)\,y)':fontsize=65" \
-acodec copy outputVideo.mp4
我得到了错误:
[Parsed_drawtext_0 @ 000002d862595c00][Eval @ 000000e1d79fe300] Undefined constant or missing '(' in 't2-t1-1),x)'
[Parsed_drawtext_0 @ 000002d862595c00] Failed to configure input pad on Parsed_drawtext_0
第二个奇怪的错误,可能是最上面的问题的原因。是我不能在多行上运行参数。因此,使用下面的代码,我必须删除斜杠并将其放在1行上。我使用PHP,因此无法正常工作(白屏,无输出)
$arguments = "-i out1.mp4 \
-vf \"drawtext=enable='between(t,12,15)':fontfile=myfont.otf:text='Test test': \
x='if(lt(t-t2+1\,0)\,x1+(x2-x1)*(t-t1)/(t2-t1-1)\,x)': \
y='if(lt(t-t2+1\,0)\,y1+(y2-y1)*(t-t1)/(t2-t1-1)\,y)':fontsize=65\" \
-acodec copy outputVideo.mp4 2>&1";
$output = shell_exec('D:/wamp64/www/createslideshow/ffmpeg-20190319-f8075b2-win64-static/bin/ffmpeg.exe '.$arguments);
这有效,但给出了未定义的恒定错误:
$arguments = "-i out1.mp4 -vf \"drawtext=enable='between(t,12,15)':fontfile=myfont.otf:text='Test test': x='if(lt(t-t2+1\,0)\,x1+(x2-x1)*(t-t1)/(t2-t1-1)\,x)': y='if(lt(t-t2+1\,0)\,y1+(y2-y1)*(t-t1)/(t2-t1-1)\,y)':fontsize=65\" -acodec copy outputVideo.mp4 2>&1";
$output = shell_exec('D:/wamp64/www/createslideshow/ffmpeg-20190319-f8075b2-win64-static/bin/ffmpeg.exe '.$arguments);