From d8b9c5b1024bc2ec95a5172cee94e83fa9a8bf4e Mon Sep 17 00:00:00 2001 From: Xiaofeng Wang <1237906+wasphin@users.noreply.github.com> Date: Thu, 17 Feb 2022 21:03:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20FFmpeg=20API=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20FFmpeg=205=20(#1434)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- player/FFMpegDecoder.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/player/FFMpegDecoder.cpp b/player/FFMpegDecoder.cpp index ae288bac..9d1f6560 100644 --- a/player/FFMpegDecoder.cpp +++ b/player/FFMpegDecoder.cpp @@ -33,10 +33,10 @@ std::shared_ptr alloc_av_packet(){ ////////////////////////////////////////////////////////////////////////////////////////// template -AVCodec *getCodec(ARGS ...names); +const AVCodec *getCodec(ARGS ...names); template -AVCodec *getCodec(const char *name) { +const AVCodec *getCodec(const char *name) { auto codec = decoder ? avcodec_find_decoder_by_name(name) : avcodec_find_encoder_by_name(name); if (codec) { InfoL << (decoder ? "got decoder:" : "got encoder:") << name; @@ -45,7 +45,7 @@ AVCodec *getCodec(const char *name) { } template -AVCodec *getCodec(enum AVCodecID id) { +const AVCodec *getCodec(enum AVCodecID id) { auto codec = decoder ? avcodec_find_decoder(id) : avcodec_find_encoder(id); if (codec) { InfoL << (decoder ? "got decoder:" : "got encoder:") << avcodec_get_name(id); @@ -54,7 +54,7 @@ AVCodec *getCodec(enum AVCodecID id) { } template -AVCodec *getCodec(First first, ARGS ...names) { +const AVCodec *getCodec(First first, ARGS ...names) { auto codec = getCodec(names...); if (codec) { return codec; @@ -139,9 +139,11 @@ FFmpegFrame::Ptr FFmpegSwr::inputFrame(const FFmpegFrame::Ptr &frame) { /////////////////////////////////////////////////////////////////////////// FFmpegDecoder::FFmpegDecoder(const Track::Ptr &track) { +#if (LIBAVCODEC_VERSION_MAJOR < 58) avcodec_register_all(); - AVCodec *codec = nullptr; - AVCodec *codec_default = nullptr; +#endif + const AVCodec *codec = nullptr; + const AVCodec *codec_default = nullptr; switch (track->getCodecId()) { case CodecH264: codec_default = getCodec(AV_CODEC_ID_H264); @@ -181,7 +183,9 @@ FFmpegDecoder::FFmpegDecoder(const Track::Ptr &track) { } //保存AVFrame的引用 +#ifdef FF_API_OLD_ENCDEC _context->refcounted_frames = 1; +#endif _context->flags |= AV_CODEC_FLAG_LOW_DELAY; _context->flags2 |= AV_CODEC_FLAG2_FAST;