新聞中心
當(dāng)前是用的是3.4版本的FFmpeg
av_register_all
??? avformat_open_input
??????? avformat_find_stream_info
??????????? avcodec_find_decoder
??????????????? avcodec_open2
av_read_frame
??? avcodec_send_packet
??????? avcodec_receive_frame
申請過程
1)調(diào)用avformat_alloc_context創(chuàng)建一個AVFormatContext變量的實例pAVFormatContext
AVFormatContext* pAVFormatContext = avformat_alloc_context();
2)調(diào)用avio_alloc_context創(chuàng)建一個AVIOContext變量的實例pAVIOContext
AVIOContext* pAVIOContext = avio_alloc_context(mallocBuffer,? mallocBufferSize, 0, this, ReadStreamData, NULL, NULL);
該函數(shù)中ReadStreamData用于讀取讀取的網(wǎng)絡(luò)或者文件中的視頻或者音頻流的函數(shù),mallocBuffer用于保存讀取到的數(shù)據(jù)用于分析,mallocBufferSize是分配的緩存長度,一旦mallocBufferSize申請的緩存長度小于返回讀取的數(shù)據(jù)長度會導(dǎo)致拷貝到緩存中的數(shù)據(jù)越界,導(dǎo)致程序崩潰
3)如果已經(jīng)知道數(shù)據(jù)的格式為h364,調(diào)用av_find_input_format創(chuàng)建一個AVInputFormat變量的實例pAVInputFormat
AVInputFormat* pAVInputFormat = av_find_input_format("h364");
pAVFormatContext->iformat = pAVInputFormat;
if (avformat_open_input(&pAVFormatContext, "", pAVInputFormat, NULL) < 0)
4)開始探測碼流格式
avformat_find_stream_info(pAVFormatContext, NULL);
釋放過程
avformat_close_input(pAVFormatContext);
分析該函數(shù)分為三部分
第一部分
關(guān)閉輸入:
??? if (s->iformat)
??????? if (s->iformat->read_close)
??????????? s->iformat->read_close(s);
對于播放rtsp://admin:[email protected]:554/h364/ch2/main/av_stream,主要是發(fā)送TearDown指令給攝像機(jī)
第二部分
avio_close(pb)
第三部分
avformat_free_context(s)
該函數(shù)的核心就是釋放申請創(chuàng)建的視頻和音頻的流??
?for (i = s->nb_streams - 1; i >= 0; i--)
??????? ff_free_stream(s, s->streams[i]);
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
分享題目:FFmpegAVFormatContext變量的申請以及釋放剖析-創(chuàng)新互聯(lián)
本文來源:http://fisionsoft.com.cn/article/dihjdo.html