Hi guys

$subject.

What was the decision for passing options to scaler ?

Btw, people might want to hook another scaler and use it to "auto scale", so it seems needed to choose a generic and simple way.

--
Baptiste COUDURIER
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org
--- ../diffs/02_ffmpeg_filters.diff	2010-04-01 12:12:01.023337425 -0700
+++ ../diffs/02_ffmpeg_filters_2.diff	2010-04-01 12:38:43.053299288 -0700
@@ -22,7 +22,7 @@ Index: ffmpeg.c
  static int qp_hist = 0;
 +#if CONFIG_AVFILTER
 +static char *vfilters = NULL;
-+AVFilterGraph *filt_graph_all = NULL;
++AVFilterGraph *graph = NULL;
 +#endif
  
  static int intra_only = 0;
@@ -41,7 +41,7 @@ Index: ffmpeg.c
  } AVInputStream;
  
  typedef struct AVInputFile {
-@@ -320,6 +338,184 @@
+@@ -320,6 +338,180 @@
  static struct termios oldtty;
  #endif
  
@@ -115,72 +115,68 @@ Index: ffmpeg.c
 +
 +static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
 +{
-+    AVFilterContext *curr_filter;
++    AVFilterContext *last_filter, filter;
 +    /** filter graph containing all filters including input & output */
 +    AVCodecContext *codec = ost->st->codec;
 +    AVCodecContext *icodec = ist->st->codec;
 +    char args[255];
 +
-+    filt_graph_all = av_mallocz(sizeof(AVFilterGraph));
++    graph = av_mallocz(sizeof(AVFilterGraph));
 +
-+    if(!(ist->input_video_filter = avfilter_open(avfilter_get_by_name("buffer"), "src")))
++    if (!(ist->input_video_filter = avfilter_open(avfilter_get_by_name("buffer"), "src")))
 +        return -1;
-+    if(!(ist->out_video_filter = avfilter_open(&output_filter, "out")))
++    if (!(ist->out_video_filter = avfilter_open(&output_filter, "out")))
 +        return -1;
 +
 +    snprintf(args, 255, "%d:%d:%d", ist->st->codec->width,
 +             ist->st->codec->height, ist->st->codec->pix_fmt);
-+    if(avfilter_init_filter(ist->input_video_filter, args, NULL))
++    if (avfilter_init_filter(ist->input_video_filter, args, NULL))
 +        return -1;
-+    if(avfilter_init_filter(ist->out_video_filter, NULL, &codec->pix_fmt))
++    if (avfilter_init_filter(ist->out_video_filter, NULL, &codec->pix_fmt))
 +        return -1;
 +
 +    /* add input and output filters to the overall graph */
-+    avfilter_graph_add_filter(filt_graph_all, ist->input_video_filter);
-+    avfilter_graph_add_filter(filt_graph_all, ist->out_video_filter);
++    avfilter_graph_add_filter(graph, ist->input_video_filter);
++    avfilter_graph_add_filter(graph, ist->out_video_filter);
 +
-+    curr_filter = ist->input_video_filter;
++    last_filter = ist->input_video_filter;
 +
-+    if(ost->video_crop) {
-+        char crop_args[255];
-+        AVFilterContext *filt_crop;
-+        snprintf(crop_args, 255, "%d:%d:%d:%d", ost->leftBand, ost->topBand,
++    if (ost->video_crop) {
++        snprintf(args, 255, "%d:%d:%d:%d", ost->leftBand, ost->topBand,
 +                 codec->width -  (frame_padleft + frame_padright),
 +                 codec->height - (frame_padtop + frame_padbottom));
-+        filt_crop = avfilter_open(avfilter_get_by_name("crop"), NULL);
-+        if (!filt_crop)
++        filter = avfilter_open(avfilter_get_by_name("crop"), NULL);
++        if (!filter)
 +            return -1;
-+        if (avfilter_init_filter(filt_crop, crop_args, NULL))
++        if (avfilter_init_filter(filter, args, NULL))
 +            return -1;
-+        if (avfilter_link(curr_filter, 0, filt_crop, 0))
++        if (avfilter_link(last_filter, 0, filter, 0))
 +            return -1;
-+        curr_filter = filt_crop;
-+        avfilter_graph_add_filter(filt_graph_all, curr_filter);
++        last_filter = filter;
++        avfilter_graph_add_filter(graph, filter);
 +    }
 +
-+    if((codec->width !=
-+        icodec->width - (frame_leftBand + frame_rightBand) +
-+        (frame_padleft + frame_padright)) ||
-+       (codec->height != icodec->height - (frame_topBand  + frame_bottomBand) +
-+        (frame_padtop + frame_padbottom))) {
-+        char crop_args[255];
-+        AVFilterContext *filt_scale;
-+        snprintf(crop_args, 255, "%d:%d:sws_flags=%d",
++    if ((codec->width !=
++         icodec->width - (frame_leftBand + frame_rightBand) +
++         (frame_padleft + frame_padright)) ||
++        (codec->height != icodec->height - (frame_topBand  + frame_bottomBand) +
++         (frame_padtop + frame_padbottom))) {
++        snprintf(args, 255, "%d:%d:sws_flags=%d",
 +                 codec->width  - (frame_padleft + frame_padright),
 +                 codec->height - (frame_padtop  + frame_padbottom),
 +                 (int)av_get_int(sws_opts, "sws_flags", NULL));
-+        filt_scale = avfilter_open(avfilter_get_by_name("scale"), NULL);
-+        if (!filt_scale)
++        filter = avfilter_open(avfilter_get_by_name("scale"), NULL);
++        if (!filter)
 +            return -1;
-+        if (avfilter_init_filter(filt_scale, crop_args, NULL))
++        if (avfilter_init_filter(filter, args, NULL))
 +            return -1;
-+        if (avfilter_link(curr_filter, 0, filt_scale, 0))
++        if (avfilter_link(filter, 0, filter, 0))
 +            return -1;
-+        curr_filter = filt_scale;
-+        avfilter_graph_add_filter(filt_graph_all, curr_filter);
++        last_filter = filter;
++        avfilter_graph_add_filter(graph, last_filter);
 +    }
 +
-+    if(vfilters) {
++    if (vfilters) {
 +        AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut));
 +        AVFilterInOut *inputs  = av_malloc(sizeof(AVFilterInOut));
 +
@@ -194,26 +190,26 @@ Index: ffmpeg.c
 +        inputs->pad_idx = 0;
 +        inputs->next    = NULL;
 +
-+        if (avfilter_graph_parse(filt_graph_all, vfilters, inputs, outputs, NULL) < 0)
++        if (avfilter_graph_parse(graph, vfilters, inputs, outputs, NULL) < 0)
 +            return -1;
 +        av_freep(&vfilters);
 +    } else {
-+        if(avfilter_link(curr_filter, 0, ist->out_video_filter, 0) < 0)
++        if (avfilter_link(last_filter, 0, ist->out_video_filter, 0) < 0)
 +            return -1;
 +    }
 +
 +    {
 +        char scale_sws_opts[128];
 +        snprintf(scale_sws_opts, sizeof(scale_sws_opts), "sws_flags=%d", (int)av_get_int(sws_opts, "sws_flags", NULL));
-+        filt_graph_all->scale_sws_opts = av_strdup(scale_sws_opts);
++        graph->scale_sws_opts = av_strdup(scale_sws_opts);
 +    }
 +
 +    /* configure all the filter links */
-+    if(avfilter_graph_check_validity(filt_graph_all, NULL))
++    if (avfilter_graph_check_validity(graph, NULL))
 +        return -1;
-+    if(avfilter_graph_config_formats(filt_graph_all, NULL))
++    if (avfilter_graph_config_formats(graph, NULL))
 +        return -1;
-+    if(avfilter_graph_config_links(filt_graph_all, NULL))
++    if (avfilter_graph_config_links(graph, NULL))
 +        return -1;
 +
 +    codec->width = ist->out_video_filter->inputs[0]->w;
@@ -226,7 +222,7 @@ Index: ffmpeg.c
  static void term_exit(void)
  {
  #if HAVE_TERMIOS_H
-@@ -461,6 +657,10 @@
+@@ -461,6 +653,10 @@
      allocated_audio_buf_size= allocated_audio_out_size= 0;
      av_free(samples);
  
@@ -237,7 +233,7 @@ Index: ffmpeg.c
      if (received_sigterm) {
          fprintf(stderr,
              "Received signal %d: terminating.\n",
-@@ -923,7 +1123,9 @@
+@@ -923,7 +1119,9 @@
                           int *frame_size)
  {
      int nb_frames, i, ret;
@@ -247,7 +243,7 @@ Index: ffmpeg.c
      AVFrame *final_picture, *formatted_picture, *resampling_dst, *padding_src;
      AVFrame picture_crop_temp, picture_pad_temp;
      AVCodecContext *enc, *dec;
-@@ -971,6 +1173,9 @@
+@@ -971,6 +1169,9 @@
      if (nb_frames <= 0)
          return;
  
@@ -257,7 +253,7 @@ Index: ffmpeg.c
      if (ost->video_crop) {
          if (av_picture_crop((AVPicture *)&picture_crop_temp, (AVPicture *)in_picture, dec->pix_fmt, ost->topBand, ost->leftBand) < 0) {
              fprintf(stderr, "error cropping picture\n");
-@@ -982,6 +1187,7 @@
+@@ -982,6 +1183,7 @@
      } else {
          formatted_picture = in_picture;
      }
@@ -265,7 +261,7 @@ Index: ffmpeg.c
  
      final_picture = formatted_picture;
      padding_src = formatted_picture;
-@@ -1008,6 +1214,7 @@
+@@ -1008,6 +1210,7 @@
              av_exit(1);
      }
  
@@ -273,7 +269,7 @@ Index: ffmpeg.c
      if (ost->video_resample) {
          padding_src = NULL;
          final_picture = &ost->pict_tmp;
-@@ -1055,6 +1262,7 @@
+@@ -1055,6 +1258,7 @@
          sws_scale(ost->img_resample_ctx, formatted_picture->data, formatted_picture->linesize,
                0, ost->resample_height, resampling_dst->data, resampling_dst->linesize);
      }
@@ -281,18 +277,18 @@ Index: ffmpeg.c
  
      if (ost->video_pad) {
          av_picture_pad((AVPicture*)final_picture, (AVPicture *)padding_src,
-@@ -1320,6 +1528,10 @@
+@@ -1320,6 +1524,10 @@
      static unsigned int samples_size= 0;
      AVSubtitle subtitle, *subtitle_to_free;
      int got_subtitle;
 +#if CONFIG_AVFILTER
-+    int loop;
++    int frame_available;
 +#endif
 +
      AVPacket avpkt;
      int bps = av_get_bits_per_sample_format(ist->st->codec->sample_fmt)>>3;
  
-@@ -1447,6 +1659,15 @@
+@@ -1447,6 +1655,15 @@
                                      &buffer_to_free);
          }
  
@@ -308,27 +304,27 @@ Index: ffmpeg.c
          // preprocess audio (volume)
          if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
              if (audio_volume != 256) {
-@@ -1468,10 +1689,18 @@
+@@ -1468,10 +1685,18 @@
              if (pts > now)
                  usleep(pts - now);
          }
 -
 +#if CONFIG_AVFILTER
-+        loop = ist->st->codec->codec_type != CODEC_TYPE_VIDEO ||
++        frame_available = ist->st->codec->codec_type != CODEC_TYPE_VIDEO ||
 +            !ist->out_video_filter || avfilter_poll_frame(ist->out_video_filter->inputs[0]);
 +#endif
          /* if output time reached then transcode raw format,
             encode packets and output them */
          if (start_time == 0 || ist->pts >= start_time)
 +#if CONFIG_AVFILTER
-+        while(loop) {
++        while(frame_available) {
 +            if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO && ist->out_video_filter)
 +                get_filtered_video_pic(ist->out_video_filter, &ist->picref, &picture, &ist->pts);
 +#endif
              for(i=0;i<nb_ostreams;i++) {
                  int frame_size;
  
-@@ -1489,6 +1718,9 @@
+@@ -1489,6 +1714,9 @@
                              do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size);
                              break;
                          case AVMEDIA_TYPE_VIDEO:
@@ -338,7 +334,7 @@ Index: ffmpeg.c
                              do_video_out(os, ost, ist, &picture, &frame_size);
                              if (vstats_filename && frame_size)
                                  do_video_stats(os, ost, frame_size);
-@@ -1557,7 +1789,17 @@
+@@ -1557,7 +1785,17 @@
                          av_free_packet(&opkt);
                      }
                  }
@@ -356,7 +352,7 @@ Index: ffmpeg.c
          av_free(buffer_to_free);
          /* XXX: allocate the subtitles in the codec ? */
          if (subtitle_to_free) {
-@@ -2039,9 +2281,10 @@
+@@ -2039,9 +2277,10 @@
                          av_exit(1);
                      }
  
@@ -368,7 +364,7 @@ Index: ffmpeg.c
                      codec->bits_per_raw_sample= 0;
                  }
                  ost->resample_height = icodec->height - (frame_topBand  + frame_bottomBand);
-@@ -2049,6 +2292,13 @@
+@@ -2049,6 +2288,13 @@
                  ost->resample_pix_fmt= icodec->pix_fmt;
                  ost->encoding_needed = 1;
                  ist->decoding_needed = 1;
@@ -382,20 +378,20 @@ Index: ffmpeg.c
                  break;
              case AVMEDIA_TYPE_SUBTITLE:
                  ost->encoding_needed = 1;
-@@ -2447,6 +2697,12 @@
+@@ -2447,6 +2693,12 @@
              avcodec_close(ist->st->codec);
          }
      }
 +#if CONFIG_AVFILTER
-+    if (filt_graph_all) {
-+        avfilter_graph_destroy(filt_graph_all);
-+        av_freep(&filt_graph_all);
++    if (graph) {
++        avfilter_graph_destroy(graph);
++        av_freep(&graph);
 +    }
 +#endif
  
      /* finished ! */
      ret = 0;
-@@ -4023,6 +4279,9 @@
+@@ -4023,6 +4275,9 @@
      { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
      { "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" },
      { "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" },
@@ -405,7 +401,7 @@ Index: ffmpeg.c
      { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
      { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" },
      { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" },
-@@ -4083,6 +4342,9 @@
+@@ -4083,6 +4338,9 @@
  
      avcodec_register_all();
      avdevice_register_all();
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to