]> git.sesse.net Git - ffmpeg/blob - tools/fourcc2pixfmt.c
Merge commit 'f5962229bfcb14c2879e69ccdf7f1a4934168609'
[ffmpeg] / tools / fourcc2pixfmt.c
1 /*
2  * Copyright (c) 2012 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #include "config.h"
22 #if HAVE_UNISTD_H
23 #include <unistd.h>             /* getopt */
24 #endif
25
26 #include "libavutil/pixdesc.h"
27 #include "libavcodec/avcodec.h"
28 #include "libavutil/common.h"
29 #include "libavcodec/raw.h"
30
31 #if !HAVE_GETOPT
32 #include "compat/getopt.c"
33 #endif
34
35 static void usage(void)
36 {
37     printf("Show the relationships between rawvideo pixel formats and FourCC tags.\n");
38     printf("usage: fourcc2pixfmt [OPTIONS]\n");
39     printf("\n"
40            "Options:\n"
41            "-l                list the pixel format for each fourcc\n"
42            "-L                list the fourccs for each pixel format\n"
43            "-p PIX_FMT        given a pixel format, print the list of associated fourccs (one per line)\n"
44            "-h                print this help\n");
45 }
46
47 static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, char sep)
48 {
49     int i;
50
51     for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
52         if (ff_raw_pix_fmt_tags[i].pix_fmt == pix_fmt) {
53             char buf[32];
54             av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
55             printf("%s%c", buf, sep);
56         }
57     }
58 }
59
60 int main(int argc, char **argv)
61 {
62     int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
63     const char *pix_fmt_name = NULL;
64     char c;
65
66     if (argc == 1) {
67         usage();
68         return 0;
69     }
70
71     while ((c = getopt(argc, argv, "hp:lL")) != -1) {
72         switch (c) {
73         case 'h':
74             usage();
75             return 0;
76         case 'l':
77             list_fourcc_pix_fmt = 1;
78             break;
79         case 'L':
80             list_pix_fmt_fourccs = 1;
81             break;
82         case 'p':
83             pix_fmt_name = optarg;
84             break;
85         case '?':
86             usage();
87             return 1;
88         }
89     }
90
91     if (list_fourcc_pix_fmt) {
92         for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
93             char buf[32];
94             av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
95             printf("%s: %s\n", buf, av_get_pix_fmt_name(ff_raw_pix_fmt_tags[i].pix_fmt));
96         }
97     }
98
99     if (list_pix_fmt_fourccs) {
100         for (i = 0; i < AV_PIX_FMT_NB; i++) {
101             const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[i];
102             if (!pix_desc->name || pix_desc->flags & PIX_FMT_HWACCEL)
103                 continue;
104             printf("%s: ", pix_desc->name);
105             print_pix_fmt_fourccs(i, ' ');
106             printf("\n");
107         }
108     }
109
110     if (pix_fmt_name) {
111         enum AVPixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
112         if (pix_fmt == AV_PIX_FMT_NONE) {
113             fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
114             return 1;
115         }
116         print_pix_fmt_fourccs(pix_fmt, '\n');
117     }
118
119     return 0;
120 }