FFmpegKit iOS / macOS / tvOS API 6.0
Loading...
Searching...
No Matches
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 * copyright (c) 2018-2022 Taner Sener
5 * copyright (c) 2023 ARTHENICA LTD
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24/*
25 * This file is the modified version of cmdutils.h file living in ffmpeg source code under the fftools folder. We
26 * manually update it each time we depend on a new ffmpeg version. Below you can see the list of changes applied
27 * by us to develop mobile-ffmpeg and later ffmpeg-kit libraries.
28 *
29 * ffmpeg-kit changes by ARTHENICA LTD
30 *
31 * 07.2023
32 * --------------------------------------------------------
33 * - FFmpeg 6.0 changes migrated
34 *
35 * mobile-ffmpeg / ffmpeg-kit changes by Taner Sener
36 *
37 * 09.2022
38 * --------------------------------------------------------
39 * - config.h include added back
40 *
41 * 01.2020
42 * --------------------------------------------------------
43 * - ffprobe support added (variables used by ffprobe marked with "__thread" specifier)
44 * - AV_LOG_STDERR log level added
45 *
46 * 12.2019
47 * --------------------------------------------------------
48 * - concurrent execution support ("__thread" specifier added to variables used by multiple threads)
49 *
50 * 03.2019
51 * --------------------------------------------------------
52 * - config.h include removed
53 *
54 * 08.2018
55 * --------------------------------------------------------
56 * - fftools_ prefix added to file name and include guards
57 *
58 * 07.2018
59 * --------------------------------------------------------
60 * - include guards renamed
61 * - unused headers removed
62 */
63
64#ifndef FFTOOLS_CMDUTILS_H
65#define FFTOOLS_CMDUTILS_H
66
67#include <stdint.h>
68
69#include "config.h"
70#include "libavcodec/avcodec.h"
71#include "libavfilter/avfilter.h"
72#include "libavformat/avformat.h"
73#include "libswscale/swscale.h"
74
75#ifdef _WIN32
76#undef main /* We don't want SDL to override our main() */
77#endif
78
82#define AV_LOG_STDERR -16
83
87extern __thread char *program_name;
88
92extern __thread int program_birth_year;
93
94extern __thread AVDictionary *sws_dict;
95extern __thread AVDictionary *swr_opts;
96extern __thread AVDictionary *format_opts, *codec_opts;
97extern __thread int hide_banner;
98extern __thread int find_stream_info;
99
103void register_exit(void (*cb)(int ret));
104
114void report_and_exit(int ret) av_noreturn;
115
119void exit_program(int ret) av_noreturn;
120
124void init_dynload(void);
125
130void uninit_opts(void);
131
136void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
137
142int opt_default(void *optctx, const char *opt, const char *arg);
143
147int opt_timelimit(void *optctx, const char *opt, const char *arg);
148
162double parse_number_or_die(const char *context, const char *numstr, int type,
163 double min, double max);
164
179int64_t parse_time_or_die(const char *context, const char *timestr,
180 int is_duration);
181
182typedef struct SpecifierOpt {
183 char *specifier;
184 union {
185 uint8_t *str;
186 int i;
187 int64_t i64;
188 uint64_t ui64;
189 float f;
190 double dbl;
191 } u;
193
194typedef struct OptionDef {
195 const char *name;
196 int flags;
197#define HAS_ARG 0x0001
198#define OPT_BOOL 0x0002
199#define OPT_EXPERT 0x0004
200#define OPT_STRING 0x0008
201#define OPT_VIDEO 0x0010
202#define OPT_AUDIO 0x0020
203#define OPT_INT 0x0080
204#define OPT_FLOAT 0x0100
205#define OPT_SUBTITLE 0x0200
206#define OPT_INT64 0x0400
207#define OPT_EXIT 0x0800
208#define OPT_DATA 0x1000
209#define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only).
210 implied by OPT_OFFSET or OPT_SPEC */
211#define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
212#define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
213 Implies OPT_OFFSET. Next element after the offset is
214 an int containing element count in the array. */
215#define OPT_TIME 0x10000
216#define OPT_DOUBLE 0x20000
217#define OPT_INPUT 0x40000
218#define OPT_OUTPUT 0x80000
219 union {
220 void *dst_ptr;
221 int (*func_arg)(void *, const char *, const char *);
222 size_t off;
223 } u;
224 const char *help;
225 const char *argname;
226} OptionDef;
227
237void show_help_options(const OptionDef *options, const char *msg, int req_flags,
238 int rej_flags, int alt_flags);
239
244void show_help_children(const AVClass *clazz, int flags);
245
250void show_help_default_ffmpeg(const char *opt, const char *arg);
251void show_help_default_ffprobe(const char *opt, const char *arg);
252
265void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
266 void (* parse_arg_function)(void *optctx, const char*));
267
273int parse_option(void *optctx, const char *opt, const char *arg,
274 const OptionDef *options);
275
281typedef struct Option {
283 const char *key;
284 const char *val;
285} Option;
287typedef struct OptionGroupDef {
289 const char *name;
294 const char *sep;
299 int flags;
302typedef struct OptionGroup {
304 const char *arg;
305
309 AVDictionary *codec_opts;
310 AVDictionary *format_opts;
311 AVDictionary *sws_dict;
312 AVDictionary *swr_opts;
314
319typedef struct OptionGroupList {
325
326typedef struct OptionParseContext {
328
332 /* parsing state */
335
342int parse_optgroup(void *optctx, OptionGroup *g);
343
362int split_commandline(OptionParseContext *octx, int argc, char *argv[],
363 const OptionDef *options,
364 const OptionGroupDef *groups, int nb_groups);
365
370
374void parse_loglevel(int argc, char **argv, const OptionDef *options);
375
379int locate_option(int argc, char **argv, const OptionDef *options,
380 const char *optname);
381
391int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
392
407AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
408 AVFormatContext *s, AVStream *st, const AVCodec *codec);
409
421AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
422 AVDictionary *codec_opts);
423
433void print_error(const char *filename, int err);
434
440void show_banner(int argc, char **argv, const OptionDef *options);
441
446int read_yesno(void);
447
466FILE *get_preset_file(char *filename, size_t filename_size,
467 const char *preset_name, int is_path, const char *codec_name);
468
479void *grow_array(void *array, int elem_size, int *size, int new_size);
480
493void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
494
495#define GROW_ARRAY(array, nb_elems)\
496 array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
497
498#define ALLOC_ARRAY_ELEM(array, nb_elems)\
499 allocate_array_elem(&array, sizeof(*array[0]), &nb_elems)
500
501#define GET_PIX_FMT_NAME(pix_fmt)\
502 const char *name = av_get_pix_fmt_name(pix_fmt);
503
504#define GET_CODEC_NAME(id)\
505 const char *name = avcodec_descriptor_get(id)->name;
506
507#define GET_SAMPLE_FMT_NAME(sample_fmt)\
508 const char *name = av_get_sample_fmt_name(sample_fmt)
509
510#define GET_SAMPLE_RATE_NAME(rate)\
511 char name[16];\
512 snprintf(name, sizeof(name), "%d", rate);
513
514double get_rotation(int32_t *displaymatrix);
515
516#endif /* FFTOOLS_CMDUTILS_H */
__thread AVDictionary * swr_opts
__thread AVDictionary * codec_opts
void init_dynload(void)
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
void report_and_exit(int ret) av_noreturn
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)
double get_rotation(int32_t *displaymatrix)
int read_yesno(void)
int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
__thread char * program_name
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)
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)
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)
void uninit_opts(void)
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 parse_optgroup(void *optctx, OptionGroup *g)
void * allocate_array_elem(void *array, size_t elem_size, int *nb_elems)
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)
void show_help_children(const AVClass *clazz, int flags)
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
static const OptionGroupDef groups[]
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 OptionGroupDef * group_def
AVDictionary * codec_opts
AVDictionary * swr_opts
AVDictionary * sws_dict
const char * arg
AVDictionary * format_opts
OptionGroup * groups
const OptionGroupDef * group_def
const char * key
const OptionDef * opt
const char * val
OptionGroupList * groups
union SpecifierOpt::@0 u