Skip to content

Commit

Permalink
Merge commit '5c7db097ebe1fb5c233cedd8846615074e7d6044'
Browse files Browse the repository at this point in the history
* commit '5c7db097ebe1fb5c233cedd8846615074e7d6044':
  avconv: pass libavresample options to AVFilterGraph

Conflicts:
	cmdutils.c
	cmdutils.h
	ffmpeg_filter.c
	ffmpeg_opt.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
  • Loading branch information
michaelni committed Feb 24, 2013
2 parents 71cf094 + 5c7db09 commit 6db37c9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
17 changes: 15 additions & 2 deletions cmdutils.c
Expand Up @@ -63,7 +63,7 @@ static int init_report(const char *env);

struct SwsContext *sws_opts;
SwrContext *swr_opts;
AVDictionary *format_opts, *codec_opts;
AVDictionary *format_opts, *codec_opts, *resample_opts;

const int this_year = 2013;

Expand Down Expand Up @@ -92,6 +92,7 @@ void uninit_opts(void)

av_dict_free(&format_opts);
av_dict_free(&codec_opts);
av_dict_free(&resample_opts);
}

void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Expand Down Expand Up @@ -478,6 +479,7 @@ int opt_default(void *optctx, const char *opt, const char *arg)
char opt_stripped[128];
const char *p;
const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
const av_unused AVClass *rc_class;
const AVClass *sc, *swr_class;

if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
Expand Down Expand Up @@ -526,6 +528,14 @@ int opt_default(void *optctx, const char *opt, const char *arg)
consumed = 1;
}
#endif
#if CONFIG_AVRESAMPLE
rc_class = avresample_get_class();
if (av_opt_find(&rc_class, opt, NULL, 0,
AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) {
av_dict_set(&resample_opts, opt, arg, FLAGS);
consumed = 1;
}
#endif

if (consumed)
return 0;
Expand Down Expand Up @@ -575,9 +585,11 @@ static void finish_group(OptionParseContext *octx, int group_idx,
g->swr_opts = swr_opts;
g->codec_opts = codec_opts;
g->format_opts = format_opts;
g->resample_opts = resample_opts;

codec_opts = NULL;
format_opts = NULL;
resample_opts = NULL;
#if CONFIG_SWSCALE
sws_opts = NULL;
#endif
Expand Down Expand Up @@ -635,6 +647,7 @@ void uninit_parse_context(OptionParseContext *octx)
av_freep(&l->groups[j].opts);
av_dict_free(&l->groups[j].codec_opts);
av_dict_free(&l->groups[j].format_opts);
av_dict_free(&l->groups[j].resample_opts);
#if CONFIG_SWSCALE
sws_freeContext(l->groups[j].sws_opts);
#endif
Expand Down Expand Up @@ -748,7 +761,7 @@ do { \
return AVERROR_OPTION_NOT_FOUND;
}

if (octx->cur_group.nb_opts || codec_opts || format_opts)
if (octx->cur_group.nb_opts || codec_opts || format_opts || resample_opts)
av_log(NULL, AV_LOG_WARNING, "Trailing options were found on the "
"commandline.\n");

Expand Down
3 changes: 2 additions & 1 deletion cmdutils.h
Expand Up @@ -52,7 +52,7 @@ extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
extern AVFormatContext *avformat_opts;
extern struct SwsContext *sws_opts;
extern struct SwrContext *swr_opts;
extern AVDictionary *format_opts, *codec_opts;
extern AVDictionary *format_opts, *codec_opts, *resample_opts;

/**
* Initialize the cmdutils option system, in particular
Expand Down Expand Up @@ -253,6 +253,7 @@ typedef struct OptionGroup {

AVDictionary *codec_opts;
AVDictionary *format_opts;
AVDictionary *resample_opts;
struct SwsContext *sws_opts;
struct SwrContext *swr_opts;
} OptionGroup;
Expand Down
1 change: 1 addition & 0 deletions ffmpeg.c
Expand Up @@ -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->resample_opts);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ffmpeg.h
Expand Up @@ -350,6 +350,7 @@ typedef struct OutputStream {
int64_t swr_dither_method;
double swr_dither_scale;
AVDictionary *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) */
int stream_copy;
Expand Down
15 changes: 14 additions & 1 deletion ffmpeg_filter.c
Expand Up @@ -24,6 +24,8 @@
#include "libavfilter/avfiltergraph.h"
#include "libavfilter/buffersink.h"

#include "libavresample/avresample.h"

#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
Expand Down Expand Up @@ -730,7 +732,9 @@ int configure_filtergraph(FilterGraph *fg)

if (simple) {
OutputStream *ost = fg->outputs[0]->ost;
char args[255];
char args[512];
AVDictionaryEntry *e = NULL;

snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
fg->graph->scale_sws_opts = av_strdup(args);

Expand All @@ -744,6 +748,15 @@ int configure_filtergraph(FilterGraph *fg)
if (strlen(args))
args[strlen(args)-1] = 0;
av_opt_set(fg->graph, "aresample_swr_opts", args, 0);

args[0] = '\0';
while ((e = av_dict_get(fg->outputs[0]->ost->resample_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';
fg->graph->resample_lavr_opts = av_strdup(args);
}

if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
Expand Down
2 changes: 2 additions & 0 deletions ffmpeg_opt.c
Expand Up @@ -1008,6 +1008,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
ost->swr_dither_scale = ost->swr_dither_scale*256;

av_dict_copy(&ost->resample_opts, o->g->resample_opts, 0);

ost->source_index = source_index;
if (source_index >= 0) {
ost->sync_ist = input_streams[source_index];
Expand Down

0 comments on commit 6db37c9

Please sign in to comment.