Mercurial > libavcodec.hg
diff apiexample.c @ 1059:890b9fb44e84 libavcodec
* still unfinished code for Options
* demo code - awating more comments
author | kabi |
---|---|
date | Mon, 10 Feb 2003 09:40:23 +0000 |
parents | 7fccaa0d699d |
children | b32afefe7d33 |
line wrap: on
line diff
--- a/apiexample.c Mon Feb 10 09:38:38 2003 +0000 +++ b/apiexample.c Mon Feb 10 09:40:23 2003 +0000 @@ -9,6 +9,10 @@ #include <string.h> #include <math.h> +#ifdef HAVE_AV_CONFIG_H +#undef HAVE_AV_CONFIG_H +#endif + #include "avcodec.h" #define INBUF_SIZE 4096 @@ -385,6 +389,80 @@ printf("\n"); } +// simple example how the options could be used +int options_example(int argc, char* argv[]) +{ + AVCodec* codec = avcodec_find_encoder_by_name((argc > 1) ? argv[2] : "mpeg4"); + const AVOption* c; + AVCodecContext* avctx; + char* def = av_malloc(5000); + const char* col = ""; + int i = 0; + + if (!codec) + return -1; + c = codec->options; + avctx = avcodec_alloc_context(); + *def = 0; + + if (c) { + const AVOption *stack[FF_OPT_MAX_DEPTH]; + int depth = 0; + for (;;) { + if (!c->name) { + if (c->sub) { + stack[depth++] = c; + c = c->sub; + } else { + if (depth == 0) + break; // finished + c = stack[--depth]; + c++; + } + } else { + int t = c->type & FF_OPT_TYPE_MASK; + printf("Config %s %s\n", + t == FF_OPT_TYPE_BOOL ? "bool " : + t == FF_OPT_TYPE_DOUBLE ? "double " : + t == FF_OPT_TYPE_INT ? "integer" : + t == FF_OPT_TYPE_STRING ? "string " : + "unknown??", c->name); + switch (t) { + case FF_OPT_TYPE_BOOL: + i += sprintf(def + i, "%s%s=%s", + col, c->name, + c->defval != 0. ? "on" : "off"); + break; + case FF_OPT_TYPE_DOUBLE: + i += sprintf(def + i, "%s%s=%f", + col, c->name, c->defval); + break; + case FF_OPT_TYPE_INT: + i += sprintf(def + i, "%s%s=%d", + col, c->name, (int) c->defval); + break; + case FF_OPT_TYPE_STRING: + if (c->defstr) { + char* d = av_strdup(c->defstr); + char* f = strchr(d, ','); + if (f) + *f = 0; + i += sprintf(def + i, "%s%s=%s", + col, c->name, d); + av_free(d); + } + break; + } + col = ":"; + c++; + } + } + } + printf("Default Options: %s\n", def); + av_free(def); + return 0; +} + int main(int argc, char **argv) { @@ -396,7 +474,10 @@ /* register all the codecs (you can also register only the codec you wish to have smaller code */ avcodec_register_all(); - + +#ifdef OPT_TEST + options_example(argc, argv); +#else if (argc <= 1) { audio_encode_example("/tmp/test.mp2"); audio_decode_example("/tmp/test.sw", "/tmp/test.mp2"); @@ -409,6 +490,7 @@ // audio_decode_example("/tmp/test.sw", filename); video_decode_example("/tmp/test%d.pgm", filename); +#endif return 0; }