FFmpeg中 avcodec_copy_context和codec deprecated方案如下:
將之前http://www.itdecent.cn/p/e35566f0965a網(wǎng)上的ios錄像功能函數(shù)在開始錄像函數(shù)的里面要修改,由于上面提到int ffp_start_recording_l(FFPlayer*ffp,constchar*file_name)函數(shù)沖突問題,修改如下:
for(inti =0; i < is->ic->nb_streams; i++) {
.........
?AVCodec*codec =avcodec_find_decoder(in_stream->codecpar->codec_id);
? ? ? ? AVStream *out_stream = avformat_new_stream(ffp->m_ofmt_ctx, codec);//avformat_new_stream(ffp->m_ofmt_ctx, in_stream->codec->codec);
...........
AVCodecContext *pCodecCtx = avcodec_alloc_context3(codec);
? ? ? ? intret =avcodec_parameters_to_context(pCodecCtx, in_stream->codecpar);
? ? ? ? //if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0)
? ? ? ? if(ret <0)
? ? ? ? {
? ? ? ? ? ? av_log(ffp, AV_LOG_ERROR, "Failed to copy context from input to output stream codec context\n");
? ? ? ? ? ? goto?end;
? ? ? ? }
?? ? ? ?pCodecCtx->codec_tag=0;
? ? ? ??if(ffp->m_ofmt_ctx->oformat->flags&AVFMT_GLOBALHEADER) {
? ? ? ? ? ? pCodecCtx->flags|=CODEC_FLAG_GLOBAL_HEADER;
? ? ? ? }
? ? ? ? ret =avcodec_parameters_from_context(out_stream->codecpar, pCodecCtx); ? ? ? ? ? ? ?
? ? ? ? if(ret <0) {
? ? ? ? ? ? printf("Failed to copy context input to output stream codec context\n");
? ? ? ? ? ??goto?end;
? ? ? ? }
? ? ? ? //out_stream->codec->codec_tag = 0;
//? ? ? ? if (ffp->m_ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) {
//? ? ? ? ? ? out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
//? ? ? ? }
}
對應修改看上面注釋都是和新修改是一一對應的。
參考資料:
?http://www.itdecent.cn/p/e35566f0965a
https://www.2cto.com/kf/201704/634731.html
https://blog.csdn.net/leixiaohua1020/article/details/25422685