Signed-off-by: Nicolas George <geo...@nsup.org> --- libavfilter/avfiltergraph.c | 45 ++++++++++--------------------------- libavfilter/formats.c | 4 ++++ libavfilter/formats.h | 2 ++ 3 files changed, 18 insertions(+), 33 deletions(-)
Obviously to be applied on top of the last two patches. The message when one of the filters changes slightly. I think it is acceptable. The numbering of the automatic filters becomes global. I think it does not matter. diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 37f09cb686..d7a17b429b 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -432,7 +432,7 @@ static int formats_declared(AVFilterContext *f) static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) { int i, j, ret; - int scaler_count = 0, resampler_count = 0; + int converter_count = 0; int count_queried = 0; /* successful calls to query_formats() */ int count_merged = 0; /* successful merge of formats lists */ int count_already_merged = 0; /* lists already merged */ @@ -499,6 +499,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) const AVFilter *filter; AVFilterLink *inlink, *outlink; char inst_name[30]; + const char *opts; if (graph->disable_auto_convert) { av_log(log_ctx, AV_LOG_ERROR, @@ -509,40 +510,18 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) } /* couldn't merge format lists. auto-insert conversion filter */ - switch (link->type) { - case AVMEDIA_TYPE_VIDEO: - if (!(filter = avfilter_get_by_name("scale"))) { - av_log(log_ctx, AV_LOG_ERROR, "'scale' filter " - "not present, cannot convert pixel formats.\n"); - return AVERROR(EINVAL); - } - - snprintf(inst_name, sizeof(inst_name), "auto_scaler_%d", - scaler_count++); - - if ((ret = avfilter_graph_create_filter(&convert, filter, - inst_name, graph->scale_sws_opts, NULL, - graph)) < 0) - return ret; - break; - case AVMEDIA_TYPE_AUDIO: - if (!(filter = avfilter_get_by_name("aresample"))) { - av_log(log_ctx, AV_LOG_ERROR, "'aresample' filter " - "not present, cannot convert audio formats.\n"); - return AVERROR(EINVAL); - } - - snprintf(inst_name, sizeof(inst_name), "auto_resampler_%d", - resampler_count++); - if ((ret = avfilter_graph_create_filter(&convert, filter, - inst_name, graph->aresample_swr_opts, - NULL, graph)) < 0) - return ret; - break; - default: + if (!(filter = avfilter_get_by_name(neg->conversion_filter))) { + av_log(log_ctx, AV_LOG_ERROR, + "'%s' filter not present, cannot convert formats.\n", + neg->conversion_filter); return AVERROR(EINVAL); } - + snprintf(inst_name, sizeof(inst_name), "auto_%s_%d", + neg->conversion_filter, converter_count++); + opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph); + ret = avfilter_graph_create_filter(&convert, filter, inst_name, opts, NULL, graph); + if (ret < 0) + return ret; if ((ret = avfilter_insert_filter(link, convert, 0, 0)) < 0) return ret; diff --git a/libavfilter/formats.c b/libavfilter/formats.c index eceae8ba9c..3e60a01fbd 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -329,11 +329,15 @@ static const AVFilterFormatsMerger mergers_audio[] = { static const AVFilterNegotiation negotiate_video = { .nb = FF_ARRAY_ELEMS(mergers_video), .mergers = mergers_video, + .conversion_filter = "scale", + .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts), }; static const AVFilterNegotiation negotiate_audio = { .nb = FF_ARRAY_ELEMS(mergers_audio), .mergers = mergers_audio, + .conversion_filter = "aresample", + .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts), }; const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link) diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 7a1f8408ac..b2dfeba497 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -78,6 +78,8 @@ typedef struct AVFilterFormatMerger { typedef struct AVFilterNegotiation { unsigned nb; const AVFilterFormatsMerger *mergers; + const char *conversion_filter; + unsigned conversion_opts_offset; } AVFilterNegotiation; const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link); -- 2.30.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".