| FFmpegKit Android 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
87 extern __thread char *program_name;
88
92 extern __thread int program_birth_year;
93
94 extern __thread AVDictionary *sws_dict;
95 extern __thread AVDictionary *swr_opts;
96 extern __thread AVDictionary *format_opts, *codec_opts;
97 extern __thread int hide_banner;
98 extern __thread int find_stream_info;
99
103 void register_exit(void (*cb)(int ret));
104
114 void report_and_exit(int ret) av_noreturn;
115
119 void exit_program(int ret) av_noreturn;
120
124 void init_dynload(void);
125
130 void uninit_opts(void);
131
136 void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
137
142 int opt_default(void *optctx, const char *opt, const char *arg);
143
147 int opt_timelimit(void *optctx, const char *opt, const char *arg);
148
162 double 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
182 typedef 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;
192} SpecifierOpt;
193
194 typedef 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
237 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
238 int rej_flags, int alt_flags);
239
244 void show_help_children(const AVClass *clazz, int flags);
245
250 void show_help_default_ffmpeg(const char *opt, const char *arg);
251 void show_help_default_ffprobe(const char *opt, const char *arg);
252
265 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
266 void (* parse_arg_function)(void *optctx, const char*));
267
273 int parse_option(void *optctx, const char *opt, const char *arg,
274 const OptionDef *options);
275
281 typedef struct Option {
282 const OptionDef *opt;
283 const char *key;
284 const char *val;
285} Option;
286
287 typedef struct OptionGroupDef {
289 const char *name;
294 const char *sep;
299 int flags;
300} OptionGroupDef;
301
302 typedef struct OptionGroup {
303 const OptionGroupDef *group_def;
304 const char *arg;
305
306 Option *opts;
307 int nb_opts;
308
309 AVDictionary *codec_opts;
310 AVDictionary *format_opts;
311 AVDictionary *sws_dict;
312 AVDictionary *swr_opts;
313} OptionGroup;
314
319 typedef struct OptionGroupList {
320 const OptionGroupDef *group_def;
321
322 OptionGroup *groups;
323 int nb_groups;
324} OptionGroupList;
325
326 typedef struct OptionParseContext {
327 OptionGroup global_opts;
328
329 OptionGroupList *groups;
330 int nb_groups;
331
332 /* parsing state */
333 OptionGroup cur_group;
334} OptionParseContext;
335
342 int parse_optgroup(void *optctx, OptionGroup *g);
343
362 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
363 const OptionDef *options,
364 const OptionGroupDef *groups, int nb_groups);
365
369 void uninit_parse_context(OptionParseContext *octx);
370
374 void parse_loglevel(int argc, char **argv, const OptionDef *options);
375
379 int locate_option(int argc, char **argv, const OptionDef *options,
380 const char *optname);
381
391 int 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
433 void print_error(const char *filename, int err);
434
440 void show_banner(int argc, char **argv, const OptionDef *options);
441
446 int 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
479 void *grow_array(void *array, int elem_size, int *size, int new_size);
480
493 void *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
514 double get_rotation(int32_t *displaymatrix);
515
516#endif /* FFTOOLS_CMDUTILS_H */
swr_opts
__thread AVDictionary * swr_opts
Definition fftools_cmdutils.c:109
codec_opts
__thread AVDictionary * codec_opts
Definition fftools_cmdutils.h:96
init_dynload
void init_dynload(void)
Definition fftools_cmdutils.c:123
parse_option
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Definition fftools_cmdutils.c:362
report_and_exit
void report_and_exit(int ret) av_noreturn
Definition fftools_cmdutils.c:139
show_help_options
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Definition fftools_cmdutils.c:190
parse_options
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *optctx, const char *))
format_opts
__thread AVDictionary * format_opts
Definition fftools_cmdutils.c:110
exit_program
void exit_program(int ret) av_noreturn
Definition fftools_cmdutils.c:145
opt_default
int opt_default(void *optctx, const char *opt, const char *arg)
Definition fftools_cmdutils.c:570
print_error
void print_error(const char *filename, int err)
Definition fftools_cmdutils.c:858
get_rotation
double get_rotation(int32_t *displaymatrix)
Definition fftools_cmdutils.c:1056
read_yesno
int read_yesno(void)
Definition fftools_cmdutils.c:863
locate_option
int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
Definition fftools_cmdutils.c:469
check_stream_specifier
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Definition fftools_cmdutils.c:946
program_name
__thread char * program_name
Definition fftools_cmdutils.c:105
parse_loglevel
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Definition fftools_cmdutils.c:528
program_birth_year
__thread int program_birth_year
Definition fftools_cmdutils.c:106
uninit_parse_context
void uninit_parse_context(OptionParseContext *octx)
Definition fftools_cmdutils.c:722
sws_dict
__thread AVDictionary * sws_dict
Definition fftools_cmdutils.c:108
split_commandline
int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups)
Definition fftools_cmdutils.c:747
log_callback_help
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
find_stream_info
__thread int find_stream_info
Definition fftools_ffprobe.c:176
show_banner
void show_banner(int argc, char **argv, const OptionDef *options)
Definition fftools_opt_common.c:262
opt_timelimit
int opt_timelimit(void *optctx, const char *opt, const char *arg)
Definition fftools_ffmpeg_opt.c:1380
parse_time_or_die
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Definition fftools_cmdutils.c:178
register_exit
void register_exit(void(*cb)(int ret))
Definition fftools_cmdutils.c:134
get_preset_file
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
Definition fftools_cmdutils.c:874
uninit_opts
void uninit_opts(void)
Definition fftools_cmdutils.c:115
show_help_default_ffprobe
void show_help_default_ffprobe(const char *opt, const char *arg)
Definition fftools_ffprobe.c:3797
grow_array
void * grow_array(void *array, int elem_size, int *size, int new_size)
Definition fftools_cmdutils.c:1029
filter_codec_opts
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec)
Definition fftools_cmdutils.c:954
hide_banner
__thread int hide_banner
Definition fftools_cmdutils.c:112
parse_optgroup
int parse_optgroup(void *optctx, OptionGroup *g)
Definition fftools_cmdutils.c:436
allocate_array_elem
void * allocate_array_elem(void *array, size_t elem_size, int *nb_elems)
Definition fftools_cmdutils.c:1046
parse_number_or_die
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
Definition fftools_cmdutils.c:157
show_help_default_ffmpeg
void show_help_default_ffmpeg(const char *opt, const char *arg)
Definition fftools_ffmpeg_opt.c:1179
show_help_children
void show_help_children(const AVClass *clazz, int flags)
Definition fftools_cmdutils.c:219
setup_find_stream_info_opts
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Definition fftools_cmdutils.c:1012
int
int
Definition fftools_ffmpeg_filter.c:180
groups
static const OptionGroupDef groups[]
Definition fftools_ffmpeg_opt.c:1264
OptionDef
Definition fftools_cmdutils.h:194
OptionDef::u
union OptionDef::@1 u
OptionDef::flags
int flags
Definition fftools_cmdutils.h:196
OptionDef::off
size_t off
Definition fftools_cmdutils.h:219
OptionDef::name
const char * name
Definition fftools_cmdutils.h:195
OptionDef::argname
const char * argname
Definition fftools_cmdutils.h:222
OptionDef::dst_ptr
void * dst_ptr
Definition fftools_cmdutils.h:217
OptionDef::help
const char * help
Definition fftools_cmdutils.h:221
OptionDef::func_arg
int(* func_arg)(void *, const char *, const char *)
Definition fftools_cmdutils.h:218
OptionGroupDef
Definition fftools_cmdutils.h:284
OptionGroupDef::name
const char * name
Definition fftools_cmdutils.h:286
OptionGroupDef::sep
const char * sep
Definition fftools_cmdutils.h:291
OptionGroupDef::flags
int flags
Definition fftools_cmdutils.h:296
OptionGroup
Definition fftools_cmdutils.h:299
OptionGroup::nb_opts
int nb_opts
Definition fftools_cmdutils.h:304
OptionGroup::group_def
const OptionGroupDef * group_def
Definition fftools_cmdutils.h:300
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition fftools_cmdutils.h:306
OptionGroup::swr_opts
AVDictionary * swr_opts
Definition fftools_cmdutils.h:309
OptionGroup::opts
Option * opts
Definition fftools_cmdutils.h:303
OptionGroup::sws_dict
AVDictionary * sws_dict
Definition fftools_cmdutils.h:308
OptionGroup::arg
const char * arg
Definition fftools_cmdutils.h:301
OptionGroup::format_opts
AVDictionary * format_opts
Definition fftools_cmdutils.h:307
OptionGroupList
Definition fftools_cmdutils.h:316
OptionGroupList::nb_groups
int nb_groups
Definition fftools_cmdutils.h:320
OptionGroupList::groups
OptionGroup * groups
Definition fftools_cmdutils.h:319
OptionGroupList::group_def
const OptionGroupDef * group_def
Definition fftools_cmdutils.h:317
Option
Definition fftools_cmdutils.h:278
Option::key
const char * key
Definition fftools_cmdutils.h:280
Option::opt
const OptionDef * opt
Definition fftools_cmdutils.h:279
Option::val
const char * val
Definition fftools_cmdutils.h:281
OptionParseContext
Definition fftools_cmdutils.h:323
OptionParseContext::global_opts
OptionGroup global_opts
Definition fftools_cmdutils.h:324
OptionParseContext::nb_groups
int nb_groups
Definition fftools_cmdutils.h:327
OptionParseContext::groups
OptionGroupList * groups
Definition fftools_cmdutils.h:326
OptionParseContext::cur_group
OptionGroup cur_group
Definition fftools_cmdutils.h:330
SpecifierOpt
Definition fftools_cmdutils.h:182
SpecifierOpt::f
float f
Definition fftools_cmdutils.h:189
SpecifierOpt::u
union SpecifierOpt::@0 u
SpecifierOpt::str
uint8_t * str
Definition fftools_cmdutils.h:185
SpecifierOpt::i64
int64_t i64
Definition fftools_cmdutils.h:187
SpecifierOpt::i
int i
Definition fftools_cmdutils.h:186
SpecifierOpt::ui64
uint64_t ui64
Definition fftools_cmdutils.h:188
SpecifierOpt::dbl
double dbl
Definition fftools_cmdutils.h:190
SpecifierOpt::specifier
char * specifier
Definition fftools_cmdutils.h:183