ffmpeg源码解读,一站

1.AVFormatContext(IO格式上下文,用于读写)

      avformat_alloc_context 分配一个结构AVFormatContext。
      avformat_alloc_context调用avformat_get_context_defaults来初始化AVFormatContext。
      avformat_get_context_defaults 填充了 av_class,io_open,io_close字段。最后调用                            av_opt_set_defaults来填充option。

  static const AVClass av_format_context_class= {
    .class_name     = "AVFormatContext",
    .item_name      = format_to_name,
    .option         = avformat_options,
    .version        = LIBAVUTIL_VERSION_INT,
    .child_next     = format_child_next,
    .child_class_next = format_child_class_next,
    .category       = AV_CLASS_CATEGORY_MUXER,
    .get_category   = get_category,
}

avformat_options的定义在libavformat/options_table.h中。

static void avformat_get_context_defaults(AVFormatContext *s)
{
    memset(s, 0, sizeof(AVFormatContext)); 
    s->av_class = &av_format_context_class;
    s->io_open  = io_open_default;
    s->io_close = io_close_default;  
    av_opt_set_defaults(s);
 }

v_opt_set_defaults。调用了av_opt_set_defaults2;

av_opt_set_defaults2调用av_opt_next来进行分析,如果存在,这返回option。(AVOption可以包含名称,简短的帮助信息,取值等等)

const AVOption *av_opt_next(const void *obj, const AVOption *last)
{
     const AVClass *class;
       if (!obj)
            return NULL;
        class = *(const AVClass**)obj;(obj指向对象的字段)
        if (!last && class && class->option && class->option[0].name)
             return class->option;
        if (last && last[1].name)
            return ++last;
           return NULL;

}

2. 打开文件函数 avformat_open_input:模块 libavformat/utils.c

声明:int avformat_open_input(AVFormatContext **ps, const char *filename,AVInputFormat *fmt, AVDictionary **options)

     如果按照默认调用

     avformat_open_input调用 init_input ,init_input会调用AVFormatContext的io_open。

如果options!=NULL

     调用av_opt_set_dict,会遍历*options,然后调用av_opt_set来设置*ps的av_class的option字段。

av_opt_set_dict遍历AVDictionary的每个值,av_opt_set获取对应的option,来设置。

转载于:https://my.oschina.net/u/343244/blog/759649

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值