cpp-ffmpeg如何解决已弃用的警告?

时间:2018-04-19 02:33:55

标签: c++ ffmpeg deprecation-warning

我正在使用FFmpeg Lib,我收到警告,我的代码如下:

if ( avformat_find_stream_info( pFormatCtx, NULL ) < 0 ) {
        std::cout << "Get Stream Information Error 13" << std::endl;
        avformat_close_input( &pFormatCtx );
        pFormatCtx = NULL;
        return -13;
 }
av_dump_format( pFormatCtx, 0, filenameSrc, 0 );

for ( unsigned int i = 0; i < pFormatCtx->nb_streams; i++ ) {
        if (pFormatCtx->streams[i]->codec->coder_type == AVMEDIA_TYPE_VIDEO) {
            video_stream_index = i;
            break;
        }
 }

我在第pFormatCtx->streams[i]->codec->coder_type == AVMEDIA_TYPE_VIDEO

行符合警告

警告:AVCodecContext::coder_type’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:2815) [-Wdeprecated-declarations]

我不明白这个警告是什么意思以及如何解决它。

任何人都可以帮助我!

感谢

3 个答案:

答案 0 :(得分:0)

正如您在警告消息中看到的那样,您可以直接使用AVCodecContext::coder_typeffmpeg docs中看到已被弃用。

但是在文档中你可以看到你还能做什么,使用编码器私有选项

您可以在某些AVCodecContext上创建AVCodec基础。然后你可以使用AVCodec::type。或者您可以从AVCodecContext再次获取它:

AVCodec *codec = avcodec_find_encoder(codec_context->codec_id);
int coder_type = codec->type;

在您的情况下,您可以像这样更改代码:

for(unsigned int i = 0; i < pFormatCtx->nb_streams; i++)
{
    if(avcodec_find_encoder(pFormatCtx->streams[i]->codec->codec_id)->type == AVMEDIA_TYPE_VIDEO)
    {
        video_stream_index = i;
        break;
    }
}

答案 1 :(得分:0)

请禁用Visual Studio的SDL检查。

在项目/属性/ C / C ++ /常规/ SDL检查中, 从是(/ sdl)更改为否(/ sdl-)

这已在Visual Studio 2017中进行了测试。

答案 2 :(得分:0)

尝试使用codec_type中的codecpar

if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
        video_stream_index = i;
相关问题