FFmpegKit Android 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 #include "saf_wrapper.h"
55 
56 #ifdef _WIN32
57 #undef main /* We don't want SDL to override our main() */
58 #endif
59 
63 #define AV_LOG_STDERR -16
64 
68 extern __thread char *program_name;
69 
73 extern __thread int program_birth_year;
74 
75 extern __thread AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
76 extern __thread AVFormatContext *avformat_opts;
77 extern __thread AVDictionary *sws_dict;
78 extern __thread AVDictionary *swr_opts;
79 extern __thread AVDictionary *format_opts, *codec_opts, *resample_opts;
80 extern __thread int hide_banner;
81 extern __thread int find_stream_info;
82 
86 void register_exit(void (*cb)(int ret));
87 
91 void exit_program(int ret) av_noreturn;
92 
96 void init_dynload(void);
97 
102 void init_opts(void);
107 void uninit_opts(void);
108 
113 void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
114 
118 int opt_cpuflags(void *optctx, const char *opt, const char *arg);
119 
124 int opt_default(void *optctx, const char *opt, const char *arg);
125 
129 int opt_loglevel(void *optctx, const char *opt, const char *arg);
130 
131 int opt_report(void *optctx, const char *opt, const char *arg);
132 
133 int opt_max_alloc(void *optctx, const char *opt, const char *arg);
134 
135 int opt_codec_debug(void *optctx, const char *opt, const char *arg);
136 
140 int opt_timelimit(void *optctx, const char *opt, const char *arg);
141 
155 double parse_number_or_die(const char *context, const char *numstr, int type,
156  double min, double max);
157 
172 int64_t parse_time_or_die(const char *context, const char *timestr,
173  int is_duration);
174 
175 typedef struct SpecifierOpt {
176  char *specifier;
177  union {
178  uint8_t *str;
179  int i;
180  int64_t i64;
181  uint64_t ui64;
182  float f;
183  double dbl;
184  } u;
186 
187 typedef struct OptionDef {
188  const char *name;
189  int flags;
190 #define HAS_ARG 0x0001
191 #define OPT_BOOL 0x0002
192 #define OPT_EXPERT 0x0004
193 #define OPT_STRING 0x0008
194 #define OPT_VIDEO 0x0010
195 #define OPT_AUDIO 0x0020
196 #define OPT_INT 0x0080
197 #define OPT_FLOAT 0x0100
198 #define OPT_SUBTITLE 0x0200
199 #define OPT_INT64 0x0400
200 #define OPT_EXIT 0x0800
201 #define OPT_DATA 0x1000
202 #define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only).
203  implied by OPT_OFFSET or OPT_SPEC */
204 #define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
205 #define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
206  Implies OPT_OFFSET. Next element after the offset is
207  an int containing element count in the array. */
208 #define OPT_TIME 0x10000
209 #define OPT_DOUBLE 0x20000
210 #define OPT_INPUT 0x40000
211 #define OPT_OUTPUT 0x80000
212  union {
213  void *dst_ptr;
214  int (*func_arg)(void *, const char *, const char *);
215  size_t off;
216  } u;
217  const char *help;
218  const char *argname;
219 } OptionDef;
220 
230 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
231  int rej_flags, int alt_flags);
232 
237 void show_help_children(const AVClass *class, int flags);
238 
243 void show_help_default_ffmpeg(const char *opt, const char *arg);
244 void show_help_default_ffprobe(const char *opt, const char *arg);
245 
249 int show_help(void *optctx, const char *opt, const char *arg);
250 
263 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
264  void (* parse_arg_function)(void *optctx, const char*));
265 
271 int parse_option(void *optctx, const char *opt, const char *arg,
272  const OptionDef *options);
273 
279 typedef struct Option {
280  const OptionDef *opt;
281  const char *key;
282  const char *val;
283 } Option;
284 
285 typedef struct OptionGroupDef {
287  const char *name;
292  const char *sep;
297  int flags;
299 
300 typedef struct OptionGroup {
302  const char *arg;
303 
305  int nb_opts;
306 
307  AVDictionary *codec_opts;
308  AVDictionary *format_opts;
309  AVDictionary *resample_opts;
310  AVDictionary *sws_dict;
311  AVDictionary *swr_opts;
312 } OptionGroup;
313 
318 typedef struct OptionGroupList {
320 
324 
325 typedef struct OptionParseContext {
327 
330 
331  /* parsing state */
334 
341 int parse_optgroup(void *optctx, OptionGroup *g);
342 
361 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
362  const OptionDef *options,
363  const OptionGroupDef *groups, int nb_groups);
364 
369 
373 void parse_loglevel(int argc, char **argv, const OptionDef *options);
374 
378 int locate_option(int argc, char **argv, const OptionDef *options,
379  const char *optname);
380 
390 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
391 
406 AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
407  AVFormatContext *s, AVStream *st, AVCodec *codec);
408 
420 AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
421  AVDictionary *codec_opts);
422 
432 void print_error(const char *filename, int err);
433 
439 void show_banner(int argc, char **argv, const OptionDef *options);
440 
447 int show_version(void *optctx, const char *opt, const char *arg);
448 
454 int show_buildconf(void *optctx, const char *opt, const char *arg);
455 
461 int show_license(void *optctx, const char *opt, const char *arg);
462 
468 int show_formats(void *optctx, const char *opt, const char *arg);
469 
475 int show_muxers(void *optctx, const char *opt, const char *arg);
476 
482 int show_demuxers(void *optctx, const char *opt, const char *arg);
483 
489 int show_devices(void *optctx, const char *opt, const char *arg);
490 
491 #if CONFIG_AVDEVICE
496 int show_sinks(void *optctx, const char *opt, const char *arg);
497 
502 int show_sources(void *optctx, const char *opt, const char *arg);
503 #endif
504 
510 int show_codecs(void *optctx, const char *opt, const char *arg);
511 
516 int show_decoders(void *optctx, const char *opt, const char *arg);
517 
522 int show_encoders(void *optctx, const char *opt, const char *arg);
523 
529 int show_filters(void *optctx, const char *opt, const char *arg);
530 
536 int show_bsfs(void *optctx, const char *opt, const char *arg);
537 
543 int show_protocols(void *optctx, const char *opt, const char *arg);
544 
550 int show_pix_fmts(void *optctx, const char *opt, const char *arg);
551 
557 int show_layouts(void *optctx, const char *opt, const char *arg);
558 
563 int show_sample_fmts(void *optctx, const char *opt, const char *arg);
564 
569 int show_colors(void *optctx, const char *opt, const char *arg);
570 
575 int read_yesno(void);
576 
595 FILE *get_preset_file(char *filename, size_t filename_size,
596  const char *preset_name, int is_path, const char *codec_name);
597 
608 void *grow_array(void *array, int elem_size, int *size, int new_size);
609 
610 #define media_type_string av_get_media_type_string
611 
612 #define GROW_ARRAY(array, nb_elems)\
613  array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
614 
615 #define GET_PIX_FMT_NAME(pix_fmt)\
616  const char *name = av_get_pix_fmt_name(pix_fmt);
617 
618 #define GET_CODEC_NAME(id)\
619  const char *name = avcodec_descriptor_get(id)->name;
620 
621 #define GET_SAMPLE_FMT_NAME(sample_fmt)\
622  const char *name = av_get_sample_fmt_name(sample_fmt)
623 
624 #define GET_SAMPLE_RATE_NAME(rate)\
625  char name[16];\
626  snprintf(name, sizeof(name), "%d", rate);
627 
628 #define GET_CH_LAYOUT_NAME(ch_layout)\
629  char name[16];\
630  snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
631 
632 #define GET_CH_LAYOUT_DESC(ch_layout)\
633  char name[128];\
634  av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
635 
636 double get_rotation(AVStream *st);
637 
638 #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