FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fourcc2pixfmt.c
Go to the documentation of this file.
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 #undef printf
32 #undef fprintf
33 
34 #if !HAVE_GETOPT
35 #include "compat/getopt.c"
36 #endif
37 
38 static void usage(void)
39 {
40  printf("Show the relationships between rawvideo pixel formats and FourCC tags.\n");
41  printf("usage: fourcc2pixfmt [OPTIONS]\n");
42  printf("\n"
43  "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");
48 }
49 
50 static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, const PixelFormatTag *pix_fmt_tags, char sep)
51 {
52  int i;
53 
54  for (i = 0; pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
55  if (pix_fmt_tags[i].pix_fmt == pix_fmt) {
56  char buf[32];
57  av_get_codec_tag_string(buf, sizeof(buf), pix_fmt_tags[i].fourcc);
58  printf("%s%c", buf, sep);
59  }
60  }
61 }
62 
63 int main(int argc, char **argv)
64 {
65  int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
66  const PixelFormatTag *pix_fmt_tags = avpriv_get_raw_pix_fmt_tags();
67  const char *pix_fmt_name = NULL;
68  char c;
69 
70  if (argc == 1) {
71  usage();
72  return 0;
73  }
74 
75  while ((c = getopt(argc, argv, "hp:lL")) != -1) {
76  switch (c) {
77  case 'h':
78  usage();
79  return 0;
80  case 'l':
81  list_fourcc_pix_fmt = 1;
82  break;
83  case 'L':
84  list_pix_fmt_fourccs = 1;
85  break;
86  case 'p':
87  pix_fmt_name = optarg;
88  break;
89  case '?':
90  usage();
91  return 1;
92  }
93  }
94 
95  if (list_fourcc_pix_fmt) {
96  for (i = 0; pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
97  char buf[32];
98  av_get_codec_tag_string(buf, sizeof(buf), pix_fmt_tags[i].fourcc);
99  printf("%s: %s\n", buf, av_get_pix_fmt_name(pix_fmt_tags[i].pix_fmt));
100  }
101  }
102 
103  if (list_pix_fmt_fourccs) {
104  for (i = 0; av_pix_fmt_desc_get(i); i++) {
105  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(i);
106  if (!pix_desc->name || pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
107  continue;
108  printf("%s: ", pix_desc->name);
109  print_pix_fmt_fourccs(i, pix_fmt_tags, ' ');
110  printf("\n");
111  }
112  }
113 
114  if (pix_fmt_name) {
115  enum AVPixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
116  if (pix_fmt == AV_PIX_FMT_NONE) {
117  fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
118  return 1;
119  }
120  print_pix_fmt_fourccs(pix_fmt, pix_fmt_tags, '\n');
121  }
122 
123  return 0;
124 }
#define NULL
Definition: coverity.c:32
static enum AVPixelFormat pix_fmt
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2157
enum AVPixelFormat pix_fmt
Definition: raw.h:34
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
Put a string representing the codec tag codec_tag in buf.
Definition: utils.c:2668
const char * name
Definition: pixdesc.h:82
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:140
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
Raw Video Codec.
int main(int argc, char **argv)
Definition: fourcc2pixfmt.c:63
static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, const PixelFormatTag *pix_fmt_tags, char sep)
Definition: fourcc2pixfmt.c:50
Libavcodec external API header.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static int getopt(int argc, char *argv[], char *opts)
Definition: getopt.c:41
void * buf
Definition: avisynth_c.h:553
common internal and external API header
static double c[64]
static char * optarg
Definition: getopt.c:39
const struct PixelFormatTag * avpriv_get_raw_pix_fmt_tags(void)
Definition: raw.c:269
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2090
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2078
static void usage(void)
Definition: fourcc2pixfmt.c:38
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61