[FFmpeg-devel] [PATCH] lavf/riff: add riff-test program

Stefano Sabatini stefasab at gmail.com
Fri Sep 7 00:18:37 CEST 2012


This test program is very simialar to libavcodec/raw-test, and is useful
to test the mapping between codec fourccs and codec IDs.
---
 libavformat/Makefile |    2 +-
 libavformat/riff.c   |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletions(-)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 72f9c22..681f507 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -405,7 +405,7 @@ OBJS-$(CONFIG_UDP_PROTOCOL)              += udp.o
 
 SKIPHEADERS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpdh.h
 SKIPHEADERS-$(CONFIG_NETWORK)            += network.h rtsp.h
-TESTPROGS = seek
+TESTPROGS = riff seek
 
 TOOLS     = aviocat                                                     \
             ismindex                                                    \
diff --git a/libavformat/riff.c b/libavformat/riff.c
index 9ff2148..3400041 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -794,3 +794,97 @@ int ff_read_riff_info(AVFormatContext *s, int64_t size)
 
     return 0;
 }
+
+#ifdef TEST
+
+#include <unistd.h>             /* getopt */
+#include "libavutil/pixdesc.h"
+
+#undef printf
+#undef fprintf
+
+static void usage(void)
+{
+    printf("\n"
+           "Options:\n"
+           "-c CODEC_NAME     given a codec name, print the list of associated fourccs (one per line)\n"
+           "-l                list the codec name for each fourcc\n"
+           "-L                list the fourccs for each codec\n"
+           "-h                print this help\n");
+}
+
+static void print_codec_fourccs(enum AVCodecID codec_id, char sep)
+{
+    int i;
+
+    for (i = 0; i < FF_ARRAY_ELEMS(ff_codec_bmp_tags); i++) {
+        if (ff_codec_bmp_tags[i].id == codec_id) {
+            char buf[32];
+            av_get_codec_tag_string(buf, sizeof(buf), ff_codec_bmp_tags[i].tag);
+            printf("%s%c", buf, sep);
+        }
+    }
+}
+
+int main(int argc, char **argv)
+{
+    int i, list_fourcc_codec = 0, list_codec_fourccs = 0;
+    const char *codec_name = NULL;
+    char c;
+
+    if (argc == 1) {
+        usage();
+        return 0;
+    }
+
+    while ((c = getopt(argc, argv, "c:hlL")) != -1) {
+        switch (c) {
+        case 'h':
+            usage();
+            return 0;
+        case 'l':
+            list_fourcc_codec = 1;
+            break;
+        case 'L':
+            list_codec_fourccs = 1;
+            break;
+        case 'c':
+            codec_name = optarg;
+            break;
+        case '?':
+            usage();
+            return 1;
+        }
+    }
+
+    if (list_fourcc_codec) {
+        for (i = 0; i < FF_ARRAY_ELEMS(ff_codec_bmp_tags); i++) {
+            char buf[32];
+            av_get_codec_tag_string(buf, sizeof(buf), ff_codec_bmp_tags[i].tag);
+            if (ff_codec_bmp_tags[i].id != AV_CODEC_ID_NONE)
+                printf("%s: %s\n", buf, avcodec_get_name(ff_codec_bmp_tags[i].id));
+        }
+    }
+
+    if (list_codec_fourccs) {
+        const AVCodecDescriptor *desc = avcodec_descriptor_next(NULL);
+        while (desc) {
+            printf("%s: ", desc->name);
+            print_codec_fourccs(desc->id, ' ');
+            printf("\n");
+            desc = avcodec_descriptor_next(desc);
+        }
+    }
+
+    if (codec_name) {
+        const AVCodecDescriptor *desc = avcodec_descriptor_get_by_name(codec_name);
+        if (!desc) {
+            fprintf(stderr, "Unknown codec selected '%s'\n", codec_name);
+            return 1;
+        }
+        print_codec_fourccs(desc->id, '\n');
+    }
+
+    return 0;
+}
+#endif // TEST
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list