Add a switch which controls which operation to perform. Useful to test only a single feature. Also the new behavior is more self-consistent.
Showing the changes to doc/examples/decoding_encoding.c (1 of 1 file). Show all
Unified · Split
| @@ -600,24 +600,33 @@ static void video_decode_example(const char *outfilename, const char *filename) · 599 unmodified lines | |||
| 600 | 600 | ||
| 601 | int main(int argc, char **argv) | 601 | int main(int argc, char **argv) |
| 602 | { | 602 | { |
| 603 | const char *filename; | 603 | const char *output_type; |
| 604 | 604 | ||
| 605 | /* register all the codecs */ | 605 | /* register all the codecs */ |
| 606 | avcodec_register_all(); | 606 | avcodec_register_all(); |
| 607 | 607 | ||
| 608 | if (argc <= 1) { | 608 | if (argc < 2) { |
| 609 | audio_encode_example("test.mp2"); | 609 | printf("usage: %s output_type\n" |
| 610 | audio_decode_example("test.sw", "test.mp2"); | 610 | "API example program to decode/encode a media stream with libavcodec.\n" |
| 611 | "output_type must be choosen between 'h264', 'mp2', 'mpg'\n", | ||
| 612 | argv[0]); | ||
| 613 | return 1; | ||
| 614 | } | ||
| 615 | output_type = argv[1]; | ||
| 611 | 616 | ||
| 617 | if (!strcmp(output_type, "h264")) { | ||
| 612 | video_encode_example("test.h264", AV_CODEC_ID_H264); | 618 | video_encode_example("test.h264", AV_CODEC_ID_H264); |
| 619 | } else if (!strcmp(output_type, "mp2")) { | ||
| 620 | audio_encode_example("test.mp2"); | ||
| 621 | audio_decode_example("test.sw", "test.mp2"); | ||
| 622 | } else if (!strcmp(output_type, "mpg")) { | ||
| 613 | video_encode_example("test.mpg", AV_CODEC_ID_MPEG1VIDEO); | 623 | video_encode_example("test.mpg", AV_CODEC_ID_MPEG1VIDEO); |
| 614 | filename = "test.mpg"; | 624 | video_decode_example("test%02d.pgm", "test.mpg"); |
| 615 | } else { | 625 | } else { |
| 616 | filename = argv[1]; | 626 | fprintf(stderr, "Invalid output type '%s', choose between 'h264', 'mp2', or 'mpg'\n", |
| 627 | output_type); | ||
| 628 | return 1; | ||
| 617 | } | 629 | } |
| 618 | 630 | ||
| 619 | // audio_decode_example("test.sw", filename); | ||
| 620 | video_decode_example("test%02d.pgm", filename); | ||
| 621 | |||
| 622 | return 0; | 631 | return 0; |
| 623 | } | 632 | } |