FFmpeg
Loading...
Searching...
No Matches
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#include <stdio.h>
23#if HAVE_UNISTD_H
24#include <unistd.h> /* getopt */
25#endif
26
27#include "libavutil/avutil.h"
28#include "libavutil/pixdesc.h"
29#include "libavcodec/raw.h"
31
32#if !HAVE_GETOPT
33#include "compat/getopt.c"
34#endif
35
36static void usage(void)
37{
38 printf("Show the relationships between rawvideo pixel formats and FourCC tags.\n");
39 printf("usage: fourcc2pixfmt [OPTIONS]\n");
40 printf("\n"
41 "Options:\n"
42 "-l list the pixel format for each fourcc\n"
43 "-L list the fourccs for each pixel format\n"
44 "-p PIX_FMT given a pixel format, print the list of associated fourccs (one per line)\n"
45 "-h print this help\n");
46}
47
48static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, const PixelFormatTag *pix_fmt_tags, char sep)
49{
50 int i;
51
52 for (i = 0; pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++)
53 if (pix_fmt_tags[i].pix_fmt == pix_fmt)
54 printf("%s%c", av_fourcc2str(pix_fmt_tags[i].fourcc), sep);
55}
56
57int main(int argc, char **argv)
58{
59 int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
60 const PixelFormatTag *pix_fmt_tags = raw_pix_fmt_tags;
61 const char *pix_fmt_name = NULL;
62 int c;
63
64 if (argc == 1) {
65 usage();
66 return 0;
67 }
68
69 while ((c = getopt(argc, argv, "hp:lL")) != -1) {
70 switch (c) {
71 case 'h':
72 usage();
73 return 0;
74 case 'l':
75 list_fourcc_pix_fmt = 1;
76 break;
77 case 'L':
78 list_pix_fmt_fourccs = 1;
79 break;
80 case 'p':
81 pix_fmt_name = optarg;
82 break;
83 case '?':
84 usage();
85 return 1;
86 }
87 }
88
89 if (list_fourcc_pix_fmt)
90 for (i = 0; pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++)
91 printf("%s: %s\n", av_fourcc2str(pix_fmt_tags[i].fourcc),
92 av_get_pix_fmt_name(pix_fmt_tags[i].pix_fmt));
93
94 if (list_pix_fmt_fourccs) {
95 for (i = 0; av_pix_fmt_desc_get(i); i++) {
96 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(i);
97 if (!pix_desc->name || pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
98 continue;
99 printf("%s: ", pix_desc->name);
100 print_pix_fmt_fourccs(i, pix_fmt_tags, ' ');
101 printf("\n");
102 }
103 }
104
105 if (pix_fmt_name) {
106 enum AVPixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
107 if (pix_fmt == AV_PIX_FMT_NONE) {
108 fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
109 return 1;
110 }
111 print_pix_fmt_fourccs(pix_fmt, pix_fmt_tags, '\n');
112 }
113
114 return 0;
115}
Convenience header that includes libavutil's core.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
static enum AVPixelFormat pix_fmt
int main
Definition dovi_rpuenc.c:38
static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, const PixelFormatTag *pix_fmt_tags, char sep)
static void usage(void)
static int getopt(int argc, char *argv[], const char *opts)
Definition getopt.c:41
static char * optarg
Definition getopt.c:39
#define av_fourcc2str(fourcc)
Definition avutil.h:323
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:3380
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3392
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition pixdesc.h:128
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
Raw Video Codec.
static const PixelFormatTag raw_pix_fmt_tags[]
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
const char * name
Definition pixdesc.h:70
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Definition pixdesc.h:94
enum AVPixelFormat pix_fmt
Definition raw.h:33
uint32_t fourcc
static double c[64]