MobileFFmpeg IOS API  3.1
fftools_cmdutils.h
Go to the documentation of this file.
1 /*
2  * Various utilities for command line tools
3  * copyright (c) 2003 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /*
23  * CHANGES 08.2018
24  * --------------------------------------------------------
25  * - fftools_ prefix added to file name and include guards
26  *
27  * CHANGES 07.2018
28  * --------------------------------------------------------
29  * - Include guards renamed
30  * - Unused headers removed
31  */
32 
33 #ifndef FFTOOLS_CMDUTILS_H
34 #define FFTOOLS_CMDUTILS_H
35 
36 #include <stdint.h>
37 
38 #include "config.h"
39 #include "libavcodec/avcodec.h"
40 #include "libavfilter/avfilter.h"
41 #include "libavformat/avformat.h"
42 #include "libswscale/swscale.h"
43 
44 #ifdef _WIN32
45 #undef main /* We don't want SDL to override our main() */
46 #endif
47 
51 extern const char program_name[];
52 
56 extern const int program_birth_year;
57 
58 extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
59 extern AVFormatContext *avformat_opts;
60 extern AVDictionary *sws_dict;
61 extern AVDictionary *swr_opts;
62 extern AVDictionary *format_opts, *codec_opts, *resample_opts;
63 extern int hide_banner;
64 
68 void register_exit(void (*cb)(int ret));
69 
73 void exit_program(int ret) av_noreturn;
74 
78 void init_dynload(void);
79 
84 void init_opts(void);
89 void uninit_opts(void);
90 
95 void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
96 
100 int opt_cpuflags(void *optctx, const char *opt, const char *arg);
101 
106 int opt_default(void *optctx, const char *opt, const char *arg);
107 
111 int opt_loglevel(void *optctx, const char *opt, const char *arg);
112 
113 int opt_report(const char *opt);
114 
115 int opt_max_alloc(void *optctx, const char *opt, const char *arg);
116 
117 int opt_codec_debug(void *optctx, const char *opt, const char *arg);
118 
122 int opt_timelimit(void *optctx, const char *opt, const char *arg);
123 
137 double parse_number_or_die(const char *context, const char *numstr, int type,
138  double min, double max);
139 
154 int64_t parse_time_or_die(const char *context, const char *timestr,
155  int is_duration);
156 
157 typedef struct SpecifierOpt {
158  char *specifier;
159  union {
160  uint8_t *str;
161  int i;
162  int64_t i64;
163  uint64_t ui64;
164  float f;
165  double dbl;
166  } u;
167 } SpecifierOpt;
168 
169 typedef struct OptionDef {
170  const char *name;
171  int flags;
172 #define HAS_ARG 0x0001
173 #define OPT_BOOL 0x0002
174 #define OPT_EXPERT 0x0004
175 #define OPT_STRING 0x0008
176 #define OPT_VIDEO 0x0010
177 #define OPT_AUDIO 0x0020
178 #define OPT_INT 0x0080
179 #define OPT_FLOAT 0x0100
180 #define OPT_SUBTITLE 0x0200
181 #define OPT_INT64 0x0400
182 #define OPT_EXIT 0x0800
183 #define OPT_DATA 0x1000
184 #define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only).
185  implied by OPT_OFFSET or OPT_SPEC */
186 #define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
187 #define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
188  Implies OPT_OFFSET. Next element after the offset is
189  an int containing element count in the array. */
190 #define OPT_TIME 0x10000
191 #define OPT_DOUBLE 0x20000
192 #define OPT_INPUT 0x40000
193 #define OPT_OUTPUT 0x80000
194  union {
195  void *dst_ptr;
196  int (*func_arg)(void *, const char *, const char *);
197  size_t off;
198  } u;
199  const char *help;
200  const char *argname;
201 } OptionDef;
202 
212 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
213  int rej_flags, int alt_flags);
214 
215 #if CONFIG_AVDEVICE
216 #define CMDUTILS_COMMON_OPTIONS_AVDEVICE \
217  { "sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_sources }, \
218  "list sources of the input device", "device" }, \
219  { "sinks" , OPT_EXIT | HAS_ARG, { .func_arg = show_sinks }, \
220  "list sinks of the output device", "device" }, \
221 
222 #else
223 #define CMDUTILS_COMMON_OPTIONS_AVDEVICE
224 #endif
225 
226 #define CMDUTILS_COMMON_OPTIONS \
227  { "L", OPT_EXIT, { .func_arg = show_license }, "show license" }, \
228  { "h", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
229  { "?", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
230  { "help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
231  { "-help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
232  { "version", OPT_EXIT, { .func_arg = show_version }, "show version" }, \
233  { "buildconf", OPT_EXIT, { .func_arg = show_buildconf }, "show build configuration" }, \
234  { "formats", OPT_EXIT, { .func_arg = show_formats }, "show available formats" }, \
235  { "muxers", OPT_EXIT, { .func_arg = show_muxers }, "show available muxers" }, \
236  { "demuxers", OPT_EXIT, { .func_arg = show_demuxers }, "show available demuxers" }, \
237  { "devices", OPT_EXIT, { .func_arg = show_devices }, "show available devices" }, \
238  { "codecs", OPT_EXIT, { .func_arg = show_codecs }, "show available codecs" }, \
239  { "decoders", OPT_EXIT, { .func_arg = show_decoders }, "show available decoders" }, \
240  { "encoders", OPT_EXIT, { .func_arg = show_encoders }, "show available encoders" }, \
241  { "bsfs", OPT_EXIT, { .func_arg = show_bsfs }, "show available bit stream filters" }, \
242  { "protocols", OPT_EXIT, { .func_arg = show_protocols }, "show available protocols" }, \
243  { "filters", OPT_EXIT, { .func_arg = show_filters }, "show available filters" }, \
244  { "pix_fmts", OPT_EXIT, { .func_arg = show_pix_fmts }, "show available pixel formats" }, \
245  { "layouts", OPT_EXIT, { .func_arg = show_layouts }, "show standard channel layouts" }, \
246  { "sample_fmts", OPT_EXIT, { .func_arg = show_sample_fmts }, "show available audio sample formats" }, \
247  { "colors", OPT_EXIT, { .func_arg = show_colors }, "show available color names" }, \
248  { "loglevel", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
249  { "v", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
250  { "report", 0, { (void*)opt_report }, "generate a report" }, \
251  { "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" }, \
252  { "cpuflags", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, \
253  { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, \
254  CMDUTILS_COMMON_OPTIONS_AVDEVICE \
255 
256 
260 void show_help_children(const AVClass *class, int flags);
261 
266 void show_help_default(const char *opt, const char *arg);
267 
271 int show_help(void *optctx, const char *opt, const char *arg);
272 
285 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
286  void (* parse_arg_function)(void *optctx, const char*));
287 
293 int parse_option(void *optctx, const char *opt, const char *arg,
294  const OptionDef *options);
295 
301 typedef struct Option {
302  const OptionDef *opt;
303  const char *key;
304  const char *val;
305 } Option;
306 
307 typedef struct OptionGroupDef {
309  const char *name;
314  const char *sep;
319  int flags;
321 
322 typedef struct OptionGroup {
324  const char *arg;
325 
327  int nb_opts;
328 
329  AVDictionary *codec_opts;
330  AVDictionary *format_opts;
331  AVDictionary *resample_opts;
332  AVDictionary *sws_dict;
333  AVDictionary *swr_opts;
334 } OptionGroup;
335 
340 typedef struct OptionGroupList {
342 
346 
347 typedef struct OptionParseContext {
349 
352 
353  /* parsing state */
356 
362 int parse_optgroup(void *optctx, OptionGroup *g);
363 
382 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
383  const OptionDef *options,
384  const OptionGroupDef *groups, int nb_groups);
385 
390 
394 void parse_loglevel(int argc, char **argv, const OptionDef *options);
395 
399 int locate_option(int argc, char **argv, const OptionDef *options,
400  const char *optname);
401 
411 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
412 
427 AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
428  AVFormatContext *s, AVStream *st, AVCodec *codec);
429 
441 AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
442  AVDictionary *codec_opts);
443 
453 void print_error(const char *filename, int err);
454 
460 void show_banner(int argc, char **argv, const OptionDef *options);
461 
468 int show_version(void *optctx, const char *opt, const char *arg);
469 
475 int show_buildconf(void *optctx, const char *opt, const char *arg);
476 
482 int show_license(void *optctx, const char *opt, const char *arg);
483 
489 int show_formats(void *optctx, const char *opt, const char *arg);
490 
496 int show_muxers(void *optctx, const char *opt, const char *arg);
497 
503 int show_demuxers(void *optctx, const char *opt, const char *arg);
504 
510 int show_devices(void *optctx, const char *opt, const char *arg);
511 
512 #if CONFIG_AVDEVICE
513 
517 int show_sinks(void *optctx, const char *opt, const char *arg);
518 
523 int show_sources(void *optctx, const char *opt, const char *arg);
524 #endif
525 
531 int show_codecs(void *optctx, const char *opt, const char *arg);
532 
537 int show_decoders(void *optctx, const char *opt, const char *arg);
538 
543 int show_encoders(void *optctx, const char *opt, const char *arg);
544 
550 int show_filters(void *optctx, const char *opt, const char *arg);
551 
557 int show_bsfs(void *optctx, const char *opt, const char *arg);
558 
564 int show_protocols(void *optctx, const char *opt, const char *arg);
565 
571 int show_pix_fmts(void *optctx, const char *opt, const char *arg);
572 
578 int show_layouts(void *optctx, const char *opt, const char *arg);
579 
584 int show_sample_fmts(void *optctx, const char *opt, const char *arg);
585 
590 int show_colors(void *optctx, const char *opt, const char *arg);
591 
596 int read_yesno(void);
597 
616 FILE *get_preset_file(char *filename, size_t filename_size,
617  const char *preset_name, int is_path, const char *codec_name);
618 
629 void *grow_array(void *array, int elem_size, int *size, int new_size);
630 
631 #define media_type_string av_get_media_type_string
632 
633 #define GROW_ARRAY(array, nb_elems)\
634  array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
635 
636 #define GET_PIX_FMT_NAME(pix_fmt)\
637  const char *name = av_get_pix_fmt_name(pix_fmt);
638 
639 #define GET_CODEC_NAME(id)\
640  const char *name = avcodec_descriptor_get(id)->name;
641 
642 #define GET_SAMPLE_FMT_NAME(sample_fmt)\
643  const char *name = av_get_sample_fmt_name(sample_fmt)
644 
645 #define GET_SAMPLE_RATE_NAME(rate)\
646  char name[16];\
647  snprintf(name, sizeof(name), "%d", rate);
648 
649 #define GET_CH_LAYOUT_NAME(ch_layout)\
650  char name[16];\
651  snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
652 
653 #define GET_CH_LAYOUT_DESC(ch_layout)\
654  char name[128];\
655  av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
656 
657 double get_rotation(AVStream *st);
658 
659 #endif /* FFTOOLS_CMDUTILS_H */
int opt_timelimit(void *optctx, const char *opt, const char *arg)
int show_muxers(void *optctx, const char *opt, const char *arg)
int show_filters(void *optctx, const char *opt, const char *arg)
int read_yesno(void)
int opt_max_alloc(void *optctx, const char *opt, const char *arg)
AVDictionary * swr_opts
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
int show_decoders(void *optctx, const char *opt, const char *arg)
int show_devices(void *optctx, const char *opt, const char *arg)
int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups)
AVDictionary * sws_dict
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
int show_formats(void *optctx, const char *opt, const char *arg)
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *optctx, const char *))
int show_demuxers(void *optctx, const char *opt, const char *arg)
int show_help(void *optctx, const char *opt, const char *arg)
struct OptionGroupList OptionGroupList
int opt_codec_debug(void *optctx, const char *opt, const char *arg)
void show_banner(int argc, char **argv, const OptionDef *options)
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
void uninit_parse_context(OptionParseContext *octx)
AVFormatContext * avformat_opts
const OptionGroupDef * group_def
int opt_report(const char *opt)
void uninit_opts(void)
void init_dynload(void)
OptionGroupList * groups
AVDictionary * format_opts
AVCodecContext * avcodec_opts[AVMEDIA_TYPE_NB]
int show_protocols(void *optctx, const char *opt, const char *arg)
AVDictionary * resample_opts
AVDictionary * format_opts
const int program_birth_year
const OptionDef * opt
AVDictionary * resample_opts
void * grow_array(void *array, int elem_size, int *size, int new_size)
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
int show_colors(void *optctx, const char *opt, const char *arg)
int hide_banner
const char * name
void exit_program(int ret) av_noreturn
int show_buildconf(void *optctx, const char *opt, const char *arg)
struct OptionDef OptionDef
const char * help
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
int show_codecs(void *optctx, const char *opt, const char *arg)
union OptionDef::@1 u
const OptionDef options[]
const OptionGroupDef * group_def
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
AVDictionary * sws_dict
struct OptionParseContext OptionParseContext
union SpecifierOpt::@0 u
const char * key
NSString * type
const char * val
int opt_default(void *optctx, const char *opt, const char *arg)
AVDictionary * codec_opts
int show_license(void *optctx, const char *opt, const char *arg)
struct Option Option
NSString * codec
const char program_name[]
void register_exit(void(*cb)(int ret))
int opt_loglevel(void *optctx, const char *opt, const char *arg)
AVDictionary * codec_opts
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
double get_rotation(AVStream *st)
const char * argname
struct SpecifierOpt SpecifierOpt
struct OptionGroupDef OptionGroupDef
void show_help_children(const AVClass *class, int flags)
const char * sep
int parse_optgroup(void *optctx, OptionGroup *g)
int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
int show_version(void *optctx, const char *opt, const char *arg)
int opt_cpuflags(void *optctx, const char *opt, const char *arg)
int show_sample_fmts(void *optctx, const char *opt, const char *arg)
void init_opts(void)
void show_help_default(const char *opt, const char *arg)
const char * arg
AVDictionary * swr_opts
struct OptionGroup OptionGroup
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
int show_bsfs(void *optctx, const char *opt, const char *arg)
int show_pix_fmts(void *optctx, const char *opt, const char *arg)
int(* func_arg)(void *, const char *, const char *)
int show_encoders(void *optctx, const char *opt, const char *arg)
void parse_loglevel(int argc, char **argv, const OptionDef *options)
OptionGroup * groups
int show_layouts(void *optctx, const char *opt, const char *arg)
const char * name
long size
Definition: Statistics.m:26
void print_error(const char *filename, int err)