ffmpeg流媒体解码流程

来源:互联网 发布:游族游戏官方网络 编辑:程序博客网 时间:2024/06/10 03:38

一. 相关API说明
1. av_register_all
2. avformat_network_init
不管是流媒体发送还是流媒体接收, 需要先执行该函数.
3. avformat_alloc_context
初始化一个AVFormatContext.
4. av_frame_alloc
初始化一个AVFrame. AVFrame用来存储非压缩的数据(视频对应RGB/YUV像素数据,音频对应PCM采样数据).
5. avformat_open_input
打开流媒体或本地文件.
6. avformat_find_stream_info
分析流信息, 该函数可以读取一部分视音频数据并且获得一些相关的信息.
7. avpicture_alloc
8. avcodec_find_decoder
查找对应ID的解码器.
9. sws_getContext
初始化一个SwsContext.
10. avcodec_open2
初始化一个视音频编解码器的AVCodecContext.
11. av_read_frame
读取码流中的音频若干帧或者视频一帧. 例如,解码视频的时候,每解码一个视频帧,需要先调用 av_read_frame()获得一帧视频的压缩数据,然后才能对该数据进行解码(例如H.264中一帧压缩数据通常对应一个NAL).
12. avcodec_decode_video2
解码一帧视频数据. 输入一个压缩编码的结构体AVPacket,输出一个解码后的结构体AVFrame.
13. sws_scale
处理图像数据(缩放,YUV/RGB格式转换等).
14. av_free_packet
销毁一个AVPacket.
15. avformat_free_context
销毁一个AVFormatContext.
16. av_frame_free
销毁一个AVFrame.
17. sws_freeContext
释放一个SwsContext.

二. 解码流程