FFmpegKit iOS / macOS / tvOS API  4.4
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 01.2020
24  * - ffprobe support changes
25  * - AV_LOG_STDERR introduced
26  *
27  * CHANGES 12.2019
28  * - Concurrent execution support
29  *
30  * CHANGES 03.2019
31  * --------------------------------------------------------
32  * - config.h include removed
33  *
34  * CHANGES 08.2018
35  * --------------------------------------------------------
36  * - fftools_ prefix added to file name and include guards
37  *
38  * CHANGES 07.2018
39  * --------------------------------------------------------
40  * - Include guards renamed
41  * - Unused headers removed
42  */
43 
44 #ifndef FFTOOLS_CMDUTILS_H
45 #define FFTOOLS_CMDUTILS_H
46 
47 #include <stdint.h>
48 
49 #include "libavcodec/avcodec.h"
50 #include "libavfilter/avfilter.h"
51 #include "libavformat/avformat.h"
52 #include "libswscale/swscale.h"
53 
54 #ifdef _WIN32
55 #undef main /* We don't want SDL to override our main() */
56 #endif
57 
61 #define AV_LOG_STDERR -16
62 
66 extern __thread char *program_name;
67 
71 extern __thread int program_birth_year;
72 
73 extern __thread AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
74 extern __thread AVFormatContext *avformat_opts;
75 extern __thread AVDictionary *sws_dict;
76 extern __thread AVDictionary *swr_opts;
77 extern __thread AVDictionary *format_opts, *codec_opts, *resample_opts;
78 extern __thread int hide_banner;
79 extern __thread int find_stream_info;
80 
84 void register_exit(void (*cb)(int ret));
85 
89 void exit_program(int ret) av_noreturn;
90 
94 void init_dynload(void);
95 
100 void init_opts(void);
105 void uninit_opts(void);
106 
111 void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
112 
116 int opt_cpuflags(void *optctx, const char *opt, const char *arg);
117 
122 int opt_default(void *optctx, const char *opt, const char *arg);
123 
127 int opt_loglevel(void *optctx, const char *opt, const char *arg);
128 
129 int opt_report(void *optctx, const char *opt, const char *arg);
130 
131 int opt_max_alloc(void *optctx, const char *opt, const char *arg);
132 
133 int opt_codec_debug(void *optctx, const char *opt, const char *arg);
134 
138 int opt_timelimit(void *optctx, const char *opt, const char *arg);
139 
153 double parse_number_or_die(const char *context, const char *numstr, int type,
154  double min, double max);
155 
170 int64_t parse_time_or_die(const char *context, const char *timestr,
171  int is_duration);
172 
173 typedef struct SpecifierOpt {
174  char *specifier;
175  union {
176  uint8_t *str;
177  int i;
178  int64_t i64;
179  uint64_t ui64;
180  float f;
181  double dbl;
182  } u;
184 
185 typedef struct OptionDef {
186  const char *name;
187  int flags;
188 #define HAS_ARG 0x0001
189 #define OPT_BOOL 0x0002
190 #define OPT_EXPERT 0x0004
191 #define OPT_STRING 0x0008
192 #define OPT_VIDEO 0x0010
193 #define OPT_AUDIO 0x0020
194 #define OPT_INT 0x0080
195 #define OPT_FLOAT 0x0100
196 #define OPT_SUBTITLE 0x0200
197 #define OPT_INT64 0x0400
198 #define OPT_EXIT 0x0800
199 #define OPT_DATA 0x1000
200 #define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only).
201  implied by OPT_OFFSET or OPT_SPEC */
202 #define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
203 #define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
204  Implies OPT_OFFSET. Next element after the offset is
205  an int containing element count in the array. */
206 #define OPT_TIME 0x10000
207 #define OPT_DOUBLE 0x20000
208 #define OPT_INPUT 0x40000
209 #define OPT_OUTPUT 0x80000
210  union {
211  void *dst_ptr;
212  int (*func_arg)(void *, const char *, const char *);
213  size_t off;
214  } u;
215  const char *help;
216  const char *argname;
217 } OptionDef;
218 
228 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
229  int rej_flags, int alt_flags);
230 
235 void show_help_children(const AVClass *class, int flags);
236 
241 void show_help_default_ffmpeg(const char *opt, const char *arg);
242 void show_help_default_ffprobe(const char *opt, const char *arg);
243 
247 int show_help(void *optctx, const char *opt, const char *arg);
248 
261 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
262  void (* parse_arg_function)(void *optctx, const char*));
263 
269 int parse_option(void *optctx, const char *opt, const char *arg,
270  const OptionDef *options);
271 
277 typedef struct Option {
278  const OptionDef *opt;
279  const char *key;
280  const char *val;
281 } Option;
282 
283 typedef struct OptionGroupDef {
285  const char *name;
290  const char *sep;
295  int flags;
297 
298 typedef struct OptionGroup {
300  const char *arg;
301 
303  int nb_opts;
304 
305  AVDictionary *codec_opts;
306  AVDictionary *format_opts;
307  AVDictionary *resample_opts;
308  AVDictionary *sws_dict;
309  AVDictionary *swr_opts;
310 } OptionGroup;
311 
316 typedef struct OptionGroupList {
318 
322 
323 typedef struct OptionParseContext {
325 
328 
329  /* parsing state */
332 
339 int parse_optgroup(void *optctx, OptionGroup *g);
340 
359 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
360  const OptionDef *options,
361  const OptionGroupDef *groups, int nb_groups);
362 
367 
371 void parse_loglevel(int argc, char **argv, const OptionDef *options);
372 
376 int locate_option(int argc, char **argv, const OptionDef *options,
377  const char *optname);
378 
388 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
389 
404 AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
405  AVFormatContext *s, AVStream *st, AVCodec *codec);
406 
418 AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
419  AVDictionary *codec_opts);
420 
430 void print_error(const char *filename, int err);
431 
437 void show_banner(int argc, char **argv, const OptionDef *options);
438 
445 int show_version(void *optctx, const char *opt, const char *arg);
446 
452 int show_buildconf(void *optctx, const char *opt, const char *arg);
453 
459 int show_license(void *optctx, const char *opt, const char *arg);
460 
466 int show_formats(void *optctx, const char *opt, const char *arg);
467 
473 int show_muxers(void *optctx, const char *opt, const char *arg);
474 
480 int show_demuxers(void *optctx, const char *opt, const char *arg);
481 
487 int show_devices(void *optctx, const char *opt, const char *arg);
488 
489 #if CONFIG_AVDEVICE
494 int show_sinks(void *optctx, const char *opt, const char *arg);
495 
500 int show_sources(void *optctx, const char *opt, const char *arg);
501 #endif
502 
508 int show_codecs(void *optctx, const char *opt, const char *arg);
509 
514 int show_decoders(void *optctx, const char *opt, const char *arg);
515 
520 int show_encoders(void *optctx, const char *opt, const char *arg);
521 
527 int show_filters(void *optctx, const char *opt, const char *arg);
528 
534 int show_bsfs(void *optctx, const char *opt, const char *arg);
535 
541 int show_protocols(void *optctx, const char *opt, const char *arg);
542 
548 int show_pix_fmts(void *optctx, const char *opt, const char *arg);
549 
555 int show_layouts(void *optctx, const char *opt, const char *arg);
556 
561 int show_sample_fmts(void *optctx, const char *opt, const char *arg);
562 
567 int show_colors(void *optctx, const char *opt, const char *arg);
568 
573 int read_yesno(void);
574 
593 FILE *get_preset_file(char *filename, size_t filename_size,
594  const char *preset_name, int is_path, const char *codec_name);
595 
606 void *grow_array(void *array, int elem_size, int *size, int new_size);
607 
608 #define media_type_string av_get_media_type_string
609 
610 #define GROW_ARRAY(array, nb_elems)\
611  array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
612 
613 #define GET_PIX_FMT_NAME(pix_fmt)\
614  const char *name = av_get_pix_fmt_name(pix_fmt);
615 
616 #define GET_CODEC_NAME(id)\
617  const char *name = avcodec_descriptor_get(id)->name;
618 
619 #define GET_SAMPLE_FMT_NAME(sample_fmt)\
620  const char *name = av_get_sample_fmt_name(sample_fmt)
621 
622 #define GET_SAMPLE_RATE_NAME(rate)\
623  char name[16];\
624  snprintf(name, sizeof(name), "%d", rate);
625 
626 #define GET_CH_LAYOUT_NAME(ch_layout)\
627  char name[16];\
628  snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
629 
630 #define GET_CH_LAYOUT_DESC(ch_layout)\
631  char name[128];\
632  av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
633 
634 double get_rotation(AVStream *st);
635 
636 #endif /* FFTOOLS_CMDUTILS_H */
__thread AVDictionary * swr_opts
int show_decoders(void *optctx, const char *opt, const char *arg)
int opt_loglevel(void *optctx, const char *opt, const char *arg)
void show_help_children(const AVClass *class, int flags)
__thread AVDictionary * codec_opts
int opt_cpuflags(void *optctx, const char *opt, const char *arg)
void init_dynload(void)
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
int show_help(void *optctx, const char *opt, const char *arg)
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *optctx, const char *))
__thread AVDictionary * format_opts
void exit_program(int ret) av_noreturn
int opt_default(void *optctx, const char *opt, const char *arg)
void print_error(const char *filename, int err)
int opt_codec_debug(void *optctx, const char *opt, const char *arg)
int show_filters(void *optctx, const char *opt, const char *arg)
int show_sample_fmts(void *optctx, const char *opt, const char *arg)
int read_yesno(void)
struct OptionParseContext OptionParseContext
struct SpecifierOpt SpecifierOpt
__thread AVFormatContext * avformat_opts
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
int show_muxers(void *optctx, const char *opt, const char *arg)
int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
int show_bsfs(void *optctx, const char *opt, const char *arg)
void * grow_array(void *array, int elem_size, int *size, int new_size)
__thread AVCodecContext * avcodec_opts[AVMEDIA_TYPE_NB]
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
__thread AVDictionary * resample_opts
__thread char * program_name
int show_layouts(void *optctx, const char *opt, const char *arg)
int show_encoders(void *optctx, const char *opt, const char *arg)
int show_version(void *optctx, const char *opt, const char *arg)
void parse_loglevel(int argc, char **argv, const OptionDef *options)
__thread int program_birth_year
void uninit_parse_context(OptionParseContext *octx)
__thread AVDictionary * sws_dict
int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups)
double get_rotation(AVStream *st)
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
__thread int find_stream_info
void show_banner(int argc, char **argv, const OptionDef *options)
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
int opt_timelimit(void *optctx, const char *opt, const char *arg)
int show_license(void *optctx, const char *opt, const char *arg)
int show_codecs(void *optctx, const char *opt, const char *arg)
int show_buildconf(void *optctx, const char *opt, const char *arg)
struct OptionGroupList OptionGroupList
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
void register_exit(void(*cb)(int ret))
int show_devices(void *optctx, const char *opt, const char *arg)
struct Option Option
struct OptionGroup OptionGroup
void uninit_opts(void)
int show_formats(void *optctx, const char *opt, const char *arg)
void show_help_default_ffprobe(const char *opt, const char *arg)
__thread int hide_banner
int show_protocols(void *optctx, const char *opt, const char *arg)
int parse_optgroup(void *optctx, OptionGroup *g)
int opt_max_alloc(void *optctx, const char *opt, const char *arg)
struct OptionGroupDef OptionGroupDef
int opt_report(void *optctx, const char *opt, const char *arg)
void init_opts(void)
struct OptionDef OptionDef
int show_colors(void *optctx, const char *opt, const char *arg)
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
void show_help_default_ffmpeg(const char *opt, const char *arg)
int show_pix_fmts(void *optctx, const char *opt, const char *arg)
int show_demuxers(void *optctx, const char *opt, const char *arg)
union OptionDef::@1 u
const char * name
const char * argname
const char * help
int(* func_arg)(void *, const char *, const char *)
const char * name
const char * sep
const OptionGroupDef * group_def
AVDictionary * codec_opts
AVDictionary * swr_opts
AVDictionary * sws_dict
const char * arg
AVDictionary * format_opts
AVDictionary * resample_opts
OptionGroup * groups
const OptionGroupDef * group_def
const char * key
const OptionDef * opt
const char * val
OptionGroupList * groups
union SpecifierOpt::@0 u