FFMPEG 解码流程 硬解码
关键流程概述
- 初始化阶段
-
- av_register_all():注册所有编解码器 新版本可以不调用了
- avformat_network_init(): 网络初始化
- avformat_alloc_context():创建封装格式上下文
- avformat_open_input():打开媒体文件
- 流信息解析
-
- avformat_find_stream_info():获取流信息
- av_find_best_stream():查找视频和音频流索引
- 解码器创建
软解方案
-
- avcodec_find_decoder():查找解码器
- avcodec_alloc_context3():创建解码器上下文
- avcodec_parameters_to_context()
- avcodec_open2():打开解码器
硬解方案:
-
- avcodec_find_decoder_by_name 查找对应的硬解码器
- .....
- avcodec_open2():打开解码器
- 解码循环
-
- av_read_frame():读取压缩数据包 Avpacket -> queue
- avcodec_send_packet():发送到解码器
- avcodec_receive_frame():接收解码帧 AvFrame yuv / pcm
- 视频渲染以及音频播放
- YUV sws_scale():统一像素格式转换(YUV420)
-
PCM 播放
有想学习音视频的兄弟 更多详情可以查看视频 哔哩哔哩_bilibili