最近学习android音视频开发,首选资料自然是雷神(雷霄骅)的博客了,大神博客中的示例所用到的ffmpeg库的版本应该是早期的,我使用的官网最新版本ffmpeg-3.4.6。博客中的案例部分api里的方法在新版库中已经被废弃,强迫症使然,看不惯被横线警告⚠️,所以特意搜寻总结了下旧版本的废弃方法的替身,基本常用的几个都已包含在内,具体如下所示,以供参考
'AVStream::codec': 被声明为已废弃:
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
替身=>
if(pFormatCtx->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO){
pCodecCtx = pFormatCtx->streams[videoindex]->codec;
替身=>
pCodecCtx = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[videoindex]->codecpar);
'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
'av_free_packet': 被声明为已否决:
av_free_packet(packet);
替身=>
av_packet_unref(packet);
网友评论