8 * typical parsed command line:
9 * msmpeg4:bitrate=720000:qmax=16
15 extern const AVOption common_options[2];
17 const AVOption common_options[2] = {
18 AVOPTION_CODEC_INT("common", "test", bit_rate, 0, 10, 0),
22 static int parse_bool(const AVOption *c, char *s, int *var)
24 int b = 1; /* by default -on- when present */
26 if (!strcasecmp(s, "off") || !strcasecmp(s, "false")
29 else if (!strcasecmp(s, "on") || !strcasecmp(s, "true")
40 static int parse_double(const AVOption *c, char *s, double *var)
46 if (c->min != c->max) {
47 if (d < c->min || d > c->max) {
48 fprintf(stderr, "Option: %s double value: %f out of range <%f, %f>\n",
49 c->name, d, c->min, c->max);
57 static int parse_int(const AVOption* c, char* s, int* var)
63 if (c->min != c->max) {
64 if (i < (int)c->min || i > (int)c->max) {
65 fprintf(stderr, "Option: %s integer value: %d out of range <%d, %d>\n",
66 c->name, i, (int)c->min, (int)c->max);
74 static int parse_string(const AVOption *c, char *s, AVCodecContext *avctx, char **var)
79 if (c->type == FF_OPT_TYPE_RCOVERRIDE) {
82 if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) {
84 avctx->rc_override = av_realloc(avctx->rc_override,
85 sizeof(RcOverride) * (avctx->rc_override_count + 1));
86 o = avctx->rc_override + avctx->rc_override_count++;
90 o->quality_factor = qf;
92 //printf("parsed Rc: %d,%d,%d,%f (%d)\n", sf,ef,qs,qf, avctx->rc_override_count);
94 printf("incorrect/unparsable Rc: \"%s\"\n", s);
103 * \param codec codec for option parsing
104 * \param opts string with options for parsing
105 * \param avctx where to store parsed results
107 int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx)
110 char* dopts = av_strdup(opts);
114 while (str && *str && r == 0) {
115 const AVOption *stack[FF_OPT_MAX_DEPTH];
117 const AVOption *c = codec->options;
118 char* e = strchr(str, ':');
123 p = strchr(str, '=');
127 // going through option structures
133 assert(depth > FF_OPT_MAX_DEPTH);
141 if (!strcmp(c->name, str)) {
142 void* ptr = (char*)avctx + c->offset;
144 switch (c->type & FF_OPT_TYPE_MASK) {
145 case FF_OPT_TYPE_BOOL:
146 r = parse_bool(c, p, (int*)ptr);
148 case FF_OPT_TYPE_DOUBLE:
149 r = parse_double(c, p, (double*)ptr);
151 case FF_OPT_TYPE_INT:
152 r = parse_int(c, p, (int*)ptr);
154 case FF_OPT_TYPE_STRING:
155 r = parse_string(c, p, avctx, (char**)ptr);