FFmpeg
enum_options.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Anton Khirnov
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 /*
22  * enumerate avoptions and format them in texinfo format
23  */
24 
25 #include <string.h>
26 
27 #include "libavformat/avformat.h"
28 #include "libavcodec/avcodec.h"
29 #include "libavutil/log.h"
30 #include "libavutil/opt.h"
31 
32 static void print_usage(void)
33 {
34  fprintf(stderr, "Usage: enum_options type\n"
35  "type: format codec\n");
36  exit(1);
37 }
38 
39 static void print_option(const AVClass *class, const AVOption *o)
40 {
41  printf("@item -%s @var{", o->name);
42  switch (o->type) {
43  case AV_OPT_TYPE_BINARY: printf("hexadecimal string"); break;
44  case AV_OPT_TYPE_STRING: printf("string"); break;
45  case AV_OPT_TYPE_INT:
46  case AV_OPT_TYPE_INT64: printf("integer"); break;
47  case AV_OPT_TYPE_FLOAT:
48  case AV_OPT_TYPE_DOUBLE: printf("float"); break;
49  case AV_OPT_TYPE_RATIONAL: printf("rational number"); break;
50  case AV_OPT_TYPE_FLAGS: printf("flags"); break;
51  default: printf("value"); break;
52  }
53  printf("} (@emph{");
54 
56  printf("input");
58  printf("/");
59  }
61  printf("output");
62 
63  printf("})\n");
64  if (o->help)
65  printf("%s\n", o->help);
66 
67  if (o->unit) {
68  const AVOption *u = NULL;
69  printf("\nPossible values:\n@table @samp\n");
70 
71  while ((u = av_opt_next(&class, u)))
72  if (u->type == AV_OPT_TYPE_CONST && u->unit && !strcmp(u->unit, o->unit))
73  printf("@item %s\n%s\n", u->name, u->help ? u->help : "");
74  printf("@end table\n");
75  }
76 }
77 
78 static void show_opts(const AVClass *class)
79 {
80  const AVOption *o = NULL;
81 
82  printf("@table @option\n");
83  while ((o = av_opt_next(&class, o)))
84  if (o->type != AV_OPT_TYPE_CONST)
85  print_option(class, o);
86  printf("@end table\n");
87 }
88 
89 static void show_format_opts(void)
90 {
91  const AVInputFormat *iformat = NULL;
92  const AVOutputFormat *oformat = NULL;
93  void *iformat_opaque = NULL;
94  void *oformat_opaque = NULL;
95 
96  printf("@section Generic format AVOptions\n");
98 
99  printf("@section Format-specific AVOptions\n");
100  while ((iformat = av_demuxer_iterate(&iformat_opaque))) {
101  if (!iformat->priv_class)
102  continue;
103  printf("@subsection %s AVOptions\n", iformat->priv_class->class_name);
105  }
106  while ((oformat = av_muxer_iterate(&oformat_opaque))) {
107  if (!oformat->priv_class)
108  continue;
109  printf("@subsection %s AVOptions\n", oformat->priv_class->class_name);
110  show_opts(oformat->priv_class);
111  }
112 }
113 
114 static void show_codec_opts(void)
115 {
116  void *iter = NULL;
117  const AVCodec *c;
118 
119  printf("@section Generic codec AVOptions\n");
121 
122  printf("@section Codec-specific AVOptions\n");
123  while ((c = av_codec_iterate(&iter))) {
124  if (!c->priv_class)
125  continue;
126  printf("@subsection %s AVOptions\n", c->priv_class->class_name);
127  show_opts(c->priv_class);
128  }
129 }
130 
131 int main(int argc, char **argv)
132 {
133  if (argc < 2)
134  print_usage();
135 
136  if (!strcmp(argv[1], "format"))
138  else if (!strcmp(argv[1], "codec"))
139  show_codec_opts();
140  else
141  print_usage();
142 
143  return 0;
144 }
AVCodec
AVCodec.
Definition: codec.h:187
opt.h
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:251
print_option
static void print_option(const AVClass *class, const AVOption *o)
Definition: enum_options.c:39
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:197
AVOption
AVOption.
Definition: opt.h:429
print_usage
static void print_usage(void)
Definition: enum_options.c:32
AVOption::help
const char * help
short English help text
Definition: opt.h:436
AVOption::flags
int flags
A combination of AV_OPT_FLAG_*.
Definition: opt.h:472
AV_OPT_TYPE_RATIONAL
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
Definition: opt.h:280
AV_OPT_TYPE_BINARY
@ AV_OPT_TYPE_BINARY
Underlying C type is a uint8_t* that is either NULL or points to an array allocated with the av_mallo...
Definition: opt.h:286
main
int main(int argc, char **argv)
Definition: enum_options.c:131
AVInputFormat
Definition: avformat.h:548
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
Definition: opt.h:263
show_format_opts
static void show_format_opts(void)
Definition: enum_options.c:89
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
avcodec_get_class
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:184
NULL
#define NULL
Definition: coverity.c:32
AVOutputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:538
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:352
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
show_opts
static void show_opts(const AVClass *class)
Definition: enum_options.c:78
av_demuxer_iterate
const AVInputFormat * av_demuxer_iterate(void **opaque)
Iterate over all registered demuxers.
Definition: allformats.c:606
printf
printf("static const uint8_t my_array[100] = {\n")
AVOption::name
const char * name
Definition: opt.h:430
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
iformat
static const AVInputFormat * iformat
Definition: ffprobe.c:360
av_opt_next
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:48
show_codec_opts
static void show_codec_opts(void)
Definition: enum_options.c:114
log.h
AVOutputFormat
Definition: avformat.h:509
av_codec_iterate
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition: allcodecs.c:959
avcodec.h
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:80
avformat.h
AVOption::type
enum AVOptionType type
Definition: opt.h:445
av_muxer_iterate
const AVOutputFormat * av_muxer_iterate(void **opaque)
Iterate over all registered muxers.
Definition: allformats.c:585
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVOption::unit
const char * unit
The logical unit to which the option belongs.
Definition: opt.h:479
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition: opt.h:255
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
AVInputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:578