2012-06-29 40 views
6

我需要一些有關decodein rtsp視頻流的幫助。 我從AXIS IP攝像機獲得它。我使用ffmpeg庫。 需要單獨創建AVCodecContext,而不是從AVFormatContext-> streams [...] - > codec;使用ffmpeg解碼h264 rtsp並分隔AVCodecContext

因此,我創建AVCodec,AVCOdecContext並嘗試初始化它們。

AVCodec *codec=avcodec_find_decoder(codec_id); 
if(!codec) 
{ 
    qDebug()<<"FFMPEG failed to create codec"<<codec_id; 
    return false; //--> 
} 

AVCodecContext *context=avcodec_alloc_context3(codec); 
if(!context) 
{ 
    qDebug()<<"FFMPEG failed to allocate codec context"; 
    return false; //--> 
} 
avcodec_open2(context, codec, NULL); 

然後在應用程序的主循環中,我得到的幀數據,並嘗試解碼:

_preallocatedFrame = avcodec_alloc_frame(); 
avcodec_decode_video2(_context, _preallocatedFrame, &got_picture, &_packet); 

在這裏,我得到很多消息在控制檯:

[h264 @ 1f177720] decode_slice_header error 
[h264 @ 1f177720] no frame! 
[h264 @ 1f177720] non-existing PPS 0 referenced 
[h264 @ 1f177720] decode_slice_header error 
[h264 @ 1f177720] no frame! 
[h264 @ 1f177720] non-existing PPS 0 referenced 
[h264 @ 1f177720] decode_slice_header error 
[h264 @ 1f177720] no frame! 
[h264 @ 1f177720] non-existing PPS 0 referenced 
[h264 @ 1f177720] decode_slice_header error 
[h264 @ 1f177720] no frame! 
[h264 @ 1f177720] non-existing PPS 0 referenced 
[h264 @ 1f177720] decode_slice_header error 
[h264 @ 1f177720] no frame! 
[h264 @ 1f177720] non-existing PPS 0 referenced 
[h264 @ 1f177720] decode_slice_header error 
[h264 @ 1f177720] no frame! 

你能建議我的東西,如何啓動AVCodecContext或其他東西來做到這一點正確?

回答

4

您需要執行一些更多的工作。 如果你想解碼h.264流,你需要傳遞解碼器的「sps pps」數據。 這個數據可以在rtp流本身找到see

或在SDP協議中。 在您用這些數據成功地提供解碼器後,解碼應該工作。

+0

好的,但差異在哪裏。當我從AVFormatContext-> streams [...] - > codec獲取我的AVCodecContext並完成相似的操作時,它解碼時沒有錯誤。 Bt它是必要的我使用分開的codeccontext(它可能會從檔案中獲取數據後解碼,保存在磁盤上,當我不能hav格式上下文) – mmmaaak

+0

您是否嘗試過比較2上下文對象? – Horonchik

+0

是的,他們之間有超過20個不同。我嘗試將除AVCOdecContext-> priv_data和其他指針字段之外的所有不同字段設置爲我的上下文,但它不起作用。 – mmmaaak