- switch(err) {
- case AVERROR_NUMEXPECTED:
- fprintf(stderr, "%s: Incorrect image filename syntax.\n"
- "Use '%%d' to specify the image number:\n"
- " for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
- " for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
- filename);
- break;
- case AVERROR_INVALIDDATA:
- fprintf(stderr, "%s: Error while parsing header\n", filename);
- break;
- case AVERROR_NOFMT:
- fprintf(stderr, "%s: Unknown format\n", filename);
- break;
- case AVERROR(EIO):
- fprintf(stderr, "%s: I/O error occured\n"
- "Usually that means that input file is truncated and/or corrupted.\n",
- filename);
- break;
- case AVERROR(ENOMEM):
- fprintf(stderr, "%s: memory allocation error occured\n", filename);
- break;
- case AVERROR(ENOENT):
- fprintf(stderr, "%s: no such file or directory\n", filename);
- break;
- default:
- fprintf(stderr, "%s: Error while opening file\n", filename);
- break;
- }
-}
-
-void show_banner(const char *program_name, int program_birth_year)
-{
- fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-2008 Fabrice Bellard, et al.\n",
- program_name, program_birth_year);
- fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n");
- fprintf(stderr, " libavutil version: " AV_STRINGIFY(LIBAVUTIL_VERSION) "\n");
- fprintf(stderr, " libavcodec version: " AV_STRINGIFY(LIBAVCODEC_VERSION) "\n");
- fprintf(stderr, " libavformat version: " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\n");
- fprintf(stderr, " libavdevice version: " AV_STRINGIFY(LIBAVDEVICE_VERSION) "\n");
- fprintf(stderr, " built on " __DATE__ " " __TIME__);
-#ifdef __GNUC__
- fprintf(stderr, ", gcc: " __VERSION__ "\n");
+ const AVOption *o;
+ if ((o = av_opt_find(avcodec_opts[0], opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) {
+ if (o->flags & AV_OPT_FLAG_VIDEO_PARAM)
+ av_dict_set(&video_opts, opt, arg, FLAGS);
+ if (o->flags & AV_OPT_FLAG_AUDIO_PARAM)
+ av_dict_set(&audio_opts, opt, arg, FLAGS);
+ if (o->flags & AV_OPT_FLAG_SUBTITLE_PARAM)
+ av_dict_set(&sub_opts, opt, arg, FLAGS);
+ } else if ((o = av_opt_find(avformat_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN)))
+ av_dict_set(&format_opts, opt, arg, FLAGS);
+ else if ((o = av_opt_find(sws_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) {
+ // XXX we only support sws_flags, not arbitrary sws options
+ int ret = av_set_string3(sws_opts, opt, arg, 1, NULL);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
+ return ret;
+ }
+ }
+
+ if (!o) {
+ SET_PREFIXED_OPTS('v', AV_OPT_FLAG_VIDEO_PARAM, video_opts)
+ SET_PREFIXED_OPTS('a', AV_OPT_FLAG_AUDIO_PARAM, audio_opts)
+ SET_PREFIXED_OPTS('s', AV_OPT_FLAG_SUBTITLE_PARAM, sub_opts)
+ }
+
+ if (o)
+ return 0;
+ fprintf(stderr, "Unrecognized option '%s'\n", opt);
+ return AVERROR_OPTION_NOT_FOUND;
+}
+
+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; *avcodec_opts && type<AVMEDIA_TYPE_NB && ret>= 0; type++){
+ const AVOption *o2 = av_opt_find(avcodec_opts[0], opt, NULL, opt_types[type], 0);
+ if(o2)
+ ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o);
+ }
+ if(!o && avformat_opts)
+ ret = av_set_string3(avformat_opts, opt, arg, 1, &o);
+ if(!o && sws_opts)
+ ret = av_set_string3(sws_opts, opt, arg, 1, &o);
+ if(!o){
+ if (opt[0] == 'a' && avcodec_opts[AVMEDIA_TYPE_AUDIO])
+ ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_AUDIO], opt+1, arg, 1, &o);
+ else if(opt[0] == 'v' && avcodec_opts[AVMEDIA_TYPE_VIDEO])
+ ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_VIDEO], opt+1, arg, 1, &o);
+ else if(opt[0] == 's' && avcodec_opts[AVMEDIA_TYPE_SUBTITLE])
+ ret = av_set_string3(avcodec_opts[AVMEDIA_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) {
+ AVCodec *p = NULL;
+ AVOutputFormat *oformat = NULL;
+ while ((p=av_codec_next(p))){
+ const AVClass *c = p->priv_class;
+ if(c && av_opt_find(&c, opt, NULL, 0, 0))
+ break;
+ }
+ if (!p) {
+ while ((oformat = av_oformat_next(oformat))) {
+ const AVClass *c = oformat->priv_class;
+ if (c && av_opt_find(&c, opt, NULL, 0, 0))
+ break;
+ }
+ }
+ }
+
+ if ((ret = opt_default2(opt, arg)) < 0)
+ return ret;
+
+// 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_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1));
+ opt_values[opt_name_count]= o ? NULL : av_strdup(arg);
+ opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
+ opt_names[opt_name_count++]= o ? o->name : av_strdup(opt);
+
+ if ((*avcodec_opts && avcodec_opts[0]->debug) || (avformat_opts && 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;
+}
+
+int opt_timelimit(const char *opt, const char *arg)
+{
+#if HAVE_SETRLIMIT
+ int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
+ struct rlimit rl = { lim, lim + 1 };
+ if (setrlimit(RLIMIT_CPU, &rl))
+ perror("setrlimit");