FFmpegKit iOS / macOS / tvOS API 5.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 * copyright (c) 2018 Taner Sener ( tanersener gmail com )
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/*
24 * This file is the modified version of cmdutils.h file living in ffmpeg source code under the fftools folder. We
25 * manually update it each time we depend on a new ffmpeg version. Below you can see the list of changes applied
26 * by us to develop mobile-ffmpeg and later ffmpeg-kit libraries.
27 *
28 * mobile-ffmpeg / ffmpeg-kit changes by Taner Sener
29 *
30 * 09.2022
31 * --------------------------------------------------------
32 * - config.h include added back
33 *
34 * 01.2020
35 * --------------------------------------------------------
36 * - ffprobe support added (variables used by ffprobe marked with "__thread" specifier)
37 * - AV_LOG_STDERR log level added
38 *
39 * 12.2019
40 * --------------------------------------------------------
41 * - concurrent execution support ("__thread" specifier added to variables used by multiple threads)
42 *
43 * 03.2019
44 * --------------------------------------------------------
45 * - config.h include removed
46 *
47 * 08.2018
48 * --------------------------------------------------------
49 * - fftools_ prefix added to file name and include guards
50 *
51 * 07.2018
52 * --------------------------------------------------------
53 * - include guards renamed
54 * - unused headers removed
55 */
56
57#ifndef FFTOOLS_CMDUTILS_H
58#define FFTOOLS_CMDUTILS_H
59
60#include <stdint.h>
61
62#include "config.h"
63#include "libavcodec/avcodec.h"
64#include "libavfilter/avfilter.h"
65#include "libavformat/avformat.h"
66#include "libswscale/swscale.h"
67
68#ifdef _WIN32
69#undef main /* We don't want SDL to override our main() */
70#endif
71
75#define AV_LOG_STDERR -16
76
80extern __thread char *program_name;
81
85extern __thread int program_birth_year;
86
87extern __thread AVDictionary *sws_dict;
88extern __thread AVDictionary *swr_opts;
89extern __thread AVDictionary *format_opts, *codec_opts;
90extern __thread int hide_banner;
91extern __thread int find_stream_info;
92
96void register_exit(void (*cb)(int ret));
97
101void exit_program(int ret) av_noreturn;
102
106void init_dynload(void);
107
112void uninit_opts(void);
113
118void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
119
124int opt_default(void *optctx, const char *opt, const char *arg);
125
129int opt_timelimit(void *optctx, const char *opt, const char *arg);
130
144double parse_number_or_die(const char *context, const char *numstr, int type,
145 double min, double max);
146
161int64_t parse_time_or_die(const char *context, const char *timestr,
162 int is_duration);
163
164typedef struct SpecifierOpt {
165 char *specifier;
166 union {
167 uint8_t *str;
168 int i;
169 int64_t i64;
170 uint64_t ui64;
171 float f;
172 double dbl;
173 } u;
175
176typedef struct OptionDef {
177 const char *name;
178 int flags;
179#define HAS_ARG 0x0001
180#define OPT_BOOL 0x0002
181#define OPT_EXPERT 0x0004
182#define OPT_STRING 0x0008
183#define OPT_VIDEO 0x0010
184#define OPT_AUDIO 0x0020
185#define OPT_INT 0x0080
186#define OPT_FLOAT 0x0100
187#define OPT_SUBTITLE 0x0200
188#define OPT_INT64 0x0400
189#define OPT_EXIT 0x0800
190#define OPT_DATA 0x1000
191#define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only).
192 implied by OPT_OFFSET or OPT_SPEC */
193#define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
194#define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
195 Implies OPT_OFFSET. Next element after the offset is
196 an int containing element count in the array. */
197#define OPT_TIME 0x10000
198#define OPT_DOUBLE 0x20000
199#define OPT_INPUT 0x40000
200#define OPT_OUTPUT 0x80000
201 union {
202 void *dst_ptr;
203 int (*func_arg)(void *, const char *, const char *);
204 size_t off;
205 } u;
206 const char *help;
207 const char *argname;
208} OptionDef;
209
219void show_help_options(const OptionDef *options, const char *msg, int req_flags,
220 int rej_flags, int alt_flags);
221
226void show_help_children(const AVClass *clazz, int flags);
227
232void show_help_default_ffmpeg(const char *opt, const char *arg);
233void show_help_default_ffprobe(const char *opt, const char *arg);
234
238int show_help(void *optctx, const char *opt, const char *arg);
239
252void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
253 void (* parse_arg_function)(void *optctx, const char*));
254
260int parse_option(void *optctx, const char *opt, const char *arg,
261 const OptionDef *options);
262
268typedef struct Option {
270 const char *key;
271 const char *val;
272} Option;
274typedef struct OptionGroupDef {
276 const char *name;
281 const char *sep;
286 int flags;
289typedef struct OptionGroup {
291 const char *arg;
292
296 AVDictionary *codec_opts;
297 AVDictionary *format_opts;
298 AVDictionary *sws_dict;
299 AVDictionary *swr_opts;
301
306typedef struct OptionGroupList {
312
313typedef struct OptionParseContext {
315
319 /* parsing state */
322
329int parse_optgroup(void *optctx, OptionGroup *g);
330
349int split_commandline(OptionParseContext *octx, int argc, char *argv[],
350 const OptionDef *options,
351 const OptionGroupDef *groups, int nb_groups);
352
357
361void parse_loglevel(int argc, char **argv, const OptionDef *options);
362
366int locate_option(int argc, char **argv, const OptionDef *options,
367 const char *optname);
368
378int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
379
394AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
395 AVFormatContext *s, AVStream *st, const AVCodec *codec);
396
408AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
409 AVDictionary *codec_opts);
410
420void print_error(const char *filename, int err);
421
427void show_banner(int argc, char **argv, const OptionDef *options);
428
433int read_yesno(void);
434
453FILE *get_preset_file(char *filename, size_t filename_size,
454 const char *preset_name, int is_path, const char *codec_name);
455
466void *grow_array(void *array, int elem_size, int *size, int new_size);
467
480void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
481
482#define GROW_ARRAY(array, nb_elems)\
483 array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
484
485#define ALLOC_ARRAY_ELEM(array, nb_elems)\
486 allocate_array_elem(&array, sizeof(*array[0]), &nb_elems)
487
488#define GET_PIX_FMT_NAME(pix_fmt)\
489 const char *name = av_get_pix_fmt_name(pix_fmt);
490
491#define GET_CODEC_NAME(id)\
492 const char *name = avcodec_descriptor_get(id)->name;
493
494#define GET_SAMPLE_FMT_NAME(sample_fmt)\
495 const char *name = av_get_sample_fmt_name(sample_fmt)
496
497#define GET_SAMPLE_RATE_NAME(rate)\
498 char name[16];\
499 snprintf(name, sizeof(name), "%d", rate);
500
501double get_rotation(int32_t *displaymatrix);
502
503#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)
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)
double get_rotation(int32_t *displaymatrix)
int read_yesno(void)
struct OptionParseContext OptionParseContext
struct SpecifierOpt SpecifierOpt
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)
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)
struct Option Option
struct OptionGroup OptionGroup
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)
struct OptionGroupDef OptionGroupDef
void * allocate_array_elem(void *array, size_t elem_size, int *nb_elems)
struct OptionDef OptionDef
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 char * sep
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