FFmpeg AVStream::codec被聲明爲已否決

場景說明
            當前使用FFmpeg3.4版本的開發庫,編譯過程中出現:'AVStream::codec': 被聲明爲已否決的異常錯誤,並且提示:Using AVStream.codec … deprecated, use AVStream.codecpar instead。從提示可以看出,需要使用AVStream.codecpar替代AVStream.codec,前者類型是AVCodecParameters,後者的類型是AVCodecContext.

歷史說明
            舊版本使用AVStream.codec是因爲在打開碼流(avformat_open_input),探測視頻數據(avformat_find_stream_info)的時候,很容易獲取源視頻的一些信息,然後在解碼的時候直接打開解碼器,開始解碼

網上方案
    將VS的SDL檢查關閉

原因分析
            新版本的FFmpeg中AVStream的codec成員不再推薦使用,而是要求使用codecpar。FFmpeg中所謂的“被聲明爲已否決”就是因爲函數或者結構體屬性被標示爲attribute_deprecated,很有可能在未來的版本中就刪除了。
所以我們最好的解決方案就是使用新的被推薦使用的函數、結構體等。在後續中因爲要解決avformat_find_stream_info探測流慢的問題,會針對codecpar進行相應的賦值


FFmpeg3.x版本之前的代碼
pAVCodecContext = pAVFormatContext->streams[videoIndex]->codec;

FFmpeg3.x最佳解決方案
    pAVCodecContext = avcodec_alloc_context3(NULL);  
    if (pAVCodecContext == NULL)  
    {  
        printf("Could not allocate AVCodecContext\n");  
        return -1;  
    }  
    avcodec_parameters_to_context(pAVCodecContext, pAVFormatContext->streams[videoIndex]->codecpar);  

 

參考
http://blog.csdn.net/luotuo44/article/details/54981809

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章