简体   繁体   中英

FFMpeg C++ How to create a filter with multiple outputs?

For example, we have one AVFrame with a size of 128x128 pixels and the task is to split the AVFrame into 4 parts (4 separate AVFrame ). To do this, I fill the graph with filters using the avfilter_graph_parse2(...) function, and then call avfilter_graph_config(...) .

Let's start. Let's cut out the top left corner. To crop a frame, we need to use the crop filter, which means we initialize the AVFilterGraph graph with the line:

buffer = width = 128: height = 128: pix_fmt = 2: time_base = 1/25, pixel_aspect = 128/64 [pad_in];
[pad_in] crop = w = 64: h = 64: x = 0: y = 0, buffersink;

Everything works great! Now let's try to make several outputs:

buffer = width = 128: height = 128: pix_fmt = 2: time_base = 1/25, pixel_aspect = 128/64 [pad_in];
[pad_in] crop = w = 64: h = 64: x = 0: y = 0, buffersink;
[pad_in] crop = w = 64: h = 64: x = 64: y = 0, buffersink;
[pad_in] crop = w = 64: h = 64: x = 0: y = 64, buffersink;
[pad_in] crop = w = 64: h = 64: x = 64: y = 64, buffersink

As you can see, we have one buffer for the input image, 4 crop filters for cutting each piece, and 4 buffersink filters for the output images. The call avfilter_graph_parse2(...) returns 0, which is good, but avfilter_graph_config() returns the error code -22 == AVERROR(EINVAL) and the message is output to the console: Input pad "default" with type video of the filter instance "Parsed_crop_3" of crop not connected to any source.

I am asking for your help in creating a filter with multiple outputs.

Alan's comment directed me to split filter . And I did this:

buffer=width=128:height=128:pix_fmt=2:time_base=1/25,sar=1 [pad_in];
[pad_in] split=4 [pad_split_0] [pad_split_1] [pad_split_2] [pad_split_3];
[pad_split_0] crop=w=64:h=64:x=0:y=0,buffersink;
[pad_split_1] crop=w=64:h=64:x=64:y=0,buffersink;
[pad_split_2] crop=w=64:h=64:x=0:y=64,buffersink;
[pad_split_3] crop=w=64:h=64:x=64:y=64,buffersink

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM