在ffmpeg.c中解析命令行的函数是ffmpeg_parse_options,此函数中主要对命令行参数解析的函数为split_commandline,首先看一下函数相关的几个重要的结构体
OptionParseContext octx,用来存储被解析后的数据,全局参数,输入输出参数
typedef struct OptionParseContext {
OptionGroup global_opts;
OptionGroupList *groups;
int nb_groups;
/* parsing state */
OptionGroup cur_group;
} OptionParseContext;
options定义在ffmpeg.c中
const OptionDef options[] = {
/* main options */
CMDUTILS_COMMON_OPTIONS
{ "f", HAS_ARG | OPT_STRING | OPT_OFFSET |
OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(format) },
"force format", "fmt" },
{ "y", OPT_BOOL, { &file_overwrite },
"overwrite output files" },
{ "n", OPT_BOOL, { &no_file_overwrite },
"never overwrite output files" },
{ "ignore_unknown", OPT_BOOL, { &ignore_unknown_streams },
"Ignore unknown stream types" },
{ "copy_unknown", OPT_BOOL | OPT_EXPERT, { ©_unknown_streams },
"Copy unknown stream types" },
typedef struct OptionDef {
const char *name;
int flags;
...
#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. */
...//省略一部分flags宏定义
union {
void *dst_ptr;
int (*func_arg)(void *, const char *, const char *);
size_t off;
} u;
const char *help;
const char *argname;
} OptionD