Trần Quốc Việt
Trần Quốc Việt

Reputation: 69

cpp-ffmpeg how to resolve deprecated warning?

I am working with FFmpeg Lib, and I get a warning, my code as below:

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;
        }
 }

And I meet the warning at line: pFormatCtx->streams[i]->codec->coder_type == AVMEDIA_TYPE_VIDEO

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

I dont understand what does this warning mean and how to resolve it.

Anyone can help me !

Thank

Upvotes: 4

Views: 7673

Answers (3)

Rainmaker
Rainmaker

Reputation: 11090

Try to use codec_type from codecpar:

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

Upvotes: 3

Green Tree
Green Tree

Reputation: 329

Please disable Visual Studio's SDL checks.

In Project / Properties / C/C++ / General / SDL checks, change from Yes(/sdl) to No(/sdl-).

This is tested in Visual Studio 2017.

Upvotes: 0

HMD
HMD

Reputation: 2226

As you can see in your warning message and also you can see in ffmpeg docs using AVCodecContext::coder_type directly is deprecated.

But in docs you can see what else you can do, use encoder private options instead.

You create your AVCodecContext base on some AVCodec. Then you can just use AVCodec::type. Or you can get it again from AVCodecContext like this :

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

In your case you can change your code like this :

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;
    }
}

Upvotes: 1

Related Questions