FFMPEG 网上下载了一些视频截图的demo,不过版本比较老,一些函数已然过期,针对这些修改一下。整理一下接触到的,作为笔记吧。
1.av_register_all(); 在新版本这个可以直接删除掉。
2.
AVStream stream=pFormatCtx.streams(i);
AVCodecContext codec=stream.codec();
//修改为:
AVStream stream=pFormatCtx.streams(videoStream);
AVCodecParameters param = stream.codecpar();
AVCodec codec = avcodec_find_decoder(param.codec_id());
AVCodecContext pCodecCtx = avcodec_alloc_context3(codec);
avcodec_parameters_to_context(pCodecCtx,param);
3.avpicture_get_size(); 改为 av_image_get_buffer_size(fmt, width, height,1); 最后一个变量改为1就行
4.avpicture_fill(); 改为av_image_fill_arrays(pFrameRGB.data(),pFrameRGB.linesize(),buffer, fmt, width, height,1);
5:avcodec_decode_video2(pCodecCtx, pFrame, frameFinished, packet);该函数已经可以移除,改为:
if(avcodec_send_packet(pCodecCtx,packet)!=0) {
return null;
}
while(avcodec_receive_frame(pCodecCtx,pFrame) == 0) {
sws_scale(sws_ctx, pFrame.data(), pFrame.linesize(), 0, height, pFrameRGB.data(),pFrameRGB.linesize());
//return 要执行的处理方法
}
6:av_free_packet()改为av_packet_unref()