Browse code

avconv: pass libavresample options to AVFilterGraph

Justin Ruggles authored on 2012/12/19 11:47:28
Showing 6 changed files
... ...
@@ -2303,6 +2303,7 @@ static int transcode(void)
2303 2303
                 av_freep(&ost->st->codec->subtitle_header);
2304 2304
                 av_free(ost->forced_kf_pts);
2305 2305
                 av_dict_free(&ost->opts);
2306
+                av_dict_free(&ost->resample_opts);
2306 2307
             }
2307 2308
         }
2308 2309
     }
... ...
@@ -293,6 +293,7 @@ typedef struct OutputStream {
293 293
 
294 294
     int64_t sws_flags;
295 295
     AVDictionary *opts;
296
+    AVDictionary *resample_opts;
296 297
     int finished;        /* no more packets should be written for this stream */
297 298
     int stream_copy;
298 299
     const char *attachment_filename;
... ...
@@ -23,8 +23,12 @@
23 23
 #include "libavfilter/avfilter.h"
24 24
 #include "libavfilter/avfiltergraph.h"
25 25
 
26
+#include "libavresample/avresample.h"
27
+
26 28
 #include "libavutil/avassert.h"
29
+#include "libavutil/avstring.h"
27 30
 #include "libavutil/channel_layout.h"
31
+#include "libavutil/opt.h"
28 32
 #include "libavutil/pixdesc.h"
29 33
 #include "libavutil/pixfmt.h"
30 34
 #include "libavutil/samplefmt.h"
... ...
@@ -501,9 +505,21 @@ int configure_filtergraph(FilterGraph *fg)
501 501
 
502 502
     if (simple) {
503 503
         OutputStream *ost = fg->outputs[0]->ost;
504
-        char args[255];
504
+        char args[512];
505
+        AVDictionaryEntry *e = NULL;
506
+        const AVClass *rc = avresample_get_class();
507
+
505 508
         snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
506 509
         fg->graph->scale_sws_opts = av_strdup(args);
510
+
511
+        args[0] = '\0';
512
+        while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e,
513
+                                AV_DICT_IGNORE_SUFFIX))) {
514
+            av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
515
+        }
516
+        if (strlen(args))
517
+            args[strlen(args) - 1] = '\0';
518
+        fg->graph->resample_lavr_opts = av_strdup(args);
507 519
     }
508 520
 
509 521
     if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
... ...
@@ -844,6 +844,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
844 844
 
845 845
     av_opt_get_int(o->g->sws_opts, "sws_flags", 0, &ost->sws_flags);
846 846
 
847
+    av_dict_copy(&ost->resample_opts, o->g->resample_opts, 0);
848
+
847 849
     ost->pix_fmts[0] = ost->pix_fmts[1] = AV_PIX_FMT_NONE;
848 850
 
849 851
     return ost;
... ...
@@ -54,7 +54,7 @@
54 54
 #endif
55 55
 
56 56
 struct SwsContext *sws_opts;
57
-AVDictionary *format_opts, *codec_opts;
57
+AVDictionary *format_opts, *codec_opts, *resample_opts;
58 58
 
59 59
 static const int this_year = 2013;
60 60
 
... ...
@@ -74,6 +74,7 @@ void uninit_opts(void)
74 74
 #endif
75 75
     av_dict_free(&format_opts);
76 76
     av_dict_free(&codec_opts);
77
+    av_dict_free(&resample_opts);
77 78
 }
78 79
 
79 80
 void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
... ...
@@ -405,6 +406,7 @@ int opt_default(void *optctx, const char *opt, const char *arg)
405 405
     char opt_stripped[128];
406 406
     const char *p;
407 407
     const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
408
+    const AVClass *rc = avresample_get_class();
408 409
 #if CONFIG_SWSCALE
409 410
     const AVClass *sc = sws_get_class();
410 411
 #endif
... ...
@@ -421,6 +423,9 @@ int opt_default(void *optctx, const char *opt, const char *arg)
421 421
     else if ((o = av_opt_find(&fc, opt, NULL, 0,
422 422
                               AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)))
423 423
         av_dict_set(&format_opts, opt, arg, FLAGS);
424
+    else if ((o = av_opt_find(&rc, opt, NULL, 0,
425
+                              AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)))
426
+        av_dict_set(&resample_opts, opt, arg, FLAGS);
424 427
 #if CONFIG_SWSCALE
425 428
     else if ((o = av_opt_find(&sc, opt, NULL, 0,
426 429
                               AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
... ...
@@ -480,9 +485,11 @@ static void finish_group(OptionParseContext *octx, int group_idx,
480 480
 #endif
481 481
     g->codec_opts  = codec_opts;
482 482
     g->format_opts = format_opts;
483
+    g->resample_opts = resample_opts;
483 484
 
484 485
     codec_opts  = NULL;
485 486
     format_opts = NULL;
487
+    resample_opts = NULL;
486 488
 #if CONFIG_SWSCALE
487 489
     sws_opts    = NULL;
488 490
 #endif
... ...
@@ -539,6 +546,7 @@ void uninit_parse_context(OptionParseContext *octx)
539 539
             av_freep(&l->groups[j].opts);
540 540
             av_dict_free(&l->groups[j].codec_opts);
541 541
             av_dict_free(&l->groups[j].format_opts);
542
+            av_dict_free(&l->groups[j].resample_opts);
542 543
 #if CONFIG_SWSCALE
543 544
             sws_freeContext(l->groups[j].sws_opts);
544 545
 #endif
... ...
@@ -645,7 +653,7 @@ do {                                                                           \
645 645
         return AVERROR_OPTION_NOT_FOUND;
646 646
     }
647 647
 
648
-    if (octx->cur_group.nb_opts || codec_opts || format_opts)
648
+    if (octx->cur_group.nb_opts || codec_opts || format_opts || resample_opts)
649 649
         av_log(NULL, AV_LOG_WARNING, "Trailing options were found on the "
650 650
                "commandline.\n");
651 651
 
... ...
@@ -42,7 +42,7 @@ extern const int program_birth_year;
42 42
 extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
43 43
 extern AVFormatContext *avformat_opts;
44 44
 extern struct SwsContext *sws_opts;
45
-extern AVDictionary *format_opts, *codec_opts;
45
+extern AVDictionary *format_opts, *codec_opts, *resample_opts;
46 46
 
47 47
 /**
48 48
  * Initialize the cmdutils option system, in particular
... ...
@@ -235,6 +235,7 @@ typedef struct OptionGroup {
235 235
 
236 236
     AVDictionary *codec_opts;
237 237
     AVDictionary *format_opts;
238
+    AVDictionary *resample_opts;
238 239
     struct SwsContext *sws_opts;
239 240
 } OptionGroup;
240 241