ffmpeg: use a AVDictionary instead of the context to move swr parameters around

This avoids per parameter changes in ffmpeg at the cost of making access
somewhat more annoying.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/10/head
Michael Niedermayer 12 years ago
parent f3abdf4392
commit ad899522ff
  1. 21
      cmdutils.c
  2. 4
      cmdutils.h
  3. 1
      ffmpeg.c
  4. 4
      ffmpeg.h
  5. 10
      ffmpeg_filter.c
  6. 7
      ffmpeg_opt.c

@ -62,7 +62,7 @@
static int init_report(const char *env);
struct SwsContext *sws_opts;
SwrContext *swr_opts;
AVDictionary *swr_opts;
AVDictionary *format_opts, *codec_opts, *resample_opts;
const int this_year = 2013;
@ -75,9 +75,6 @@ void init_opts(void)
if(CONFIG_SWSCALE)
sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC,
NULL, NULL, NULL);
if(CONFIG_SWRESAMPLE)
swr_opts = swr_alloc();
}
void uninit_opts(void)
@ -87,9 +84,7 @@ void uninit_opts(void)
sws_opts = NULL;
#endif
if(CONFIG_SWRESAMPLE)
swr_free(&swr_opts);
av_dict_free(&swr_opts);
av_dict_free(&format_opts);
av_dict_free(&codec_opts);
av_dict_free(&resample_opts);
@ -518,13 +513,16 @@ int opt_default(void *optctx, const char *opt, const char *arg)
#endif
#if CONFIG_SWRESAMPLE
swr_class = swr_get_class();
if (!consumed && av_opt_find(&swr_class, opt, NULL, 0,
AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) {
int ret = av_opt_set(swr_opts, opt, arg, 0);
if (!consumed && (o=av_opt_find(&swr_class, opt, NULL, 0,
AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
struct SwrContext *swr = swr_alloc();
int ret = av_opt_set(swr, opt, arg, 0);
swr_free(&swr);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
return ret;
}
av_dict_set(&swr_opts, opt, arg, FLAGS);
consumed = 1;
}
#endif
@ -651,8 +649,7 @@ void uninit_parse_context(OptionParseContext *octx)
#if CONFIG_SWSCALE
sws_freeContext(l->groups[j].sws_opts);
#endif
if(CONFIG_SWRESAMPLE)
swr_free(&l->groups[j].swr_opts);
av_dict_free(&l->groups[j].swr_opts);
}
av_freep(&l->groups);
}

@ -51,7 +51,7 @@ extern const int this_year;
extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
extern AVFormatContext *avformat_opts;
extern struct SwsContext *sws_opts;
extern struct SwrContext *swr_opts;
extern AVDictionary *swr_opts;
extern AVDictionary *format_opts, *codec_opts, *resample_opts;
/**
@ -255,7 +255,7 @@ typedef struct OptionGroup {
AVDictionary *format_opts;
AVDictionary *resample_opts;
struct SwsContext *sws_opts;
struct SwrContext *swr_opts;
AVDictionary *swr_opts;
} OptionGroup;
/**

@ -3212,6 +3212,7 @@ static int transcode(void)
av_freep(&ost->st->codec->subtitle_header);
av_free(ost->forced_kf_pts);
av_dict_free(&ost->opts);
av_dict_free(&ost->swr_opts);
av_dict_free(&ost->resample_opts);
}
}

@ -346,10 +346,8 @@ typedef struct OutputStream {
char *avfilter;
int64_t sws_flags;
int64_t swr_filter_type;
int64_t swr_dither_method;
double swr_dither_scale;
AVDictionary *opts;
AVDictionary *swr_opts;
AVDictionary *resample_opts;
int finished; /* no more packets should be written for this stream */
int unavailable; /* true if the steram is unavailable (possibly temporarily) */

@ -739,12 +739,10 @@ int configure_filtergraph(FilterGraph *fg)
fg->graph->scale_sws_opts = av_strdup(args);
args[0] = 0;
if (ost->swr_filter_type != SWR_FILTER_TYPE_KAISER)
av_strlcatf(args, sizeof(args), "filter_type=%d:", (int)ost->swr_filter_type);
if (ost->swr_dither_method)
av_strlcatf(args, sizeof(args), "dither_method=%d:", (int)ost->swr_dither_method);
if (ost->swr_dither_scale != 1.0)
av_strlcatf(args, sizeof(args), "dither_scale=%f:", ost->swr_dither_scale);
while ((e = av_dict_get(ost->swr_opts, "", e,
AV_DICT_IGNORE_SUFFIX))) {
av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
}
if (strlen(args))
args[strlen(args)-1] = 0;
av_opt_set(fg->graph, "aresample_swr_opts", args, 0);

@ -1002,11 +1002,10 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
av_opt_get_int(o->g->sws_opts, "sws_flags", 0, &ost->sws_flags);
av_opt_get_int (o->g->swr_opts, "filter_type" , 0, &ost->swr_filter_type);
av_opt_get_int (o->g->swr_opts, "dither_method", 0, &ost->swr_dither_method);
av_opt_get_double(o->g->swr_opts, "dither_scale" , 0, &ost->swr_dither_scale);
av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
ost->swr_dither_scale = ost->swr_dither_scale*256;
av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
av_dict_copy(&ost->resample_opts, o->g->resample_opts, 0);

Loading…
Cancel
Save