4.1版本弃用清单
ffmpeg API里面有各种接口改变的记录,如果发现接口不能用了,可以去搜索文档,可以找到对应的新接口,然后到新接口对应的头文件中找到说明文字。
常见的替换的API
1) 不认识guess_format.
解决: #define guess_format av_guess_format
接口不变。
2) 不认识av_alloc_format_context
解决: #define av_alloc_format_context avformat_alloc_output_context
接口调整
3) 不认识CODEC_TYPE_VIDEO 和 CODEC_TYPE_AUDIO
解决:
#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO
#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO
4) 不认识audio_resample_init
解决:#define audio_resample_init av_audio_resample_init
接口调整。
5) avcodec_decode_video 到 avcodec_decode_video2接口调整
旧代码:
len = avcodec_decode_video(c, (short *)outbuf, &out_size, inbuf_ptr, size);
新代码:av_init_packet(&pkt); pkt.data = (unsigned char*)inbuf_ptr; pkt.size = size; len = avcodec_decode_video2(c, &tmpFrame, &got_picture, &pkt);
6) 新的ffmpeg库不需要集中初始化的组建
旧的接口:av_register_all();
新版的API,此处不需要注册组建
7)新的API中将AVStream结构体中codec作了遗弃处理,当需要解码器上下文的时候,需要用AVCodecParameters去转化,解决方案是如下
AVCodecContext *avCodecContext = avcodec_alloc_context3(NULL); if (avCodecContext == NULL) { return; } // avcodec_parameters_to_context(AVCodecContext *codec, constAVCodecParameters *par) // 将新的API中的 codecpar 转成 AVCodecContext // 此处的avcodecParameters 是AVStream中的codecpar属性,codecpar里面包含了视频基础信息, // 但是此处不能直接使用codecpar中的width和height,否者会报错误,错误如下 // Assertion desc failed at src/libswscale/swscale_internal.h:668 avcodec_parameters_to_context(avCodecContext, avcodecParameters);
8)PIX_FMT_YUV420P -> AV_PIX_FMT_YUV420P
‘AVStream::codec’: 被声明为已否决:
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
=>
if(pFormatCtx->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO){
‘avpicture_get_size’: 被声明为已否决:
avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height)
=>
#include "libavutil/imgutils.h"
av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx-height, 1)
‘avpicture_fill’: 被声明为已否决:
avpicture_fill((AVPicture *)pFrameYUV, out_buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
=>
av_image_fill_arrays(pFrameYUV->data, pFrameYUV->linesize, out_buffer,AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1);
‘avcodec_decode_video2’: 被声明为已否决:
ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet); //got_picture_ptr Zero if no frame could be decompressed
=>
ret = avcodec_send_packet(pCodecCtx, packet);
got_picture = avcodec_receive_frame(pCodecCtx, pFrame); //got_picture = 0 success, a frame was returned
//注意:got_picture含义相反
或者:
int ret = avcodec_send_packet(aCodecCtx, &pkt);
if (ret != 0)
{
prinitf("%s/n","error");
return;
}
while( avcodec_receive_frame(aCodecCtx, &frame) == 0){
//读取到一帧音频或者视频
//处理解码后音视频 frame
}
‘av_free_packet’: 被声明为已否决:
av_free_packet(packet);
=>
av_packet_unref(packet);
avcodec_decode_audio4:被声明为已否决:
int ret = avcodec_send_packet(aCodecCtx, &pkt);
if (ret != 0){prinitf("%s/n","error");}
while( avcodec_receive_frame(aCodecCtx, &frame) == 0){
//读取到一帧音频或者视频
//处理解码后音视频 frame
}