0
点赞
收藏
分享

微信扫一扫

FFmpeg avcodec_copy_context deprecated替换方案

人间四月天i 2022-06-06 阅读 83

新版本中FFmpeg的avcodec_copy_context被avcodec_parameters_to_context和avcodec_parameters_from_context所替代,因此需要将原本的写法修改一下。
旧API版本如下

ret = avcodec_copy_context(out_stream->codec, in_stream->codec);
if (ret < 0){
printf("Failed to copy context from input to output stream codec context\n");
goto end;
}

out_stream->codec->codec_tag = 0;
if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
out_stream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

替换新API版本如下

AVCodecContext *codec_ctx = avcodec_alloc_context3(in_codec);
ret = avcodec_parameters_to_context(codec_ctx, in_stream->codecpar);
if (ret < 0){
printf("Failed to copy in_stream codecpar to codec context\n");
goto end;
}

codec_ctx->codec_tag = 0;
if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
codec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

ret = avcodec_parameters_from_context(out_stream->codecpar, codec_ctx);
if (ret < 0){
printf("Failed to copy codec context to out_stream codecpar context\n");
goto end;
}


举报

相关推荐

0 条评论