本文记录FFmpeg的两个API函数:avcodec_find_encoder()和avcodec_find_decoder()。avcodec_find_encoder()用于查找FFmpeg的编码器,avcodec_find_decoder()用于查找FFmpeg的解码器。
avcodec_find_encoder()的声明位于libavcodecavcodec.h,以下所示。
* Find a registered encoder with a matching codec ID.
*
* @param id AVCodecID of the requested encoder
* @return An encoder if one was found, NULL otherwise.
*/
AVCodec *avcodec_find_encoder(enum AVCodecID id);
函数的参数是1个编码器的ID,返回查找到的编码器(没有找到就返回NULL)。
avcodec_find_decoder()的声明也位于libavcodecavcodec.h,以下所示。
* Find a registered decoder with a matching codec ID.
*
* @param id AVCodecID of the requested decoder
* @return A decoder if one was found, NULL otherwise.
*/
AVCodec *avcodec_find_decoder(enum AVCodecID id);
函数的参数是1个解码器的ID,返回查找到的解码器(没有找到就返回NULL)。
avcodec_find_encoder()函数最典型的例子可以参考:
最简单的基于FFMPEG的视频编码器(YUV编码为H.264)
avcodec_find_decoder()函数最典型的例子可以参考:
最简单的基于FFMPEG+SDL的视频播放器 ver2 (采取SDL2.0)
其实这两个函数的实质就是遍历AVCodec链表并且取得符合条件的元素。有关AVCodec链表的建立可以参考文章:
ffmpeg 源代码简单分析 : av_register_all()
函数调用关系图
avcodec_find_encoder()和avcodec_find_decoder()的函数调用关系图以下所示。
波比源码 » FFmpeg源代码简单分析:av_find_decoder()和av_find_encoder()