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 #undef printf
00032 #undef fprintf
00033
00034 #if !HAVE_GETOPT
00035 #include "compat/getopt.c"
00036 #endif
00037
00038 static void usage(void)
00039 {
00040 printf("Show the relationships between rawvideo pixel formats and FourCC tags.\n");
00041 printf("usage: fourcc2pixfmt [OPTIONS]\n");
00042 printf("\n"
00043 "Options:\n"
00044 "-l list the pixel format for each fourcc\n"
00045 "-L list the fourccs for each pixel format\n"
00046 "-p PIX_FMT given a pixel format, print the list of associated fourccs (one per line)\n"
00047 "-h print this help\n");
00048 }
00049
00050 static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, char sep)
00051 {
00052 int i;
00053
00054 for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
00055 if (ff_raw_pix_fmt_tags[i].pix_fmt == pix_fmt) {
00056 char buf[32];
00057 av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
00058 printf("%s%c", buf, sep);
00059 }
00060 }
00061 }
00062
00063 int main(int argc, char **argv)
00064 {
00065 int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
00066 const char *pix_fmt_name = NULL;
00067 char c;
00068
00069 if (argc == 1) {
00070 usage();
00071 return 0;
00072 }
00073
00074 while ((c = getopt(argc, argv, "hp:lL")) != -1) {
00075 switch (c) {
00076 case 'h':
00077 usage();
00078 return 0;
00079 case 'l':
00080 list_fourcc_pix_fmt = 1;
00081 break;
00082 case 'L':
00083 list_pix_fmt_fourccs = 1;
00084 break;
00085 case 'p':
00086 pix_fmt_name = optarg;
00087 break;
00088 case '?':
00089 usage();
00090 return 1;
00091 }
00092 }
00093
00094 if (list_fourcc_pix_fmt) {
00095 for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
00096 char buf[32];
00097 av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
00098 printf("%s: %s\n", buf, av_get_pix_fmt_name(ff_raw_pix_fmt_tags[i].pix_fmt));
00099 }
00100 }
00101
00102 if (list_pix_fmt_fourccs) {
00103 for (i = 0; i < AV_PIX_FMT_NB; i++) {
00104 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(i);
00105 if (!pix_desc->name || pix_desc->flags & PIX_FMT_HWACCEL)
00106 continue;
00107 printf("%s: ", pix_desc->name);
00108 print_pix_fmt_fourccs(i, ' ');
00109 printf("\n");
00110 }
00111 }
00112
00113 if (pix_fmt_name) {
00114 enum AVPixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
00115 if (pix_fmt == AV_PIX_FMT_NONE) {
00116 fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
00117 return 1;
00118 }
00119 print_pix_fmt_fourccs(pix_fmt, '\n');
00120 }
00121
00122 return 0;
00123 }