问题描述
为什么 ffmpeg 中的 sendcmd
对 drawtext
有效,但对 scale
、rotation
和其他过滤器无效?
示例(此代码有效)
ffmpeg -i testIN.mp4 -filter_complex "[0:v]sendcmd=f=testTXT.cmd,drawtext=fontfile=PF.ttf:text='': fontcolor=white:fontsize=150" testOUT.mp4
testTXT.cmd
0 drawtext reinit 'text=111';1 drawtext reinit 'text=222';2 drawtext reinit 'text=333';
示例(此代码不起作用)
ffmpeg -i testIN.mp4 -filter_complex "[0:v]sendcmd=f=testTXT.cmd,drawbox=x=10:y=10:w=100:h=100" testOUT.mp4
testTXT.cmd
0 drawbox reinit 'x=20:y=20:w=200:h=200';1个拉杆重新初始化'x=30:y=30:w=300:h=300';2 drawbox reinit 'x=40:y=40:w=400:h=400';
您遇到了几个问题:
并非所有过滤器都支持 sendcmd.您可以使用
ffmpeg -filters
查看哪些过滤器支持 sendcmd.查找过滤器名称左侧的C
".此外,只有某些过滤器选项(又名 sendcmd命令")可以与 sendcmd 一起使用.请参阅FFmpeg 过滤器文档,或参考man ffmpeg-filters
,并查看每个过滤器的 Commands 部分下的可用选项.每个过滤器命令都必须在 sendcmd 文件中声明.文档示例中显示的
reinit
似乎仅限于 drawtext 过滤器,但这在文档中没有解释.
旋转示例
示例 sendcmd 文本文件:
0 旋转角度 '45*PI/180';1 旋转角度'90*PI/180';2 旋转角度'180*PI/180';
示例 ffmpeg
命令:
ffmpeg -i input.mp4 -filter_complex "[0:v]sendcmd=f=test.cmd,rotate" output.mp4
上面的例子将在持续时间0
、1
和2
上轮换.
叠加示例
示例 sendcmd 文本文件:
0覆盖@1 x 10,覆盖@1 y 10,覆盖@2 x W-w-10,叠加@2 y H-h-10,覆盖@3 x (W-w)/2,覆盖@3 y (H-h)/2;#overlay@1 在此期间不会移动,因此此处不需要新条目2.25覆盖@2 x 10,叠加@2 y H-h-10,覆盖@3 x (W-w)/2,覆盖@3 y H-h-10;示例 ffmpeg
命令:
ffmpeg -i video.mp4 -i overlay1.png -i overlay2.jpg -i overlay3.png -filter_complex "[0:v]sendcmd=f=test.cmd,nullsink;[0:v][1:v]overlay@1[bg1];[bg1][2:v]overlay@2[bg2];[bg2][3:v]overlay[v]" -map "[v]" -map 0:一个?-c:a 复制 output.mp4
Why sendcmd
in ffmpeg works with drawtext
, but does not work with scale
, rotation
and other filters?
Example (this code works)
ffmpeg -i testIN.mp4 -filter_complex "[0:v]sendcmd=f=testTXT.cmd,drawtext=fontfile=PF.ttf:text='': fontcolor=white:fontsize=150" testOUT.mp4
testTXT.cmd
0 drawtext reinit 'text=111';
1 drawtext reinit 'text=222';
2 drawtext reinit 'text=333';
Example (this code does not work)
ffmpeg -i testIN.mp4 -filter_complex "[0:v]sendcmd=f=testTXT.cmd,drawbox=x=10:y=10:w=100:h=100" testOUT.mp4
testTXT.cmd
0 drawbox reinit 'x=20:y=20:w=200:h=200';
1 drawbox reinit 'x=30:y=30:w=300:h=300';
2 drawbox reinit 'x=40:y=40:w=400:h=400';
You are encountering several issues:
Not all filters support sendcmd. You can see which filters support sendcmd with
ffmpeg -filters
. Look for a "C
" to the left of the filter name. Additionally, only certain filter options (aka sendcmd "commands") can be used with sendcmd. See the FFmpeg filter documentation, or refer toman ffmpeg-filters
, and view the available options under the Commands section for each filter.Each filter command must be declared in the sendcmd file. The
reinit
shown in the documentation example appears to be limited to the drawtext filter, but this is not explained in the documentation.
rotate example
Example sendcmd text file:
0 rotate angle '45*PI/180';
1 rotate angle '90*PI/180';
2 rotate angle '180*PI/180';
Example ffmpeg
command:
ffmpeg -i input.mp4 -filter_complex "[0:v]sendcmd=f=test.cmd,rotate" output.mp4
The above example will rotate on duration 0
, 1
, and 2
.
overlay example
Example sendcmd text file:
0
overlay@1 x 10,
overlay@1 y 10,
overlay@2 x W-w-10,
overlay@2 y H-h-10,
overlay@3 x (W-w)/2,
overlay@3 y (H-h)/2;
# overlay@1 does not move at this duration so it needs no new entry here
2.25
overlay@2 x 10,
overlay@2 y H-h-10,
overlay@3 x (W-w)/2,
overlay@3 y H-h-10;
Example ffmpeg
command:
ffmpeg -i video.mp4 -i overlay1.png -i overlay2.jpg -i overlay3.png -filter_complex "[0:v]sendcmd=f=test.cmd,nullsink;[0:v][1:v]overlay@1[bg1];[bg1][2:v]overlay@2[bg2];[bg2][3:v]overlay[v]" -map "[v]" -map 0:a? -c:a copy output.mp4
这篇关于ffmpeg中的Sendcmd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!