[FFmpeg-soc] [PATCH] Auto insert resample filter between audio filters during sample format negotiation

Stefano Sabatini stefano.sabatini-lala at poste.it
Mon Aug 16 11:55:51 CEST 2010


On date Monday 2010-08-16 01:07:19 -0700, S.N. Hemanth Meenakshisundaram encoded:
> 
> Inserts resample filter between audio filters with incompatible formats.
> Updated as per Michael's comment earlier.
> Doesn't work in some cases due to a separate issue with lavfi
> framework's merge_formats function. Will post a patch for that when its
> fixed.
> 
> ---
>  libavfilter/avfiltergraph.c |   16 ++++++++++++----
>  1 files changed, 12 insertions(+), 4 deletions(-)
> 
> 
> 

> diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
> index 2123c28..ef13bbf 100644
> --- a/libavfilter/avfiltergraph.c
> +++ b/libavfilter/avfiltergraph.c
> @@ -128,14 +128,22 @@ 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)) {
> +                    enum AVMediaType type = link->type;
>                      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++);
> -                    avfilter_open(&scale, avfilter_get_by_name("scale"), inst_name);
> +                    const char *filt_name = type == AVMEDIA_TYPE_VIDEO ? "scale" : "resample";
> +                    snprintf(inst_name, sizeof(inst_name), "auto-inserted %sr %d",
> +                             filt_name, scaler_count++);
> +                    avfilter_open(&scale, avfilter_get_by_name(filt_name),inst_name);
> +
> +                    if (type == AVMEDIA_TYPE_VIDEO)
> +                        snprintf(scale_args, sizeof(scale_args), "0:0:%s",
> +                                 graph->scale_sws_opts);
> +                    if (type == AVMEDIA_TYPE_AUDIO)
> +                        snprintf(scale_args, sizeof(scale_args), "%d:-1",
> +                                 link->out_formats->formats[0]);
>  
> -                    snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts);
>                      if(!scale || scale->filter->init(scale, scale_args, NULL) ||
>                                   avfilter_insert_filter(link, scale, 0, 0)) {
>                          avfilter_destroy(scale);

Looks OK. I'll apply it as the audio lavfi framework patch will be
applied.

Regards.


More information about the FFmpeg-soc mailing list