现在的位置: 首页 > 综合 > 正文

FFmpeg完美入门【7】-FFmpeg架构之Demuxer和muxer模块分析

2013年12月13日 ⁄ 综合 ⁄ 共 1618字 ⁄ 字号 评论关闭

http://it6655.com/2012/09/ffmpeg-7-html

1概述
ffmpeg的demuxer和muxer接口分别在AVInputFormat和AVOutputFormat两个结构体中实现,在av_register_all()函数中将两个结构分别静态初始化为两个链表,保存在全局变量:first_iformat和first_oformat两个变量中。在FFmpeg的文件转换或者打开过程中,首先要做的就是根据传入文件和传出文件的后缀名匹配合适的demuxer和muxer,得到合适的信息后保存在AVFormatContext中。

2相关数据结构介绍

1、AVInputFormat

该结构被称为demuxer,是音视频文件的一个解封装器,它的定义如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
typedef struct AVInputFormat {
const char *name; 
const char *long_name; 
int priv_data_size; //具体文件容器格式对应的Context的大小,如:
avicontext int (*read_probe)(AVProbeData *);
int (*read_header)(struct AVFormatContext *, AVFormatParameters *ap); 
int (*read_packet)(struct AVFormatContext *, AVPacket *pkt); 
int (*read_close)(struct AVFormatContext *); 
#if FF_API_READ_SEEK 
attribute_deprecated int (*read_seek)(struct AVFormatContext *, int stream_index, int64_t timestamp, int flags); 
#endif 
int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index, int64_t *pos, int64_t pos_limit);
int flags;
const char *extensions; 
int value; int (*read_play)(struct AVFormatContext *);
int (*read_pause)(struct AVFormatContext *); 
const struct AVCodecTag * const *codec_tag; 
int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); 
#if FF_API_OLD_METADATA2 
const AVMetadataConv *metadata_conv; 
#endif 
const AVClass *priv_class; ///< AVClass for the private context struct AVInputFormat *next; 
} AVInputFormat;

对于不同的文件格式要实现相应的函数接口,这样每一种格式都有一个对应的demuxer,所有的demuxer都保存在全局变量first_iformat中。红色表示提供的接口。

2、AVOutputFormat

该结构与AVInputFormat类似也是在编译时静态初始化,组织为一个链表结构,提供了多个muxer的函数接口。

1
2
3
int (*write_header)(struct AVFormatContext *)

抱歉!评论已关闭.