從FFmpeg 3.0 開始 , 使用了很多新接口,在一些基本用法上,編譯會看見很多的warning,類似
“ warning: ‘AVStream::codec’ is deprecated (declared at /usr/local/ffmpeg/include/libavformat/avformat.h:880) [-Wdeprecated-declarations]
out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;”
avcodec_decode_video2()
原本的解碼函數(shù)被拆解為兩個函數(shù)avcodec_send_packet()和avcodec_receive_frame() 具體用法如下:
old:
avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, pPacket);
new:
avcodec_send_packet(pCodecCtx, pPacket);
avcodec_receive_frame(pCodecCtx, pFrame);avcodec_encode_video2()
對應的編碼函數(shù)也被拆分為兩個函數(shù)avcodec_send_frame()和avcodec_receive_packet() 具體用法如下:
old:
avcodec_encode_video2(pCodecCtx, pPacket, pFrame, &got_picture);
new:
avcodec_send_frame(pCodecCtx, pFrame);
avcodec_receive_packet(pCodecCtx, pPacket);avpicture_get_size()
現(xiàn)在改為使用av_image_get_size() 具體用法如下:
old:
avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
new:
//最后一個參數(shù)align這里是置1的,具體看情況是否需要置1
av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1);avpicture_fill()
現(xiàn)在改為使用av_image_fill_arrays 具體用法如下:
old:
avpicture_fill((AVPicture *)pFrame, buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
new:
//最后一個參數(shù)align這里是置1的,具體看情況是否需要置1
av_image_fill_arrays(pFrame->data, pFrame->linesize, buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height,1);關(guān)于codec問題有的可以直接改為codecpar,但有的時候這樣這樣是不對的,所以我也還在探索,這里記錄一個對pCodecCtx和pCodec賦值方式的改變
old:
pCodecCtx = pFormatCtx->streams[video_index]->codec;
pCodec = avcodec_find_decoder(pFormatCtx->streams[video_index]->codec->codec_id);
new:
pCodecCtx = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(pCodecCtx,pFormatCtx->streams[video_index]->codecpar);
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);PIX_FMT_YUV420P -> AV_PIX_FMT_YUV420P
'AVStream::codec': 被聲明為已否決:
old:
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
new:
if(pFormatCtx->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO){'AVStream::codec': 被聲明為已否決:
old:
pCodecCtx = pFormatCtx->streams[videoindex]->codec;
new:
pCodecCtx = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[videoindex]->codecpar);'avpicture_get_size': 被聲明為已否決:
old:
avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height)
new:
include "libavutil/imgutils.h"
av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1)
'avpicture_fill': 被聲明為已否決:
old:
avpicture_fill((AVPicture *)pFrameYUV, out_buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
new:
av_image_fill_arrays(pFrameYUV->data, pFrameYUV->linesize, out_buffer, AV_PIX_FMT_YUV420P,
pCodecCtx->width, pCodecCtx->height, 1);'avcodec_decode_video2': 被聲明為已否決:
old:
ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet); //got_picture_ptr Zero if no frame could be decompressed
new:
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': 被聲明為已否決:
old:
av_free_packet(packet);
new:
av_packet_unref(packet);avcodec_decode_audio4:被聲明為已否決:
old:
result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, &enc_pkt);
new:
int ret = avcodec_send_packet(dec_ctx, &enc_pkt);
if (ret != 0) {
prinitf("%s/n","error");
}
while( avcodec_receive_frame(dec_ctx, &out_frame) == 0){
//讀取到一幀音頻或者視頻
//處理解碼后音視頻 frame
}