+int opt_default(const char *opt, const char *arg){
+ int type;
+ int ret= 0;
+ const AVOption *o= NULL;
+ int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0};
+
+ for(type=0; type<CODEC_TYPE_NB && ret>= 0; type++){
+ const AVOption *o2 = av_find_opt(avcodec_opts[0], opt, NULL, opt_types[type], opt_types[type]);
+ if(o2)
+ ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o);
+ }
+ if(!o)
+ ret = av_set_string3(avformat_opts, opt, arg, 1, &o);
+ if(!o)
+ ret = av_set_string3(sws_opts, opt, arg, 1, &o);
+ if(!o){
+ if(opt[0] == 'a')
+ ret = av_set_string3(avcodec_opts[CODEC_TYPE_AUDIO], opt+1, arg, 1, &o);
+ else if(opt[0] == 'v')
+ ret = av_set_string3(avcodec_opts[CODEC_TYPE_VIDEO], opt+1, arg, 1, &o);
+ else if(opt[0] == 's')
+ ret = av_set_string3(avcodec_opts[CODEC_TYPE_SUBTITLE], opt+1, arg, 1, &o);
+ }
+ if (o && ret < 0) {
+ fprintf(stderr, "Invalid value '%s' for option '%s'\n", arg, opt);
+ exit(1);
+ }
+ if(!o)
+ return -1;
+
+// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avcodec_opts, opt, NULL), (int)av_get_int(avcodec_opts, opt, NULL));
+
+ //FIXME we should always use avcodec_opts, ... for storing options so there will not be any need to keep track of what i set over this
+ opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
+ opt_names[opt_name_count++]= o->name;
+
+ if(avcodec_opts[0]->debug || avformat_opts->debug)
+ av_log_set_level(AV_LOG_DEBUG);
+ return 0;
+}
+
+int opt_loglevel(const char *opt, const char *arg)
+{
+ const struct { const char *name; int level; } log_levels[] = {
+ { "quiet" , AV_LOG_QUIET },
+ { "panic" , AV_LOG_PANIC },
+ { "fatal" , AV_LOG_FATAL },
+ { "error" , AV_LOG_ERROR },
+ { "warning", AV_LOG_WARNING },
+ { "info" , AV_LOG_INFO },
+ { "verbose", AV_LOG_VERBOSE },
+ { "debug" , AV_LOG_DEBUG },
+ };
+ char *tail;
+ int level;
+ int i;
+
+ for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
+ if (!strcmp(log_levels[i].name, arg)) {
+ av_log_set_level(log_levels[i].level);
+ return 0;
+ }
+ }
+
+ level = strtol(arg, &tail, 10);
+ if (*tail) {
+ fprintf(stderr, "Invalid loglevel \"%s\". "
+ "Possible levels are numbers or:\n", arg);
+ for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
+ fprintf(stderr, "\"%s\"\n", log_levels[i].name);
+ exit(1);
+ }
+ av_log_set_level(level);
+ return 0;
+}
+
+void set_context_opts(void *ctx, void *opts_ctx, int flags)
+{
+ int i;
+ for(i=0; i<opt_name_count; i++){
+ char buf[256];
+ const AVOption *opt;
+ const char *str= av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
+ /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */
+ if(str && ((opt->flags & flags) == flags))
+ av_set_string3(ctx, opt_names[i], str, 1, NULL);
+ }
+}
+