diff --git a/libavcodec/opt.c b/libavcodec/opt.c index 0bdef5c984aeabffa248e483e1215e855f3b6e68..84ea19117d0641eee98430b062afcb0e855c2bb4 100644 --- a/libavcodec/opt.c +++ b/libavcodec/opt.c @@ -299,3 +299,40 @@ int av_opt_show(void *obj, void *av_log_obj){ } return 0; } + +void av_opt_set_defaults(void *s) +{ + AVOption *opt = NULL; + while ((opt = av_next_option(s, opt)) != NULL) { + switch(opt->type) { + case FF_OPT_TYPE_CONST: + /* Nothing to be done here */ + break; + case FF_OPT_TYPE_FLAGS: + case FF_OPT_TYPE_INT: { + int val; + val = opt->default_val; + av_set_int(s, opt->name, val); + } + break; + case FF_OPT_TYPE_FLOAT: { + double val; + val = opt->default_val; + av_set_double(s, opt->name, val); + } + break; + case FF_OPT_TYPE_RATIONAL: { + AVRational val; + val = av_d2q(opt->default_val, INT_MAX); + av_set_q(s, opt->name, val); + } + break; + case FF_OPT_TYPE_STRING: + /* Cannot set default for string as default_val is of type * double */ + break; + default: + av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name); + } + } +} + diff --git a/libavcodec/opt.h b/libavcodec/opt.h index 92a4535ecf08dafa7c61589a3f63e8dae5edca29..e7be7b54f41e292e1334ab08c3e3cf5220be5602 100644 --- a/libavcodec/opt.h +++ b/libavcodec/opt.h @@ -76,5 +76,6 @@ int64_t av_get_int(void *obj, const char *name, AVOption **o_out); const char *av_get_string(void *obj, const char *name, AVOption **o_out, char *buf, int buf_len); AVOption *av_next_option(void *obj, AVOption *last); int av_opt_show(void *obj, void *av_log_obj); +void av_opt_set_defaults(void *s); #endif diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 0e59852eaefb530feb662bc6c1fdb007b74c4945..5aba3dac8a2be789c70686b92cf930fabda1cdfd 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -765,6 +765,9 @@ void avcodec_get_context_defaults(AVCodecContext *s){ memset(s, 0, sizeof(AVCodecContext)); s->av_class= &av_codec_context_class; + + av_opt_set_defaults(s); + s->bit_rate= 800*1000; s->bit_rate_tolerance= s->bit_rate*10; s->qmin= 2; diff --git a/libavformat/utils.c b/libavformat/utils.c index d9b57897dc83e5ca5189c18696bc2ceac06a6c8f..a9adb2b3f466f38396256649eaa7e0c661911836 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -486,6 +486,10 @@ static void avformat_get_context_defaults(AVFormatContext *s){ memset(s, 0, sizeof(AVFormatContext)); + s->av_class = &av_format_context_class; + + av_opt_set_defaults(s); + /* from mpegts.c: 1.0 second at 24Mbit/s */ s->probesize=32000; }