不确定您是否想到了这一点……但这是一种对我有用的方法。
提示1:使用库“编码任何过滤器”的先决条件是
理解 ffmpeg 命令行语法。
提示2:一般情况下,ffmpeg.filter() 将过滤器名称作为第一个参数。紧随其后的是所有过滤条件。该函数将下游的流返回到您刚刚创建的过滤器节点。
例如:在问题的示例 ffmpeg 命令行中...阅读它告诉我您要缩放视频,然后应用 boxblur 过滤器,然后进行裁剪。
所以你可以用ffmpeg-python 来表示它
# create a stream object, Note that any supplied kwargs are passed to ffmpeg verbatim
my_vid_stream = ffmpeg.input(input_file, "lavfi")
# The input() returns a stream object has what is called 'base_object' which represents the outgoing edge of an upstream node and can be used to create more downstream nodes. That is what we will do. This stream base_object has two properties, audio and video .. assign the video stream to a new variable, we will be creating filters to only video stream, as indicated by [0:v] in ffmpeg command line.
my_vid_stream = mystream.video
# ffmpeg.filter() takes the upstream node followed by the name of the filter, followed by the configuration of the filter
# first filter you wanted to apply is 'scale' filter. So...
my_vid_stream = ffmpeg.filter(my_vid_stream,"scale","ih*16/9:-1")
# next to the upstream node create a new filter which does the boxblur operation per your specs. so ..
my_vid_stream = ffmpeg.filter(my_vid_stream,"boxblur", "min(h\,w)/20:luma_power=1:chroma_radius=min(cw\,ch)/20:chroma_power=1[bg];[bg][0:v]overlay=(W-w)/2:(H-h)/2")
# finally apply the crop filter to it's upstream node and assign the output stream back to the same variable. so ...
my_vid_stream = ffmpeg.filter(my_vid_stream, "crop", h="iw*9/16")
# now generate the output node and write it to an output file.
my_vid_stream = ffmpeg.output(my_vid_stream,output_file)
## to see your pipeline in action. call the ffmpeg.run(my_vid_stream)
希望这可以帮助您或其他任何努力有效利用此库的人。