FFmpeg
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  printf("%s%c", av_fourcc2str(pix_fmt_tags[i].fourcc), sep);
57 }
58 
59 int main(int argc, char **argv)
60 {
61  int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
62  const PixelFormatTag *pix_fmt_tags = avpriv_get_raw_pix_fmt_tags();
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; pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++)
93  printf("%s: %s\n", av_fourcc2str(pix_fmt_tags[i].fourcc),
94  av_get_pix_fmt_name(pix_fmt_tags[i].pix_fmt));
95 
96  if (list_pix_fmt_fourccs) {
97  for (i = 0; av_pix_fmt_desc_get(i); i++) {
98  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(i);
99  if (!pix_desc->name || pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
100  continue;
101  printf("%s: ", pix_desc->name);
102  print_pix_fmt_fourccs(i, pix_fmt_tags, ' ');
103  printf("\n");
104  }
105  }
106 
107  if (pix_fmt_name) {
108  enum AVPixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
109  if (pix_fmt == AV_PIX_FMT_NONE) {
110  fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
111  return 1;
112  }
113  print_pix_fmt_fourccs(pix_fmt, pix_fmt_tags, '\n');
114  }
115 
116  return 0;
117 }
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
avpriv_get_raw_pix_fmt_tags
const struct PixelFormatTag * avpriv_get_raw_pix_fmt_tags(void)
Definition: raw.c:300
PixelFormatTag
Definition: raw.h:34
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2541
pixdesc.h
AVPixFmtDescriptor::name
const char * name
Definition: pixdesc.h:71
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:129
PixelFormatTag::pix_fmt
enum AVPixelFormat pix_fmt
Definition: raw.h:35
raw.h
getopt
static int getopt(int argc, char *argv[], char *opts)
Definition: getopt.c:41
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demuxing_decoding.c:41
NULL
#define NULL
Definition: coverity.c:32
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:95
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
print_pix_fmt_fourccs
static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, const PixelFormatTag *pix_fmt_tags, char sep)
Definition: fourcc2pixfmt.c:50
printf
printf("static const uint8_t my_array[100] = {\n")
main
int main(int argc, char **argv)
Definition: fourcc2pixfmt.c:59
i
int i
Definition: input.c:407
common.h
avcodec.h
getopt.c
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2473
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
optarg
static char * optarg
Definition: getopt.c:39
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:70
usage
static void usage(void)
Definition: fourcc2pixfmt.c:38
fourcc
uint32_t fourcc
Definition: vaapi_decode.c:239
av_get_pix_fmt_name
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:2461
av_fourcc2str
#define av_fourcc2str(fourcc)
Definition: avutil.h:348