[PATCH] Auto-insert resample filter where necessary.

Stefano Sabatini stefano.sabatini-lala
Wed Jan 12 00:25:10 CET 2011


Based on a patch by Hemanth.
---
 libavfilter/avfiltergraph.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index a62fe2f..4853e46 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -157,22 +157,28 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
             if (link && link->in_formats != link->out_formats) {
                 if (!avfilter_merge_formats(link->in_formats,
                                             link->out_formats)) {
-                    AVFilterContext *scale;
-                    char scale_args[256];
-                    /* couldn't merge format lists. auto-insert scale filter */
-                    snprintf(inst_name, sizeof(inst_name), "auto-inserted scaler %d",
-                             scaler_count++);
-                    snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts);
-                    if ((ret = avfilter_graph_create_filter(&scale, avfilter_get_by_name("scale"),
-                                                            inst_name, scale_args, NULL, graph)) < 0)
+                    AVFilterContext *filt_ctx;
+                    enum AVMediaType type = link->type;
+                    char filt_args[256];
+                    const char *filt_name = type == AVMEDIA_TYPE_VIDEO ? "scale" : "resample";
+
+                    /* couldn't merge format lists. auto-insert scale/resample filter */
+                    snprintf(inst_name, sizeof(inst_name), "auto-inserted %sr %d",
+                             filt_name, scaler_count++);
+                    if (type == AVMEDIA_TYPE_VIDEO)
+                        snprintf(filt_args, sizeof(filt_args), "0:0:%s", graph->scale_sws_opts);
+                    if (type == AVMEDIA_TYPE_AUDIO)
+                        snprintf(filt_args, sizeof(filt_args), "%d:-1", link->out_formats->formats[0]);
+                    if ((ret = avfilter_graph_create_filter(&filt_ctx, avfilter_get_by_name(filt_name),
+                                                            inst_name, filt_args, NULL, graph)) < 0)
                         return ret;
-                    if ((ret = avfilter_insert_filter(link, scale, 0, 0)) < 0)
+                    if ((ret = avfilter_insert_filter(link, filt_ctx, 0, 0)) < 0)
                         return ret;
 
-                    scale->filter->query_formats(scale);
-                    if (((link = scale-> inputs[0]) &&
+                    filt_ctx->filter->query_formats(filt_ctx);
+                    if (((link = filt_ctx-> inputs[0]) &&
                          !avfilter_merge_formats(link->in_formats, link->out_formats)) ||
-                        ((link = scale->outputs[0]) &&
+                        ((link = filt_ctx->outputs[0]) &&
                          !avfilter_merge_formats(link->in_formats, link->out_formats))) {
                         av_log(log_ctx, AV_LOG_ERROR,
                                "Impossible to convert between the formats supported by the filter "
-- 
1.7.2.3


--aT9PWwzfKXlsBJM1--



More information about the ffmpeg-devel mailing list