溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

FFmpeg AVFormatContext變量的申請以及釋放剖析

發布時間:2020-06-06 10:46:17 來源:網絡 閱讀:978 作者:fengyuzaitu 欄目:軟件技術

當前是用的是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)調用avformat_alloc_context創建一個AVFormatContext變量的實例pAVFormatContext
AVFormatContext* pAVFormatContext = avformat_alloc_context();


2)調用avio_alloc_context創建一個AVIOContext變量的實例pAVIOContext
AVIOContext* pAVIOContext = avio_alloc_context(mallocBuffer,? mallocBufferSize, 0, this, ReadStreamData, NULL, NULL);
該函數中ReadStreamData用于讀取讀取的網絡或者文件中的視頻或者音頻流的函數,mallocBuffer用于保存讀取到的數據用于分析,mallocBufferSize是分配的緩存長度,一旦mallocBufferSize申請的緩存長度小于返回讀取的數據長度會導致拷貝到緩存中的數據越界,導致程序崩潰


3)如果已經知道數據的格式為h364,調用av_find_input_format創建一個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);

分析該函數分為三部分
第一部分
關閉輸入:
??? if (s->iformat)
??????? if (s->iformat->read_close)
??????????? s->iformat->read_close(s);
對于播放rtsp://admin:admin888@192.168.28.130:554/h364/ch2/main/av_stream,主要是發送TearDown指令給攝像機


第二部分
avio_close(pb)


第三部分
avformat_free_context(s)
該函數的核心就是釋放申請創建的視頻和音頻的流??
?for (i = s->nb_streams - 1; i >= 0; i--)
??????? ff_free_stream(s, s->streams[i]);


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女