1. 程式人生 > >FFmepg avcodec_receive_frame函數分析

FFmepg avcodec_receive_frame函數分析

全部 刷新 分析 指向 bsp 根據 ref htm vco

int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
/*
brief:從解碼器中獲取解碼的輸出數據
*/
@參數 avctx 編碼上下文
@參數 frame 這將會指向從解碼器分配的一個引用計數的視頻或者音頻幀(取決於解碼類型)
@註意該函數在處理其他事情之前會調用av_frame_unref(frame)

@返回值
0:成功,返回一幀數據
AVERROR(EAGAIN):當前輸出無效,用戶必須發送新的輸入
AVERROR_EOF:解碼器已經完全刷新,當前沒有多余的幀可以輸出
AVERROR(EINVAL):解碼器沒有被打開,或者它是一個編碼器
其他負值:對應其他的解碼錯誤

代碼例子
avcodec_send_packet和avcodec_receive_frame調用關系並不一定是一對一的,比如一些音頻數據一個AVPacket中包含了1秒鐘的音頻,調用一次avcodec_send_packet之後,可能需要調用25次 avcodec_receive_frame才能獲取全部的解碼音頻數據,所以要做如下處理:

int re = avcodec_send_packet(codec, pkt);
if (re != 0)
{
return;
}

while( avcodec_receive_frame(codec, frame) == 0)
{
//讀取到一幀音頻或者視頻
//處理解碼後音視頻 frame
}


根據上面的評論,下面的代碼是否有問題,當前只是處理視頻幀數據
while(1)
{
int nRet = avcodec_send_packet(pAVCodecContext, packet);
if (0 != nRet) continue;

if (avcodec_receive_frame(pVideoc->m_pAVCodecContext, pFrame) != 0) continue;
}



參考
http://www.bubuko.com/infodetail-2106896.html

FFmepg avcodec_receive_frame函數分析