Loading...
Searching...
No Matches
fftools_cmdutils.h
Go to the documentation of this file.
/*
* Various utilities for command line tools
* copyright (c) 2003 Fabrice Bellard
* copyright (c) 2018-2022 Taner Sener
* copyright (c) 2023 ARTHENICA LTD
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* This file is the modified version of cmdutils.h file living in ffmpeg source code under the fftools folder. We
* manually update it each time we depend on a new ffmpeg version. Below you can see the list of changes applied
* by us to develop mobile-ffmpeg and later ffmpeg-kit libraries.
*
* ffmpeg-kit changes by ARTHENICA LTD
*
* 07.2023
* --------------------------------------------------------
* - FFmpeg 6.0 changes migrated
*
* mobile-ffmpeg / ffmpeg-kit changes by Taner Sener
*
* 09.2022
* --------------------------------------------------------
* - config.h include added back
*
* 01.2020
* --------------------------------------------------------
* - ffprobe support added (variables used by ffprobe marked with "__thread" specifier)
* - AV_LOG_STDERR log level added
*
* 12.2019
* --------------------------------------------------------
* - concurrent execution support ("__thread" specifier added to variables used by multiple threads)
*
* 03.2019
* --------------------------------------------------------
* - config.h include removed
*
* 08.2018
* --------------------------------------------------------
* - fftools_ prefix added to file name and include guards
*
* 07.2018
* --------------------------------------------------------
* - include guards renamed
* - unused headers removed
*/
#ifndef FFTOOLS_CMDUTILS_H
#define FFTOOLS_CMDUTILS_H
#include <stdint.h>
#include "config.h"
#include "libavcodec/avcodec.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#ifdef _WIN32
#undef main /* We don't want SDL to override our main() */
#endif
#define AV_LOG_STDERR -16
extern __thread char *program_name;
extern __thread int program_birth_year;
extern __thread AVDictionary *sws_dict;
extern __thread AVDictionary *swr_opts;
extern __thread AVDictionary *format_opts, *codec_opts;
extern __thread int hide_banner;
extern __thread int find_stream_info;
void register_exit(void (*cb)(int ret));
void report_and_exit(int ret) av_noreturn;
void exit_program(int ret) av_noreturn;
void init_dynload(void);
void uninit_opts(void);
void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
int opt_default(void *optctx, const char *opt, const char *arg);
int opt_timelimit(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);
int64_t parse_time_or_die(const char *context, const char *timestr,
int is_duration);
typedef struct SpecifierOpt {
char *specifier;
union {
uint8_t *str;
int i;
int64_t i64;
uint64_t ui64;
float f;
double dbl;
} u;
} SpecifierOpt;
typedef struct OptionDef {
const char *name;
int flags;
#define HAS_ARG 0x0001
#define OPT_BOOL 0x0002
#define OPT_EXPERT 0x0004
#define OPT_STRING 0x0008
#define OPT_VIDEO 0x0010
#define OPT_AUDIO 0x0020
#define OPT_INT 0x0080
#define OPT_FLOAT 0x0100
#define OPT_SUBTITLE 0x0200
#define OPT_INT64 0x0400
#define OPT_EXIT 0x0800
#define OPT_DATA 0x1000
#define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only).
implied by OPT_OFFSET or OPT_SPEC */
#define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
#define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
Implies OPT_OFFSET. Next element after the offset is
an int containing element count in the array. */
#define OPT_TIME 0x10000
#define OPT_DOUBLE 0x20000
#define OPT_INPUT 0x40000
#define OPT_OUTPUT 0x80000
union {
void *dst_ptr;
int (*func_arg)(void *, const char *, const char *);
size_t off;
} u;
const char *help;
const char *argname;
} OptionDef;
void show_help_options(const OptionDef *options, const char *msg, int req_flags,
int rej_flags, int alt_flags);
void show_help_children(const AVClass *clazz, int flags);
void show_help_default_ffmpeg(const char *opt, const char *arg);
void show_help_default_ffprobe(const char *opt, const char *arg);
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
void (* parse_arg_function)(void *optctx, const char*));
int parse_option(void *optctx, const char *opt, const char *arg,
const OptionDef *options);
typedef struct Option {
const OptionDef *opt;
const char *key;
const char *val;
} Option;
typedef struct OptionGroupDef {
const char *name;
const char *sep;
int flags;
} OptionGroupDef;
typedef struct OptionGroup {
const OptionGroupDef *group_def;
const char *arg;
Option *opts;
int nb_opts;
AVDictionary *codec_opts;
AVDictionary *format_opts;
AVDictionary *sws_dict;
AVDictionary *swr_opts;
} OptionGroup;
typedef struct OptionGroupList {
const OptionGroupDef *group_def;
OptionGroup *groups;
int nb_groups;
} OptionGroupList;
typedef struct OptionParseContext {
OptionGroup global_opts;
OptionGroupList *groups;
int nb_groups;
/* parsing state */
OptionGroup cur_group;
} OptionParseContext;
int parse_optgroup(void *optctx, OptionGroup *g);
int split_commandline(OptionParseContext *octx, int argc, char *argv[],
const OptionDef *options,
const OptionGroupDef *groups, int nb_groups);
void uninit_parse_context(OptionParseContext *octx);
void parse_loglevel(int argc, char **argv, const OptionDef *options);
int locate_option(int argc, char **argv, const OptionDef *options,
const char *optname);
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
AVFormatContext *s, AVStream *st, const AVCodec *codec);
AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
AVDictionary *codec_opts);
void print_error(const char *filename, int err);
void show_banner(int argc, char **argv, const OptionDef *options);
int read_yesno(void);
FILE *get_preset_file(char *filename, size_t filename_size,
const char *preset_name, int is_path, const char *codec_name);
void *grow_array(void *array, int elem_size, int *size, int new_size);
void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
#define GROW_ARRAY(array, nb_elems)\
array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
#define ALLOC_ARRAY_ELEM(array, nb_elems)\
allocate_array_elem(&array, sizeof(*array[0]), &nb_elems)
#define GET_PIX_FMT_NAME(pix_fmt)\
const char *name = av_get_pix_fmt_name(pix_fmt);
#define GET_CODEC_NAME(id)\
const char *name = avcodec_descriptor_get(id)->name;
#define GET_SAMPLE_FMT_NAME(sample_fmt)\
const char *name = av_get_sample_fmt_name(sample_fmt)
#define GET_SAMPLE_RATE_NAME(rate)\
char name[16];\
snprintf(name, sizeof(name), "%d", rate);
double get_rotation(int32_t *displaymatrix);
#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