With the current code, an automatically inserted aconvert necessary for format change would usually convert to mono for no good reason. The new code will not avoid all conversions, but at least will keep them among the layouts common to both filters.
Showing the changes to libavfilter/avfiltergraph.c (1 of 1 file). Show all
Unified · Split
| @@ -187,6 +187,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) · 186 unmodified lines | ||
| 187 | 187 | { |
| 188 | 188 | int i, j, ret; |
| 189 | 189 | char filt_args[128]; |
| 190 | + AVFilterFormats *formats, *chlayouts, *packing; | |
| 190 | 191 | |
| 191 | 192 | /* ask all the sub-filters for their supported media formats */ |
| 192 | 193 | for (i = 0; i < graph->filter_count; i++) { |
| @@ -221,9 +222,13 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) · 28 unmodified lines | ||
| 221 | 222 | !link->in_packing || !link->out_packing) |
| 222 | 223 | return AVERROR(EINVAL); |
| 223 | 224 | |
| 224 | − if (!avfilter_merge_formats(link->in_formats, link->out_formats) || | |
| 225 | − !avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) || | |
| 226 | − !avfilter_merge_formats(link->in_packing, link->out_packing)) | |
| 225 | + /* Merge all three list before checking: that way, in all | |
| 226 | + * three categories, aconvert will use a common format | |
| 227 | + * whenever possible. */ | |
| 228 | + formats = avfilter_merge_formats(link->in_formats, link->out_formats); | |
| 229 | + chlayouts = avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts); | |
| 230 | + packing = avfilter_merge_formats(link->in_packing, link->out_packing); | |
| 231 | + if (!formats || !chlayouts || !packing) | |
| 227 | 232 | if (ret = insert_conv_filter(graph, link, "aconvert", NULL)) |
| 228 | 233 | return ret; |
| 229 | 234 | } |