00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "config.h"
00022 #if HAVE_UNISTD_H
00023 #include <unistd.h>
00024 #endif
00025
00026 #include "libavutil/pixdesc.h"
00027 #include "libavcodec/avcodec.h"
00028 #include "libavutil/common.h"
00029 #include "libavcodec/raw.h"
00030
00031 #if !HAVE_GETOPT
00032 #include "compat/getopt.c"
00033 #endif
00034
00035 static void usage(void)
00036 {
00037 printf("Show the relationships between rawvideo pixel formats and FourCC tags.\n");
00038 printf("usage: fourcc2pixfmt [OPTIONS]\n");
00039 printf("\n"
00040 "Options:\n"
00041 "-l list the pixel format for each fourcc\n"
00042 "-L list the fourccs for each pixel format\n"
00043 "-p PIX_FMT given a pixel format, print the list of associated fourccs (one per line)\n"
00044 "-h print this help\n");
00045 }
00046
00047 static void print_pix_fmt_fourccs(enum PixelFormat pix_fmt, char sep)
00048 {
00049 int i;
00050
00051 for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != PIX_FMT_NONE; i++) {
00052 if (ff_raw_pix_fmt_tags[i].pix_fmt == pix_fmt) {
00053 char buf[32];
00054 av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
00055 printf("%s%c", buf, sep);
00056 }
00057 }
00058 }
00059
00060 int main(int argc, char **argv)
00061 {
00062 int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
00063 const char *pix_fmt_name = NULL;
00064 char c;
00065
00066 if (argc == 1) {
00067 usage();
00068 return 0;
00069 }
00070
00071 while ((c = getopt(argc, argv, "hp:lL")) != -1) {
00072 switch (c) {
00073 case 'h':
00074 usage();
00075 return 0;
00076 case 'l':
00077 list_fourcc_pix_fmt = 1;
00078 break;
00079 case 'L':
00080 list_pix_fmt_fourccs = 1;
00081 break;
00082 case 'p':
00083 pix_fmt_name = optarg;
00084 break;
00085 case '?':
00086 usage();
00087 return 1;
00088 }
00089 }
00090
00091 if (list_fourcc_pix_fmt) {
00092 for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != PIX_FMT_NONE; i++) {
00093 char buf[32];
00094 av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
00095 printf("%s: %s\n", buf, av_get_pix_fmt_name(ff_raw_pix_fmt_tags[i].pix_fmt));
00096 }
00097 }
00098
00099 if (list_pix_fmt_fourccs) {
00100 for (i = 0; i < PIX_FMT_NB; i++) {
00101 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[i];
00102 if (!pix_desc->name || pix_desc->flags & PIX_FMT_HWACCEL)
00103 continue;
00104 printf("%s: ", pix_desc->name);
00105 print_pix_fmt_fourccs(i, ' ');
00106 printf("\n");
00107 }
00108 }
00109
00110 if (pix_fmt_name) {
00111 enum PixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
00112 if (pix_fmt == PIX_FMT_NONE) {
00113 fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
00114 return 1;
00115 }
00116 print_pix_fmt_fourccs(pix_fmt, '\n');
00117 }
00118
00119 return 0;
00120 }