FFmpeg

来源:互联网 发布:帝国竞争算法程序 编辑:程序博客网 时间:2024/06/06 20:59

FFmpeg old version, We initialize AVCodecContext often use the follow code.

But, in the FFmpeg new version, the streams->codec code be declared attribute_deprecated, it is suggest not to use the follow code.

AVCodecContext * pCodecCtx = pFormatCtx->streams[videoIndex]->codec;AVCodec * pCodec = avcodec_find_decoder(pCodecCtx->codec_id);

How should we do?

The avcodec_open2 method’s document advice to use avcodec_alloc_context3() method.

The document is introduced in detail how should we do.

But, it missing a method. It is avcodec_parameters_to_context() method.

AVCodec *pCodec = avcodec_find_decoder(pFormatCtx->streams[videoIndex]->codecpar->codec_id);AVCodecContext *pCodecCtx = avcodec_alloc_context3(pCodec);avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[videoIndex]->codecpar);if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {   printf("Could not open codec.\n");    return -1;}
0 0
原创粉丝点击