一般流程:
1裁眯、av_register_all();//注冊(cè)所有文件格式和編解碼庫
2智什、avformat_network_init();//打開網(wǎng)絡(luò)視頻流
3漆枚、av_open_input_file();//讀取文件頭部把信息保存到AVFormatContext結(jié)構(gòu)體
4竞川、av_find_stream_info();//為pFormatCtx->streams填充上正確的信息
5棋嘲、CODEC_TYPE_VIDEO;//通過判斷得到視頻流類型
6酒唉、avcodec_find_decoder();//查找解碼器
7、avcodec_open();//打開編解碼器
8沸移、avcodec_alloc_frame();//分配空間保存幀數(shù)據(jù)
9痪伦、av_read_frame();//不斷從流中提取幀數(shù)據(jù)
10、avcodec_decode_video();//解碼視頻流
11雹锣、avcodec_close();//關(guān)閉解碼器
12网沾、avformat_close_input_file();//關(guān)閉輸入文件
FFmpeg使用流程_KirogiYi的博客-CSDN博客_ffmpeg使用流程
Camera公共庫使用流程
一、init 初始化信息
1蕊爵、avformat_open_input // 讀取文件頭部把信息保存到AVFormatContext結(jié)構(gòu)體辉哥,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 根據(jù)編解碼器上下文的信息, 設(shè)置圖像轉(zhuǎn)換參數(shù)
6捂人、av_frame_alloc御雕、av_image_alloc || av_samples_alloc // 分配空間保存YUV或者PCM幀數(shù)據(jù)
7-1、initVideoFilter; // 設(shè)置視頻幀解碼完成回調(diào)
7-2先慷、音頻 initSwrContext ==》 swr_alloc_set_opts // 設(shè)置重采樣參數(shù)
二饮笛、start 開始拉流
1咨察、playVideoInternal ==》 while循環(huán)將已經(jīng)解碼完成的數(shù)據(jù)從視頻緩存隊(duì)列中回調(diào)到上層渲染论熙;
2、av_read_frame摄狱;//不斷從流中提取幀數(shù)據(jù)
3脓诡、avcodec_send_packet; //解碼音視頻流
4媒役、avcodec_receive_frame祝谚; // 循環(huán)讀取解碼完成后的數(shù)據(jù)
5、audioResample ==》 swr_convert音頻重采樣
6酣衷、playAudioInternal交惯;將處理完的音頻數(shù)據(jù)回調(diào)到上層播放;
三穿仪、release 結(jié)束
1席爽、avformat_close_input ; // 關(guān)閉打開的輸入AVFormatContext
2、avformat_free_context啊片; // 釋放AVFormatContext及其所有流
2只锻、avcodec_free_context; // 釋放編解碼器上下文和與之相關(guān)的所有內(nèi)容
3、sws_freeContext紫谷、swr_free齐饮; // 釋放圖像、音頻處理上下文