Revision 40c5fa26 libavcodec/apiexample.c

View differences:

libavcodec/apiexample.c
409 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 412
int main(int argc, char **argv)
489 413
{
490 414
    const char *filename;
......
496 420
       you wish to have smaller code */
497 421
    avcodec_register_all();
498 422

  
499
#ifdef OPT_TEST
500
    options_example(argc, argv);
501
#else
502 423
    if (argc <= 1) {
503 424
        audio_encode_example("/tmp/test.mp2");
504 425
        audio_decode_example("/tmp/test.sw", "/tmp/test.mp2");
......
511 432

  
512 433
    //    audio_decode_example("/tmp/test.sw", filename);
513 434
    video_decode_example("/tmp/test%d.pgm", filename);
514
#endif
515 435

  
516 436
    return 0;
517 437
}

Also available in: Unified diff