2 * Copyright (c) 2012 Stefano Sabatini
4 * This file is part of FFmpeg.
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.
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.
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
23 #include <unistd.h> /* getopt */
26 #include "libavutil/pixdesc.h"
27 #include "libavcodec/avcodec.h"
28 #include "libavutil/common.h"
29 #include "libavcodec/raw.h"
35 #include "compat/getopt.c"
38 static void usage(void)
40 printf("Show the relationships between rawvideo pixel formats and FourCC tags.\n");
41 printf("usage: fourcc2pixfmt [OPTIONS]\n");
44 "-l list the pixel format for each fourcc\n"
45 "-L list the fourccs for each pixel format\n"
46 "-p PIX_FMT given a pixel format, print the list of associated fourccs (one per line)\n"
47 "-h print this help\n");
50 static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, char sep)
54 for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
55 if (ff_raw_pix_fmt_tags[i].pix_fmt == pix_fmt) {
57 av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
58 printf("%s%c", buf, sep);
63 int main(int argc, char **argv)
65 int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
66 const char *pix_fmt_name = NULL;
74 while ((c = getopt(argc, argv, "hp:lL")) != -1) {
80 list_fourcc_pix_fmt = 1;
83 list_pix_fmt_fourccs = 1;
86 pix_fmt_name = optarg;
94 if (list_fourcc_pix_fmt) {
95 for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
97 av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
98 printf("%s: %s\n", buf, av_get_pix_fmt_name(ff_raw_pix_fmt_tags[i].pix_fmt));
102 if (list_pix_fmt_fourccs) {
103 for (i = 0; av_pix_fmt_desc_get(i); i++) {
104 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(i);
105 if (!pix_desc->name || pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
107 printf("%s: ", pix_desc->name);
108 print_pix_fmt_fourccs(i, ' ');
114 enum AVPixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
115 if (pix_fmt == AV_PIX_FMT_NONE) {
116 fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
119 print_pix_fmt_fourccs(pix_fmt, '\n');