使用ffmpeg都是使用命令的。实际使用中,命令都会很长,为了解析这些命令,一般都会通过将命令分组。将命令分组,一来方便解析,二来方便管理。
那么,内部机制中是如何对命令进行分组的?下面简单分析ffmpeg的命令分组机制。
ffmpeg一般情况下,将命令分成三组(如果细分的话,还有一个分类AVDictionary ):
1.全局 —–如:-filter_complex -loglevel
2.输入源相关的设置
3.输出源相关的设置
static const OptionGroupDef global_group = { "global" };
static const OptionGroupDef groups[] = {
[GROUP_OUTFILE] = { "output file", NULL, OPT_OUTPUT },
[GROUP_INFILE] = { "input file", "i", OPT_INPUT },
};
AVDictionary *codec_opts;
AVDictionary *format_opts;
AVDictionary *resample_opts;
AVDictionary *sws_dict;
AVDictionary *swr_opts;
这个分类涉及到目录libavcodec和libavformat下的文件options_table.h以及其它参数
libavcodec/options_table.h—->static const AVOption avcodec_options[]
libavformat/options_table.h—->static const AVOption static const AVOption avformat_options[]
这个两个数组保存着与编解码和封装相关的参数设置
下面简单分析split_commandline是如何给命令进行分组的:
int split_commandline(OptionParseContext *octx, int argc, char *argv[],
const OptionDef *options,
const OptionGroupDef *groups, int nb_groups) //nb_groups = 2
{
int optindex = 1;
int dashdash = -2;
/* perform system-dependent conversions for arguments list */
prepare_app_arguments(&argc, &argv);
/*基本的内存分配
*OptionGroupDef 与OptionParseContext建立联系
*/
init_parse_context(octx, groups, nb_groups);
av_log(NULL, AV_LOG

ffmpeg命令通常较长,通过分组便于解析和管理。主要分为全局、输入源和输出源三组,涉及libavcodec和libavformat的options_table.h。split_commandline函数负责分组,find_option查找匹配命令,add_opt根据参数属性分类,存入OptionGroup结构体。-i标志指示输入源分组,后续为输出源分组。
最低0.47元/天 解锁文章
5436

被折叠的 条评论
为什么被折叠?



