- 5
- 0
- 约1.02万字
- 约 7页
- 2019-04-04 发布于江苏
- 举报
FFMpeg 框架代码阅读
1. 简介
FFmpeg 是一个集录制、转换、音/视频编码解码功能为一体的完整的开源解决方案。
FFmpeg 的开发 基于 Linux 操作系统,但 可以在大多数操作系统中编译和使用。
FFmpeg 支持MPEG、DivX、MPEG4、AC3、DV、FLV 等40 多种编码,AVI、MPEG、
OGG、Matroska、ASF 等90 多种解码.TCPMP, VLC, MPlayer 等开源播放器都用到了
FFmpeg。
FFmpeg 主目录下主要有 libavcodec 、libavformat 和 libavutil 等子目录。其中
libavcodec 用 于存 放各个 encode/decode 模 块, libavformat 用 于 存放
muxer/demuxer 模块,libavutil 用于存放内存操作等辅助性模块。
以flash movie 的flv 文件格式为例, muxer/demuxer 的flvenc.c 和flvdec.c 文件在
libavformat 目录下,encode/decode 的mpegvideo.c 和h263de.c 在libavcodec 目
录下。
2. muxer/demuxer 与encoder/decoder 定义与初始化
muxer/demuxer 和encoder/decoder 在FFmpeg 中的实现代码里,有许多相同的地方,
而二者最大的差别 muxer 和 demuxer 分别是不同的结构 AVOutputFormat
AVInputFormat,而encoder 和decoder 都 用的AVCodec 结构。
muxer/demuxer 和encoder/decoder 在FFmpeg 中相同的地方有:
二者都是在main()开始的av_register_all()函数内初始化的
二者都是以链表的形式保存在全局变量中的
muxer/demuxer 是分别保存在全局变量AVOutputFormat *first_oformat
AVInputFormat *first_iformat 中的。
encoder/decoder 都 保存在全局变量AVCodec *first_avcodec 中的。
二者都用函数指针的方式作为开放的公共接口
demuxer 开放的接口有:
int (*read_probe)(AVProbeData *);
int (*read_header)(struct AVFormatContext *, AVFormatParameters *ap);
int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
int (*read_close)(struct AVFormatContext *);
int (*read_seek)(struct AVFormatContext *, int stream_index, int64_t
timestamp, int flags);
muxer 开放的接口有:
int (*write_header)(struct AVFormatContext *);
int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
int (*write_trailer)(struct AVFormatContext *);
encoder/decoder 的接口是一样的,只不过二者分别只实现encoder 和decoder 函数:
int (*init)(AVCodecContext *);
int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
int (*close)(AVCodecContext *);
int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, uint8_t
*buf, int buf_size);
仍以flv 文件为例来说明muxer/demuxer 的初始化。
在libavformat\allformats.c 文件的av_register_all(v
原创力文档

文档评论(0)