场景说明
            当前使用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);  

 

新旧版本FFmpeg对比

新                                            旧

AVPixelFormat                       PixelFormat

codecpar                                AVStream::codec

av_image_fill_arrays               avpicture_fill

 

FFmpeg 4.4版本更新情况

1)void av_register_all(void);该函数不再需要调用,即可加载所有的模块

2)av_free_packet已经废弃,被av_packet_unref替代

3)avformat_new_stream创建输出流

        AVStream* pInputAVStream = pInputAVFormatContext->streams[i];
        AVStream* pOutputAVStream = avformat_new_stream(pOutputAVFormatContext, 0);
        avcodec_parameters_copy(pOutputAVStream->codecpar, pInputAVStream->codecpar);

4)AVStream中的视音频类型判断AVMEDIA_TYPE_VIDEO

ictx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO修改为

ictx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO