Merge commit '2e661f26f8b12195f75ae3b07d9591e395135bc7'
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 6 Aug 2013 08:08:17 +0000 (10:08 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 6 Aug 2013 08:08:17 +0000 (10:08 +0200)
* commit '2e661f26f8b12195f75ae3b07d9591e395135bc7':
  avconv: insert extra filters in the same way for both graph inputs and outputs

Conflicts:
ffmpeg_filter.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
ffmpeg_filter.c

diff --cc ffmpeg_filter.c
@@@ -617,22 -417,10 +617,21 @@@ static int configure_input_video_filter
      InputStream *ist = ifilter->ist;
      AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
                                           ist->st->time_base;
 +    AVRational fr = ist->framerate;
      AVRational sar;
 -    char args[255], name[255];
 +    AVBPrint args;
 +    char name[255];
-     int pad_idx = in->pad_idx;
      int ret;
  
 +    if (!fr.num)
 +        fr = av_guess_frame_rate(input_files[ist->file_index]->ctx, ist->st, NULL);
 +
 +    if (ist->st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
 +        ret = sub2video_prepare(ist);
 +        if (ret < 0)
 +            return ret;
 +    }
 +
      sar = ist->st->sample_aspect_ratio.num ?
            ist->st->sample_aspect_ratio :
            ist->st->codec->sample_aspect_ratio;
               ist->file_index, ist->st->index);
  
      if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
 -                                            args, NULL, fg->graph)) < 0)
 +                                            args.str, NULL, fg->graph)) < 0)
          return ret;
+     last_filter = ifilter->filter;
  
      if (ist->framerate.num) {
          AVFilterContext *setpts;
                                                  fg->graph)) < 0)
              return ret;
  
-         if ((ret = avfilter_link(setpts, 0, first_filter, pad_idx)) < 0)
+         if ((ret = avfilter_link(last_filter, 0, setpts, 0)) < 0)
              return ret;
  
-         first_filter = setpts;
-         pad_idx = 0;
+         last_filter = setpts;
      }
  
-         if ((ret = avfilter_link(yadif, 0, first_filter, pad_idx)) < 0)
 +    if (do_deinterlace) {
 +        AVFilterContext *yadif;
 +
 +        snprintf(name, sizeof(name), "deinterlace input from stream %d:%d",
 +                 ist->file_index, ist->st->index);
 +        if ((ret = avfilter_graph_create_filter(&yadif,
 +                                                avfilter_get_by_name("yadif"),
 +                                                name, "", NULL,
 +                                                fg->graph)) < 0)
 +            return ret;
 +
-         first_filter = yadif;
-         pad_idx = 0;
++        if ((ret = avfilter_link(last_filter, 0, yadif, 0)) < 0)
 +            return ret;
 +
-     if ((ret = avfilter_link(ifilter->filter, 0, first_filter, pad_idx)) < 0)
++        last_filter = yadif;
 +    }
 +
+     if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
          return ret;
      return 0;
  }
  static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
                                          AVFilterInOut *in)
  {
-     AVFilterContext *first_filter = in->filter_ctx;
+     AVFilterContext *last_filter;
      const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
      InputStream *ist = ifilter->ist;
-     int pad_idx = in->pad_idx;
 -    char args[255], name[255];
 +    AVBPrint args;
 +    char name[255];
      int ret;
  
 -    snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s"
 -             ":channel_layout=0x%"PRIx64,
 +    av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC);
 +    av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
               1, ist->st->codec->sample_rate,
               ist->st->codec->sample_rate,
 -             av_get_sample_fmt_name(ist->st->codec->sample_fmt),
 -             ist->st->codec->channel_layout);
 +             av_get_sample_fmt_name(ist->st->codec->sample_fmt));
 +    if (ist->st->codec->channel_layout)
 +        av_bprintf(&args, ":channel_layout=0x%"PRIx64,
 +                   ist->st->codec->channel_layout);
 +    else
 +        av_bprintf(&args, ":channels=%d", ist->st->codec->channels);
      snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
               ist->file_index, ist->st->index);
  
      if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
 -                                            name, args, NULL,
 +                                            name, args.str, NULL,
                                              fg->graph)) < 0)
          return ret;
+     last_filter = ifilter->filter;
  
-     ret = avfilter_link(filt_ctx, 0, first_filter, pad_idx);                \
 +#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do {                 \
 +    AVFilterContext *filt_ctx;                                              \
 +                                                                            \
 +    av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi "            \
 +           "similarly to -af " filter_name "=%s.\n", arg);                  \
 +                                                                            \
 +    snprintf(name, sizeof(name), "graph %d %s for input stream %d:%d",      \
 +                fg->index, filter_name, ist->file_index, ist->st->index);   \
 +    ret = avfilter_graph_create_filter(&filt_ctx,                           \
 +                                       avfilter_get_by_name(filter_name),   \
 +                                       name, arg, NULL, fg->graph);         \
 +    if (ret < 0)                                                            \
 +        return ret;                                                         \
 +                                                                            \
-     first_filter = filt_ctx;                                                  \
++    ret = avfilter_link(last_filter, 0, filt_ctx, 0);                       \
 +    if (ret < 0)                                                            \
 +        return ret;                                                         \
 +                                                                            \
++    last_filter = filt_ctx;                                                 \
 +} while (0)
 +
      if (audio_sync_method > 0) {
 -        AVFilterContext *async;
 -        int  len = 0;
 -
 -        av_log(NULL, AV_LOG_WARNING, "-async has been deprecated. Used the "
 -               "asyncts audio filter instead.\n");
 -
 -        if (audio_sync_method > 1)
 -            len += snprintf(args + len, sizeof(args) - len, "compensate=1:"
 -                            "max_comp=%d:", audio_sync_method);
 -        snprintf(args + len, sizeof(args) - len, "min_delta=%f",
 -                 audio_drift_threshold);
 -
 -        snprintf(name, sizeof(name), "graph %d audio sync for input stream %d:%d",
 -                 fg->index, ist->file_index, ist->st->index);
 -        ret = avfilter_graph_create_filter(&async,
 -                                           avfilter_get_by_name("asyncts"),
 -                                           name, args, NULL, fg->graph);
 -        if (ret < 0)
 -            return ret;
 +        char args[256] = {0};
 +
 +        av_strlcatf(args, sizeof(args), "async=%d", audio_sync_method);
 +        if (audio_drift_threshold != 0.1)
 +            av_strlcatf(args, sizeof(args), ":min_hard_comp=%f", audio_drift_threshold);
 +        if (!fg->reconfiguration)
 +            av_strlcatf(args, sizeof(args), ":first_pts=0");
 +        AUTO_INSERT_FILTER_INPUT("-async", "aresample", args);
 +    }
  
 -        ret = avfilter_link(last_filter, 0, async, 0);
 -        if (ret < 0)
 -            return ret;
 +//     if (ost->audio_channels_mapped) {
 +//         int i;
 +//         AVBPrint pan_buf;
 +//         av_bprint_init(&pan_buf, 256, 8192);
 +//         av_bprintf(&pan_buf, "0x%"PRIx64,
 +//                    av_get_default_channel_layout(ost->audio_channels_mapped));
 +//         for (i = 0; i < ost->audio_channels_mapped; i++)
 +//             if (ost->audio_channels_map[i] != -1)
 +//                 av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]);
 +//         AUTO_INSERT_FILTER_INPUT("-map_channel", "pan", pan_buf.str);
 +//         av_bprint_finalize(&pan_buf, NULL);
 +//     }
  
 -        last_filter = async;
 -    }
      if (audio_volume != 256) {
 -        AVFilterContext *volume;
 +        char args[256];
  
          av_log(NULL, AV_LOG_WARNING, "-vol has been deprecated. Use the volume "
                 "audio filter instead.\n");
  
 -        snprintf(args, sizeof(args), "volume=%f", audio_volume / 256.0);
 -
 -        snprintf(name, sizeof(name), "graph %d volume for input stream %d:%d",
 -                 fg->index, ist->file_index, ist->st->index);
 -        ret = avfilter_graph_create_filter(&volume,
 -                                           avfilter_get_by_name("volume"),
 -                                           name, args, NULL, fg->graph);
 -        if (ret < 0)
 -            return ret;
 -
 -        ret = avfilter_link(last_filter, 0, volume, 0);
 -        if (ret < 0)
 -            return ret;
 -
 -        last_filter = volume;
 +        snprintf(args, sizeof(args), "%f", audio_volume / 256.);
 +        AUTO_INSERT_FILTER_INPUT("-vol", "volume", args);
      }
-     if ((ret = avfilter_link(ifilter->filter, 0, first_filter, pad_idx)) < 0)
+     if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
          return ret;
  
      return 0;