From aae8eee6d02c980c41cb62e142b752480ebe1ba0 Mon Sep 17 00:00:00 2001 From: Lubosz Sarnecki Date: Wed, 8 Mar 2023 12:26:53 +0100 Subject: [PATCH] VideoFFmpegComponent: Fix build with FFMpeg 6.0. Version 58 of libav removes the deprecated enums AV_CODEC_CAP_TRUNCATED and AV_CODEC_FLAG_TRUNCATED, just don't use these. They are "redunant with parsers". See https://github.com/FFmpeg/FFmpeg/commit/dd846bc4a91 The struct member `pkt_duration` was also deprecatred in favor of `duration`. See https://github.com/FFmpeg/FFmpeg/commit/4397f9a5a0 Remove LIBAVUTIL_VERSION_MINOR requirement in branches for FFmpeg 5.1+, as they also apply for 6.0. --- .../src/components/VideoFFmpegComponent.cpp | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/es-core/src/components/VideoFFmpegComponent.cpp b/es-core/src/components/VideoFFmpegComponent.cpp index 8e955670b..516d416ff 100644 --- a/es-core/src/components/VideoFFmpegComponent.cpp +++ b/es-core/src/components/VideoFFmpegComponent.cpp @@ -21,7 +21,8 @@ #include #include -#if LIBAVUTIL_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MINOR >= 28 +#if LIBAVUTIL_VERSION_MAJOR >= 58 || \ + (LIBAVUTIL_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MINOR >= 28) // FFmpeg 5.1 and above. #define CHANNELS ch_layout.nb_channels #else @@ -502,7 +503,10 @@ bool VideoFFmpegComponent::setupAudioFilters() int returnValue {0}; std::string errorMessage(512, '\0'); const int outSampleRates[] {AudioManager::getInstance().sAudioFormat.freq, -1}; - const enum AVSampleFormat outSampleFormats[] {AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE}; + const enum AVSampleFormat outSampleFormats[] { + AV_SAMPLE_FMT_FLT, + AV_SAMPLE_FMT_NONE + }; mAFilterInputs = avfilter_inout_alloc(); mAFilterOutputs = avfilter_inout_alloc(); @@ -533,7 +537,8 @@ bool VideoFFmpegComponent::setupAudioFilters() std::string channelLayout(128, '\0'); -#if LIBAVUTIL_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MINOR >= 28 +#if LIBAVUTIL_VERSION_MAJOR >= 58 || \ + (LIBAVUTIL_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MINOR >= 28) // FFmpeg 5.1 and above. AVChannelLayout chLayout {}; av_channel_layout_from_mask(&chLayout, mAudioCodecContext->ch_layout.u.mask); @@ -687,7 +692,11 @@ void VideoFFmpegComponent::readFrames() destFrame->chroma_location = mVideoFrame->chroma_location; destFrame->pkt_pos = mVideoFrame->pkt_pos; +#if LIBAVUTIL_VERSION_MAJOR < 58 destFrame->pkt_duration = mVideoFrame->pkt_duration; +#else + destFrame->duration = mVideoFrame->duration; +#endif destFrame->pkt_size = mVideoFrame->pkt_size; } } @@ -781,9 +790,14 @@ void VideoFFmpegComponent::getProcessedFrames() const double pts {static_cast(mVideoFrameResampled->pkt_dts) * av_q2d(mVideoStream->time_base)}; - // Needs to be adjusted if changing the rate? +// Needs to be adjusted if changing the rate? +#if LIBAVUTIL_VERSION_MAJOR < 58 const double frameDuration {static_cast(mVideoFrameResampled->pkt_duration) * av_q2d(mVideoStream->time_base)}; +#else + const double frameDuration {static_cast(mVideoFrameResampled->duration) * + av_q2d(mVideoStream->time_base)}; +#endif currFrame.pts = pts; currFrame.frameDuration = frameDuration; @@ -1441,8 +1455,10 @@ void VideoFFmpegComponent::startVideoStream() return; } +#if LIBAVUTIL_VERSION_MAJOR < 58 if (mVideoCodec->capabilities & AV_CODEC_CAP_TRUNCATED) mVideoCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED; +#endif if (avcodec_parameters_to_context(mVideoCodecContext, mVideoStream->codecpar)) { LOG(LogError) << "VideoFFmpegComponent::startVideoStream(): " @@ -1484,8 +1500,10 @@ void VideoFFmpegComponent::startVideoStream() mAudioCodecContext = avcodec_alloc_context3(mAudioCodec); +#if LIBAVUTIL_VERSION_MAJOR < 58 if (mAudioCodec->capabilities & AV_CODEC_CAP_TRUNCATED) mAudioCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED; +#endif // Some formats want separate stream headers. if (mAudioCodecContext->flags & AVFMT_GLOBALHEADER)