fftools_cmdutils.h
Go to the documentation of this file.
/*
* Various utilities for command line tools
* copyright (c) 2003 Fabrice Bellard
*
* 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
*/
/*
* CHANGES 01.2020
* - ffprobe support changes
* - AV_LOG_STDERR introduced
*
* CHANGES 12.2019
* - Concurrent execution support
*
* CHANGES 03.2019
* --------------------------------------------------------
* - config.h include removed
*
* CHANGES 08.2018
* --------------------------------------------------------
* - fftools_ prefix added to file name and include guards
*
* CHANGES 07.2018
* --------------------------------------------------------
* - Include guards renamed
* - Unused headers removed
*/
#ifndef FFTOOLS_CMDUTILS_H
#define FFTOOLS_CMDUTILS_H
#include <stdint.h>
#include "libavcodec/avcodec.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "saf_wrapper.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 AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
extern __thread AVFormatContext *avformat_opts;
extern __thread AVDictionary *sws_dict;
extern __thread AVDictionary *swr_opts;
extern __thread AVDictionary *format_opts, *codec_opts, *resample_opts;
extern __thread int hide_banner;
extern __thread int find_stream_info;
void register_exit(void (*cb)(int ret));
void exit_program(int ret) av_noreturn;
void init_dynload(void);
void init_opts(void);
void uninit_opts(void);
void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
int opt_cpuflags(void *optctx, const char *opt, const char *arg);
int opt_default(void *optctx, const char *opt, const char *arg);
int opt_loglevel(void *optctx, const char *opt, const char *arg);
int opt_report(void *optctx, const char *opt, const char *arg);
int opt_max_alloc(void *optctx, const char *opt, const char *arg);
int opt_codec_debug(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 *class, int flags);
void show_help_default_ffmpeg(const char *opt, const char *arg);
void show_help_default_ffprobe(const char *opt, const char *arg);
int show_help(void *optctx, 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 *resample_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, 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 show_version(void *optctx, const char *opt, const char *arg);
int show_buildconf(void *optctx, const char *opt, const char *arg);
int show_license(void *optctx, const char *opt, const char *arg);
int show_formats(void *optctx, const char *opt, const char *arg);
int show_muxers(void *optctx, const char *opt, const char *arg);
int show_demuxers(void *optctx, const char *opt, const char *arg);
int show_devices(void *optctx, const char *opt, const char *arg);
#if CONFIG_AVDEVICE
int show_sinks(void *optctx, const char *opt, const char *arg);
int show_sources(void *optctx, const char *opt, const char *arg);
#endif
int show_codecs(void *optctx, const char *opt, const char *arg);
int show_decoders(void *optctx, const char *opt, const char *arg);
int show_encoders(void *optctx, const char *opt, const char *arg);
int show_filters(void *optctx, const char *opt, const char *arg);
int show_bsfs(void *optctx, const char *opt, const char *arg);
int show_protocols(void *optctx, const char *opt, const char *arg);
int show_pix_fmts(void *optctx, const char *opt, const char *arg);
int show_layouts(void *optctx, const char *opt, const char *arg);
int show_sample_fmts(void *optctx, const char *opt, const char *arg);
int show_colors(void *optctx, const char *opt, const char *arg);
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);
#define media_type_string av_get_media_type_string
#define GROW_ARRAY(array, nb_elems)\
array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
#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);
#define GET_CH_LAYOUT_NAME(ch_layout)\
char name[16];\
snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
#define GET_CH_LAYOUT_DESC(ch_layout)\
char name[128];\
av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
double get_rotation(AVStream *st);
#endif /* FFTOOLS_CMDUTILS_H */
swr_opts
__thread AVDictionary * swr_opts
Definition: fftools_cmdutils.c:102
show_decoders
int show_decoders(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1688
opt_loglevel
int opt_loglevel(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:914
show_help_children
void show_help_children(const AVClass *class, int flags)
Definition: fftools_cmdutils.c:239
codec_opts
__thread AVDictionary * codec_opts
Definition: fftools_cmdutils.h:79
opt_cpuflags
int opt_cpuflags(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:902
init_dynload
void init_dynload(void)
Definition: fftools_cmdutils.c:150
parse_option
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Definition: fftools_cmdutils.c:384
show_help
int show_help(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:2039
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:210
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:103
exit_program
void exit_program(int ret) av_noreturn
Definition: fftools_cmdutils.c:166
opt_default
int opt_default(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:583
print_error
void print_error(const char *filename, int err)
Definition: fftools_cmdutils.c:1131
opt_codec_debug
int opt_codec_debug(void *optctx, const char *opt, const char *arg)
show_filters
int show_filters(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1727
show_sample_fmts
int show_sample_fmts(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1850
read_yesno
int read_yesno(void)
Definition: fftools_cmdutils.c:2084
OptionParseContext
struct OptionParseContext OptionParseContext
SpecifierOpt
struct SpecifierOpt SpecifierOpt
avformat_opts
__thread AVFormatContext * avformat_opts
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:2095
show_muxers
int show_muxers(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1403
locate_option
int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
Definition: fftools_cmdutils.c:485
show_bsfs
int show_bsfs(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1700
grow_array
void * grow_array(void *array, int elem_size, int *size, int new_size)
Definition: fftools_cmdutils.c:2230
avcodec_opts
__thread AVCodecContext * avcodec_opts[AVMEDIA_TYPE_NB]
setup_find_stream_info_opts
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Definition: fftools_cmdutils.c:2210
check_stream_specifier
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Definition: fftools_cmdutils.c:2145
resample_opts
__thread AVDictionary * resample_opts
Definition: fftools_cmdutils.h:79
program_name
__thread char * program_name
Definition: fftools_cmdutils.c:98
show_layouts
int show_layouts(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1821
show_encoders
int show_encoders(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1694
show_version
int show_version(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1239
parse_loglevel
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Definition: fftools_cmdutils.c:544
program_birth_year
__thread int program_birth_year
Definition: fftools_cmdutils.c:99
uninit_parse_context
void uninit_parse_context(OptionParseContext *octx)
Definition: fftools_cmdutils.c:765
sws_dict
__thread AVDictionary * sws_dict
Definition: fftools_cmdutils.c:101
split_commandline
int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups)
Definition: fftools_cmdutils.c:791
get_rotation
double get_rotation(AVStream *st)
Definition: fftools_cmdutils.c:2249
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_ffmpeg_opt.c:207
show_banner
void show_banner(int argc, char **argv, const OptionDef *options)
Definition: fftools_cmdutils.c:1228
filter_codec_opts
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
Definition: fftools_cmdutils.c:2153
opt_timelimit
int opt_timelimit(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1118
show_license
int show_license(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1254
show_codecs
int show_codecs(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1593
show_buildconf
int show_buildconf(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1247
OptionGroupList
struct OptionGroupList OptionGroupList
parse_time_or_die
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Definition: fftools_cmdutils.c:198
register_exit
void register_exit(void(*cb)(int ret))
Definition: fftools_cmdutils.c:161
show_devices
int show_devices(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1413
Option
struct Option Option
OptionGroup
struct OptionGroup OptionGroup
uninit_opts
void uninit_opts(void)
Definition: fftools_cmdutils.c:121
show_formats
int show_formats(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1398
show_help_default_ffprobe
void show_help_default_ffprobe(const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3418
hide_banner
__thread int hide_banner
Definition: fftools_cmdutils.c:107
show_protocols
int show_protocols(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1712
parse_optgroup
int parse_optgroup(void *optctx, OptionGroup *g)
Definition: fftools_cmdutils.c:452
opt_max_alloc
int opt_max_alloc(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1104
OptionGroupDef
struct OptionGroupDef OptionGroupDef
opt_report
int opt_report(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1099
init_opts
void init_opts(void)
Definition: fftools_cmdutils.c:116
OptionDef
struct OptionDef OptionDef
show_colors
int show_colors(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1774
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:177
show_help_default_ffmpeg
void show_help_default_ffmpeg(const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3247
show_pix_fmts
int show_pix_fmts(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1788
show_demuxers
int show_demuxers(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1408
int
int
Definition: fftools_ffmpeg_filter.c:200
saf_wrapper.h
OptionDef
Definition: fftools_cmdutils.h:187
OptionDef::u
union OptionDef::@1 u
OptionDef::flags
int flags
Definition: fftools_cmdutils.h:189
OptionDef::off
size_t off
Definition: fftools_cmdutils.h:212
OptionDef::name
const char * name
Definition: fftools_cmdutils.h:188
OptionDef::argname
const char * argname
Definition: fftools_cmdutils.h:215
OptionDef::dst_ptr
void * dst_ptr
Definition: fftools_cmdutils.h:210
OptionDef::help
const char * help
Definition: fftools_cmdutils.h:214
OptionDef::func_arg
int(* func_arg)(void *, const char *, const char *)
Definition: fftools_cmdutils.h:211
OptionGroupDef
Definition: fftools_cmdutils.h:282
OptionGroupDef::name
const char * name
Definition: fftools_cmdutils.h:284
OptionGroupDef::sep
const char * sep
Definition: fftools_cmdutils.h:289
OptionGroupDef::flags
int flags
Definition: fftools_cmdutils.h:294
OptionGroup
Definition: fftools_cmdutils.h:297
OptionGroup::nb_opts
int nb_opts
Definition: fftools_cmdutils.h:302
OptionGroup::group_def
const OptionGroupDef * group_def
Definition: fftools_cmdutils.h:298
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: fftools_cmdutils.h:304
OptionGroup::swr_opts
AVDictionary * swr_opts
Definition: fftools_cmdutils.h:308
OptionGroup::opts
Option * opts
Definition: fftools_cmdutils.h:301
OptionGroup::sws_dict
AVDictionary * sws_dict
Definition: fftools_cmdutils.h:307
OptionGroup::arg
const char * arg
Definition: fftools_cmdutils.h:299
OptionGroup::format_opts
AVDictionary * format_opts
Definition: fftools_cmdutils.h:305
OptionGroup::resample_opts
AVDictionary * resample_opts
Definition: fftools_cmdutils.h:306
OptionGroupList
Definition: fftools_cmdutils.h:315
OptionGroupList::nb_groups
int nb_groups
Definition: fftools_cmdutils.h:319
OptionGroupList::groups
OptionGroup * groups
Definition: fftools_cmdutils.h:318
OptionGroupList::group_def
const OptionGroupDef * group_def
Definition: fftools_cmdutils.h:316
Option
Definition: fftools_cmdutils.h:276
Option::key
const char * key
Definition: fftools_cmdutils.h:278
Option::opt
const OptionDef * opt
Definition: fftools_cmdutils.h:277
Option::val
const char * val
Definition: fftools_cmdutils.h:279
OptionParseContext
Definition: fftools_cmdutils.h:322
OptionParseContext::global_opts
OptionGroup global_opts
Definition: fftools_cmdutils.h:323
OptionParseContext::nb_groups
int nb_groups
Definition: fftools_cmdutils.h:326
OptionParseContext::groups
OptionGroupList * groups
Definition: fftools_cmdutils.h:325
OptionParseContext::cur_group
OptionGroup cur_group
Definition: fftools_cmdutils.h:329
SpecifierOpt
Definition: fftools_cmdutils.h:175
SpecifierOpt::f
float f
Definition: fftools_cmdutils.h:182
SpecifierOpt::u
union SpecifierOpt::@0 u
SpecifierOpt::str
uint8_t * str
Definition: fftools_cmdutils.h:178
SpecifierOpt::i64
int64_t i64
Definition: fftools_cmdutils.h:180
SpecifierOpt::i
int i
Definition: fftools_cmdutils.h:179
SpecifierOpt::ui64
uint64_t ui64
Definition: fftools_cmdutils.h:181
SpecifierOpt::dbl
double dbl
Definition: fftools_cmdutils.h:183
SpecifierOpt::specifier
char * specifier
Definition: fftools_cmdutils.h:176