一、通用API
1.1 av_register_all()
初始化 libavformat 和注册所有的复用器、解复用器和协议处理器。如果不调用这个函数,可以调用下面的三个函数来选择支持的格式。
- 注册复用器的函数是
av_register_output_format()
。 - 注册解复用器的函数是
av_register_input_format()
。 - 注册协议处理器的函数是
ffurl_register_protocol()
。
注:FFmpeg4.0 以上的版本,这个函数已经被废弃。
1.2 内存的分配和释放(av_malloc()、av_free()等)
av_malloc() 和 av_free() 都是简单的封装了系统函数 malloc() 和free(),并做了一些错误检查工作。同理的还有 av_realloc()。
1.3 avcodec_find_encoder() 和 avcodec_find_decoder()
avcodec_find_encoder() 用于查找 FFmpeg 的编码器,avcodec_find_decoder() 用于查找 FFmpeg 的解码器,声明都位于 libavcodec\avcodec.h。其原型如下:
// 函数的参数是一个编码器的ID,返回查找到的编码器(没有找到就返回NULL)。
AVCodec *avcodec_find_encoder(enum AVCodecID id);
// 函数的参数是一个解码器的ID,返回查找到的解码器(没有找到就返回NULL)。
AVCodec *avcodec_find_decoder(enum AVCodecID id);
1.4 avcodec_open2()
用于初始化一个视音频编解码器的 AVCodecContext,声明位于 libavcodec\utils.c。其原型如下:
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **option