一般流程:
1、av_register_all();//注册所有文件格式和编解码库
2、avformat_network_init();//打开网络视频流
3、av_open_input_file();//读取文件头部把信息保存到AVFormatContext结构体
4、av_find_stream_info();//为pFormatCtx->streams填充上正确的信息
5、CODEC_TYPE_VIDEO;//通过判断得到视频流类型
6、avcodec_find_decoder();//查找解码器
7、avcodec_open();//打开编解码器
8、avcodec_alloc_frame();//分配空间保存帧数据
9、av_read_frame();//不断从流中提取帧数据
10、avcodec_decode_video();//解码视频流
11、avcodec_close();//关闭解码器
12、avformat_close_input_file();//关闭输入文件
FFmpeg使用流程_KirogiYi的博客-CSDN博客_ffmpeg使用流程
Camera公共库使用流程
一、init 初始化信息
1、avformat_open_input // 读取文件头部把信息保存到AVFormatContext结构体,format = avformat_alloc_context
2、avformat_find_stream_info
3、AVMEDIA_TYPE_VIDEO、AVMEDIA_TYPE_AUDIO; // 通过获取视频流类型
3、avcodec_find_decoder; // 查找编码器
4、avcodec_open2 //打开编解码器
5、initSwsContext ==》 sws_getContext 根据编解码器上下文的信息, 设置图像转换参数
6、av_frame_alloc、av_image_alloc || av_samples_alloc // 分配空间保存YUV或者PCM帧数据
7-1、initVideoFilter; // 设置视频帧解码完成回调
7-2、音频 initSwrContext ==》 swr_alloc_set_opts // 设置重采样参数
二、start 开始拉流
1、playVideoInternal ==》 while循环将已经解码完成的数据从视频缓存队列中回调到上层渲染;
2、av_read_frame;//不断从流中提取帧数据
3、avcodec_send_packet; //解码音视频流
4、avcodec_receive_frame; // 循环读取解码完成后的数据
5、audioResample ==》 swr_convert音频重采样
6、playAudioInternal;将处理完的音频数据回调到上层播放;
三、release 结束
1、avformat_close_input ; // 关闭打开的输入AVFormatContext
2、avformat_free_context; // 释放AVFormatContext及其所有流
2、avcodec_free_context; // 释放编解码器上下文和与之相关的所有内容
3、sws_freeContext、swr_free; // 释放图像、音频处理上下文