FFmpegKit iOS / macOS / tvOS API 4.5
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
66extern __thread char *program_name;
67
71extern __thread int program_birth_year;
72
73extern __thread AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
74extern __thread AVFormatContext *avformat_opts;
75extern __thread AVDictionary *sws_dict;
76extern __thread AVDictionary *swr_opts;
77extern __thread AVDictionary *format_opts, *codec_opts, *resample_opts;
78extern __thread int hide_banner;
79extern __thread int find_stream_info;
80
84void register_exit(void (*cb)(int ret));
85
89void exit_program(int ret) av_noreturn;
90
94void init_dynload(void);
95
100void init_opts(void);
105void uninit_opts(void);
106
111void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
112
116int opt_cpuflags(void *optctx, const char *opt, const char *arg);
117
121int opt_cpucount(void *optctx, const char *opt, const char *arg);
122
127int opt_default(void *optctx, const char *opt, const char *arg);
128
132int opt_loglevel(void *optctx, const char *opt, const char *arg);
133
134int opt_report(void *optctx, const char *opt, const char *arg);
135
136int opt_max_alloc(void *optctx, const char *opt, const char *arg);
137
138int opt_codec_debug(void *optctx, const char *opt, const char *arg);
139
143int opt_timelimit(void *optctx, const char *opt, const char *arg);
144
158double parse_number_or_die(const char *context, const char *numstr, int type,
159 double min, double max);
160
175int64_t parse_time_or_die(const char *context, const char *timestr,
176 int is_duration);
177
178typedef struct SpecifierOpt {
179 char *specifier;
180 union {
181 uint8_t *str;
182 int i;
183 int64_t i64;
184 uint64_t ui64;
185 float f;
186 double dbl;
187 } u;
189
190typedef struct OptionDef {
191 const char *name;
192 int flags;
193#define HAS_ARG 0x0001
194#define OPT_BOOL 0x0002
195#define OPT_EXPERT 0x0004
196#define OPT_STRING 0x0008
197#define OPT_VIDEO 0x0010
198#define OPT_AUDIO 0x0020
199#define OPT_INT 0x0080
200#define OPT_FLOAT 0x0100
201#define OPT_SUBTITLE 0x0200
202#define OPT_INT64 0x0400
203#define OPT_EXIT 0x0800
204#define OPT_DATA 0x1000
205#define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only).
206 implied by OPT_OFFSET or OPT_SPEC */
207#define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
208#define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
209 Implies OPT_OFFSET. Next element after the offset is
210 an int containing element count in the array. */
211#define OPT_TIME 0x10000
212#define OPT_DOUBLE 0x20000
213#define OPT_INPUT 0x40000
214#define OPT_OUTPUT 0x80000
215 union {
216 void *dst_ptr;
217 int (*func_arg)(void *, const char *, const char *);
218 size_t off;
219 } u;
220 const char *help;
221 const char *argname;
222} OptionDef;
223
233void show_help_options(const OptionDef *options, const char *msg, int req_flags,
234 int rej_flags, int alt_flags);
235
240void show_help_children(const AVClass *class, int flags);
241
246void show_help_default_ffmpeg(const char *opt, const char *arg);
247void show_help_default_ffprobe(const char *opt, const char *arg);
248
252int show_help(void *optctx, const char *opt, const char *arg);
253
266void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
267 void (* parse_arg_function)(void *optctx, const char*));
268
274int parse_option(void *optctx, const char *opt, const char *arg,
275 const OptionDef *options);
276
282typedef struct Option {
284 const char *key;
285 const char *val;
286} Option;
288typedef struct OptionGroupDef {
290 const char *name;
295 const char *sep;
300 int flags;
303typedef struct OptionGroup {
305 const char *arg;
306
310 AVDictionary *codec_opts;
311 AVDictionary *format_opts;
312 AVDictionary *resample_opts;
313 AVDictionary *sws_dict;
314 AVDictionary *swr_opts;
316
321typedef struct OptionGroupList {
327
328typedef struct OptionParseContext {
330
334 /* parsing state */
337
344int parse_optgroup(void *optctx, OptionGroup *g);
345
364int split_commandline(OptionParseContext *octx, int argc, char *argv[],
365 const OptionDef *options,
366 const OptionGroupDef *groups, int nb_groups);
367
372
376void parse_loglevel(int argc, char **argv, const OptionDef *options);
377
381int locate_option(int argc, char **argv, const OptionDef *options,
382 const char *optname);
383
393int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
394
409AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
410 AVFormatContext *s, AVStream *st, const AVCodec *codec);
411
423AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
424 AVDictionary *codec_opts);
425
435void print_error(const char *filename, int err);
436
442void show_banner(int argc, char **argv, const OptionDef *options);
443
450int show_version(void *optctx, const char *opt, const char *arg);
451
457int show_buildconf(void *optctx, const char *opt, const char *arg);
458
464int show_license(void *optctx, const char *opt, const char *arg);
465
471int show_formats(void *optctx, const char *opt, const char *arg);
472
478int show_muxers(void *optctx, const char *opt, const char *arg);
479
485int show_demuxers(void *optctx, const char *opt, const char *arg);
486
492int show_devices(void *optctx, const char *opt, const char *arg);
493
494#if CONFIG_AVDEVICE
499int show_sinks(void *optctx, const char *opt, const char *arg);
500
505int show_sources(void *optctx, const char *opt, const char *arg);
506#endif
507
513int show_codecs(void *optctx, const char *opt, const char *arg);
514
519int show_decoders(void *optctx, const char *opt, const char *arg);
520
525int show_encoders(void *optctx, const char *opt, const char *arg);
526
532int show_filters(void *optctx, const char *opt, const char *arg);
533
539int show_bsfs(void *optctx, const char *opt, const char *arg);
540
546int show_protocols(void *optctx, const char *opt, const char *arg);
547
553int show_pix_fmts(void *optctx, const char *opt, const char *arg);
554
560int show_layouts(void *optctx, const char *opt, const char *arg);
561
566int show_sample_fmts(void *optctx, const char *opt, const char *arg);
567
572int show_colors(void *optctx, const char *opt, const char *arg);
573
578int read_yesno(void);
579
598FILE *get_preset_file(char *filename, size_t filename_size,
599 const char *preset_name, int is_path, const char *codec_name);
600
611void *grow_array(void *array, int elem_size, int *size, int new_size);
613#define media_type_string av_get_media_type_string
614
615#define GROW_ARRAY(array, nb_elems)\
616 array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
617
618#define GET_PIX_FMT_NAME(pix_fmt)\
619 const char *name = av_get_pix_fmt_name(pix_fmt);
620
621#define GET_CODEC_NAME(id)\
622 const char *name = avcodec_descriptor_get(id)->name;
623
624#define GET_SAMPLE_FMT_NAME(sample_fmt)\
625 const char *name = av_get_sample_fmt_name(sample_fmt)
626
627#define GET_SAMPLE_RATE_NAME(rate)\
628 char name[16];\
629 snprintf(name, sizeof(name), "%d", rate);
630
631#define GET_CH_LAYOUT_NAME(ch_layout)\
632 char name[16];\
633 snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
634
635#define GET_CH_LAYOUT_DESC(ch_layout)\
636 char name[128];\
637 av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
638
639double get_rotation(AVStream *st);
640
641#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
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)
__thread AVCodecContext * avcodec_opts[AVMEDIA_TYPE_NB]
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
int opt_cpucount(void *optctx, const char *opt, const char *arg)
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)
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))
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
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)
void * grow_array(void *array, int elem_size, int *size, int new_size)
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec)
__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)
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
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