comparison apiexample.c @ 2552:9a7770ebed14 libavcodec

AVOption removial patch from (James A. Morrison >ja2morri csclub.uwaterloo ca>) with minor changes from me
author michael
date Sun, 06 Mar 2005 23:20:53 +0000
parents 3d8bbb8e7156
children ef44d24680d1
comparison
equal deleted inserted replaced
2551:615995277bc5 2552:9a7770ebed14
407 av_free(c); 407 av_free(c);
408 av_free(picture); 408 av_free(picture);
409 printf("\n"); 409 printf("\n");
410 } 410 }
411 411
412 // simple example how the options could be used
413 int options_example(int argc, char* argv[])
414 {
415 AVCodec* codec = avcodec_find_encoder_by_name((argc > 1) ? argv[2] : "mpeg4");
416 const AVOption* c;
417 AVCodecContext* avctx;
418 #define DEF_SIZE 5000
419 char* def = av_malloc(DEF_SIZE);
420 const char* col = "";
421 int i = 0;
422
423 if (!codec)
424 return -1;
425 c = codec->options;
426 avctx = avcodec_alloc_context();
427 *def = 0;
428
429 if (c) {
430 const AVOption *stack[FF_OPT_MAX_DEPTH];
431 int depth = 0;
432 for (;;) {
433 if (!c->name) {
434 if (c->help) {
435 stack[depth++] = c;
436 c = (const AVOption*)c->help;
437 } else {
438 if (depth == 0)
439 break; // finished
440 c = stack[--depth];
441 c++;
442 }
443 } else {
444 int t = c->type & FF_OPT_TYPE_MASK;
445 printf("Config %s %s\n",
446 t == FF_OPT_TYPE_BOOL ? "bool " :
447 t == FF_OPT_TYPE_DOUBLE ? "double " :
448 t == FF_OPT_TYPE_INT ? "integer" :
449 t == FF_OPT_TYPE_STRING ? "string " :
450 "unknown??", c->name);
451 switch (t) {
452 case FF_OPT_TYPE_BOOL:
453 i += snprintf(def + i, DEF_SIZE-i, "%s%s=%s",
454 col, c->name,
455 c->defval != 0. ? "on" : "off");
456 break;
457 case FF_OPT_TYPE_DOUBLE:
458 i += snprintf(def + i, DEF_SIZE-i, "%s%s=%f",
459 col, c->name, c->defval);
460 break;
461 case FF_OPT_TYPE_INT:
462 i += snprintf(def + i, DEF_SIZE-i, "%s%s=%d",
463 col, c->name, (int) c->defval);
464 break;
465 case FF_OPT_TYPE_STRING:
466 if (c->defstr) {
467 char* d = av_strdup(c->defstr);
468 char* f = strchr(d, ',');
469 if (f)
470 *f = 0;
471 i += snprintf(def + i, DEF_SIZE-i, "%s%s=%s",
472 col, c->name, d);
473 av_free(d);
474 }
475 break;
476 }
477 col = ":";
478 c++;
479 }
480 }
481 }
482 printf("Default Options: %s\n", def);
483 av_free(def);
484 return 0;
485 }
486
487
488 int main(int argc, char **argv) 412 int main(int argc, char **argv)
489 { 413 {
490 const char *filename; 414 const char *filename;
491 415
492 /* must be called before using avcodec lib */ 416 /* must be called before using avcodec lib */
494 418
495 /* register all the codecs (you can also register only the codec 419 /* register all the codecs (you can also register only the codec
496 you wish to have smaller code */ 420 you wish to have smaller code */
497 avcodec_register_all(); 421 avcodec_register_all();
498 422
499 #ifdef OPT_TEST
500 options_example(argc, argv);
501 #else
502 if (argc <= 1) { 423 if (argc <= 1) {
503 audio_encode_example("/tmp/test.mp2"); 424 audio_encode_example("/tmp/test.mp2");
504 audio_decode_example("/tmp/test.sw", "/tmp/test.mp2"); 425 audio_decode_example("/tmp/test.sw", "/tmp/test.mp2");
505 426
506 video_encode_example("/tmp/test.mpg"); 427 video_encode_example("/tmp/test.mpg");
509 filename = argv[1]; 430 filename = argv[1];
510 } 431 }
511 432
512 // audio_decode_example("/tmp/test.sw", filename); 433 // audio_decode_example("/tmp/test.sw", filename);
513 video_decode_example("/tmp/test%d.pgm", filename); 434 video_decode_example("/tmp/test%d.pgm", filename);
514 #endif
515 435
516 return 0; 436 return 0;
517 } 437 }