6 * typical parsed command line:
7 * msmpeg4:bitrate=720000:qmax=16
19 * todo - use for decoder options also
22 static int parse_bool(avc_config_t* c, char* s)
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")
41 static int parse_double(avc_config_t* c, char* s)
47 if (c->min != c->max) {
48 if (d < c->min || d > c->max) {
49 fprintf(stderr, "Option: %s double value: %f out of range <%f, %f>\n",
50 c->name, d, c->min, c->max);
55 *(double*)(c->val) = d;
59 static int parse_int(avc_config_t* c, char* s)
65 if (c->min != c->max) {
66 if (i < (int)c->min || i > (int)c->max) {
67 fprintf(stderr, "Option: %s integer value: %d out of range <%d, %d>\n",
68 c->name, i, (int)c->min, (int)c->max);
77 static int parse_string(AVCodecContext* avctx, avc_config_t* c, char* s)
82 if (c->type == FF_CONF_TYPE_RCOVERIDE) {
85 if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) {
87 *((RcOverride**)c->val) =
88 realloc(*((RcOverride**)c->val),
89 sizeof(RcOverride) * (avctx->rc_override_count + 1));
90 o = *((RcOverride**)c->val) + avctx->rc_override_count++;
94 o->quality_factor = qf;
96 //printf("parsed Rc: %d,%d,%d,%f (%d)\n", sf,ef,qs,qf, avctx->rc_override_count);
98 printf("incorrect/unparsable Rc: \"%s\"\n", s);
101 (char*)(c->val) = strdup(s);
105 static int parse(AVCodecContext* avctx, avc_config_t* config, char* str)
107 while (str && *str) {
108 avc_config_t* c = config;
109 char* e = strchr(str, ':');
114 p = strchr(str, '=');
119 if (!strcmp(c->name, str)) {
120 switch (c->type & FF_CONF_TYPE_MASK) {
121 case FF_CONF_TYPE_BOOL:
124 case FF_CONF_TYPE_DOUBLE:
127 case FF_CONF_TYPE_INT:
130 case FF_CONF_TYPE_STRING:
131 parse_string(avctx, c, p);
147 * \param avctx where to store parsed results
148 * \param str string with options for parsing
149 * or selectional string (pick only options appliable
150 * for codec - use ,msmpeg4, (with commas to avoid mismatch)
151 * \param config allocated avc_config_t for external parsing
152 * i.e. external program might learn about all available
153 * options for given codec
155 void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config)
157 AVCodecContext avctx_tmp;
158 AVCodecContext* ctx = (avctx) ? avctx : &avctx_tmp;
159 static const char* class_h263 = ",msmpeg4,";
160 //"huffyuv,wmv1,msmpeg4v2,msmpeg4,mpeg4,mpeg1,mpeg1video,mjpeg,rv10,h263,h263p"
164 // FIXME: sorted by importance!!!
165 // expert option should follow more common ones
167 "bitrate", "desired video bitrate",
168 FF_CONF_TYPE_INT, &ctx->bit_rate, 4, 240000000, 800000, NULL, class_h263
170 "vhq", "very high quality",
171 FF_CONF_TYPE_FLAG, &ctx->flags, 0, CODEC_FLAG_HQ, 0, NULL, class_h263
173 "ratetol", "number of bits the bitstream is allowed to diverge from the reference"
174 "the reference can be CBR (for CBR pass1) or VBR (for pass2)",
175 FF_CONF_TYPE_INT, &ctx->bit_rate_tolerance, 4, 240000000, 8000, NULL, class_h263
177 "qmin", "minimum quantizer", FF_CONF_TYPE_INT, &ctx->qmin, 1, 31, 2, NULL, class_h263
179 "qmax", "maximum qunatizer", FF_CONF_TYPE_INT, &ctx->qmax, 1, 31, 31, NULL, class_h263
181 "rc_eq", "rate control equation",
182 FF_CONF_TYPE_STRING, &ctx->rc_eq, 0, 0, 0, "tex^qComp" /* FILLME options */, class_h263
184 "rc_minrate", "rate control minimum bitrate",
185 FF_CONF_TYPE_INT, &ctx->rc_min_rate, 4, 24000000, 0, NULL, class_h263
187 "rc_maxrate", "rate control maximum bitrate",
188 FF_CONF_TYPE_INT, &ctx->rc_max_rate, 4, 24000000, 0, NULL, class_h263
190 "psnr", "calculate PSNR of compressed frames",
191 FF_CONF_TYPE_FLAG, &ctx->flags, 0, CODEC_FLAG_PSNR, 0, NULL, class_h263
193 "rc_override", "ratecontrol override (=startframe,endframe,qscale,quality_factor)",
194 FF_CONF_TYPE_RCOVERIDE, &ctx->rc_override, 0, 0, 0, "0,0,0,0", class_h263
197 { NULL, NULL, 0, NULL, 0, 0, 0, NULL, NULL }
201 *config = malloc(sizeof(cnf));
203 avc_config_t* src = cnf;
204 avc_config_t* dst = *config;
206 if (!str || !src->supported || strstr(src->supported, str))
207 memcpy(dst++, src, sizeof(avc_config_t));
210 memset(dst, 0, sizeof(avc_config_t));
213 char* s = strdup(str);
215 parse(avctx, cnf, s);
227 * compile standalone: make CFLAGS="-DOPTS_MAIN" opts
229 int main(int argc, char* argv[])
231 AVCodecContext avctx;
232 avc_config_t* config;
233 char* def = malloc(5000);
234 const char* col = "";
237 memset(&avctx, 0, sizeof(avctx));
239 avcodec_getopt(&avctx, argv[1], NULL);
241 avcodec_getopt(NULL, (argc > 2) ? argv[2] : NULL, &config);
243 while (config->name) {
244 int t = config->type & FF_CONF_TYPE_MASK;
245 printf("Config %s %s\n", config->name,
246 t == FF_CONF_TYPE_BOOL ? "bool" :
247 t == FF_CONF_TYPE_DOUBLE ? "double" :
248 t == FF_CONF_TYPE_INT ? "integer" :
249 t == FF_CONF_TYPE_STRING ? "string" :
252 case FF_CONF_TYPE_BOOL:
253 i += sprintf(def + i, "%s%s=%s",
255 config->defval != 0. ? "on" : "off");
257 case FF_CONF_TYPE_DOUBLE:
258 i += sprintf(def + i, "%s%s=%f",
259 col, config->name, config->defval);
261 case FF_CONF_TYPE_INT:
262 i += sprintf(def + i, "%s%s=%d",
263 col, config->name, (int) config->defval);
265 case FF_CONF_TYPE_STRING:
266 i += sprintf(def + i, "%s%s=%s",
267 col, config->name, config->defstr);
274 printf("Default Options: %s\n", def);