背景
ffmpegのライブラリルーチンメソッドを呼び出すようにするとき学ぶためによると警告の束を発見しました。
main.cpp:81:37: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
入門
FFmpegの3.0から、いくつかの基本的な使い方に新しいインタフェースの多くを使用して、コンパイラは同様の警告の多くが表示されます
“ 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;”
1. avcodec_decode_video2()
元の復号化機能は、二つの分解avcodec_send_packet(の関数)とavcodec_receive_frame()次のように使用されます。
古い:
avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, pPacket);
新着:
avcodec_send_packet(pCodecCtx, pPacket);
avcodec_receive_frame(pCodecCtx, pFrame);
2. avcodec_encode_video2()
次のように使用した)(符号化関数に対応また、(2つの関数avcodec_send_frameに分割することができる)とavcodec_receive_packet。
古い:
avcodec_encode_video2(pCodecCtx, pPacket, pFrame, &got_picture);
新着:
avcodec_send_frame(pCodecCtx, pFrame);
avcodec_receive_packet(pCodecCtx, pPacket);
3. avpicture_get_size()
今、代わりに使用しav_image_get_size()
、以下のように使用:
古い:
avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
新着:
//最后一个参数align这里是置1的,具体看情况是否需要置1
av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1);
4. avpicture_fill()
今、代わりに使用しav_image_fill_arrays
、以下のように使用:
古い:
avpicture_fill((AVPicture *)pFrame, buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
新着:
//最后一个参数align这里是置1的,具体看情况是否需要置1
av_image_fill_arrays(pFrame->data, pFrame->linesize, buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height,1);
直接変更することができますコーデックいくつかの問題については5 codecpar
、時にはこれがそう間違っている、私はまだ模索ので、ここで割り当てpCodecCtxとpCodecの仕方の変化を記録します
古い:
pCodecCtx = pFormatCtx->streams[video_index]->codec;
pCodec = avcodec_find_decoder(pFormatCtx->streams[video_index]->codec->codec_id);
新着:
pCodecCtx = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(pCodecCtx,pFormatCtx->streams[video_index]->codecpar);
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
6. PIX_FMT_YUV420P - > AV_PIX_FMT_YUV420P
7.「AVStream ::コーデック」:それが拒否されたと宣言されています。
古い:
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
新着:
if(pFormatCtx->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO){
8.「AVStream ::コーデック」:それが拒否されたと宣言されています。
古い:
pCodecCtx = pFormatCtx->streams[videoindex]->codec;
新着:
pCodecCtx = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[videoindex]->codecpar);
9.「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)
10.「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);
11.「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
}
12.「av_free_packet」:拒否は次のように宣言されています。
古い:
av_free_packet(packet);
新着:
av_packet_unref(packet);
13. avcodec_decode_audio4は:廃止予定宣言されました:
古い:
result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, &enc_pkt);
新着:
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
}
エラー:「avcodec_alloc_frame」はこのスコープで宣言されていませんでした
古い:
pFrame = avcodec_alloc_frame();
新しいです:
pFrame = av_frame_alloc();