- avfilter_graph_add_filter(graphctx, scale);
- scale->filter->query_formats(scale);
- if(!avfilter_merge_formats(scale-> inputs[0]->in_formats,
- scale-> inputs[0]->out_formats) ||
- !avfilter_merge_formats(scale->outputs[0]->in_formats,
- scale->outputs[0]->out_formats))
- return -1;
+ snprintf(inst_name, sizeof(inst_name), "auto-inserted resampler %d",
+ resampler_count++);
+ if ((ret = avfilter_graph_create_filter(&convert,
+ avfilter_get_by_name("resample"),
+ inst_name, NULL, NULL, graph)) < 0)
+ return ret;
+ break;
+ default:
+ return AVERROR(EINVAL);
+ }
+
+ if ((ret = avfilter_insert_filter(link, convert, 0, 0)) < 0)
+ return ret;
+
+ convert->filter->query_formats(convert);
+ inlink = convert->inputs[0];
+ outlink = convert->outputs[0];
+ if (!ff_merge_formats( inlink->in_formats, inlink->out_formats) ||
+ !ff_merge_formats(outlink->in_formats, outlink->out_formats))
+ ret |= AVERROR(ENOSYS);
+ if (inlink->type == AVMEDIA_TYPE_AUDIO &&
+ (!ff_merge_samplerates(inlink->in_samplerates,
+ inlink->out_samplerates) ||
+ !ff_merge_channel_layouts(inlink->in_channel_layouts,
+ inlink->out_channel_layouts)))
+ ret |= AVERROR(ENOSYS);
+ if (outlink->type == AVMEDIA_TYPE_AUDIO &&
+ (!ff_merge_samplerates(outlink->in_samplerates,
+ outlink->out_samplerates) ||
+ !ff_merge_channel_layouts(outlink->in_channel_layouts,
+ outlink->out_channel_layouts)))
+ ret |= AVERROR(ENOSYS);
+
+ if (ret < 0) {
+ av_log(log_ctx, AV_LOG_ERROR,
+ "Impossible to convert between the formats supported by the filter "
+ "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
+ return ret;