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

Stefano Sabatini stefano.sabatini-lala
Mon Aug 23 17:14:47 CEST 2010


On date Monday 2010-08-23 00:16:08 -0700, S.N. Hemanth Meenakshisundaram encoded:
> Auto insert af_resample between audio filters with incompatible sample
> formats. This patch works on top of the latest af_resample patch sent
> earlier.
> 
> Passes make test and auto insertion can be tested by modifying af_anull
> to accept only a specified format, say SAMPLE_FMT_FLT. Then doing
> 
> ./ffplay -af anull in.mp3
> 
> ---
>  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 to me.
-- 
FFmpeg = Fantastic and Free Monstrous Puristic Easy God



More information about the ffmpeg-devel mailing list