Sendcmd in ffmpeg

2019-03-02 11:17发布

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';

标签: video ffmpeg
1条回答
Bombasti
2楼-- · 2019-03-02 11:40

You are encountering several issues:

  1. 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 to man ffmpeg-filters, and view the available options under the Commands section for each filter.

  2. 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
查看更多
登录 后发表回答