Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
833 views
in Technique[技术] by (71.8m points)

video - Sendcmd in ffmpeg

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';
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...