From 8ceb119b4ad08230c5415887c4d055f612d87236 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 31 May 2023 12:01:44 +0200 Subject: [PATCH] Cleanup: Deprecation warning in the FFmpeg Since avuitl 57.30.100 the pkt_duration is deprecated, and the duration is to be used instead. The units seems to match, and also from the avcodec decoder.c the `frame->pkt_duration = frame->duration;` so does not seem we need to do any conversion. The change in FFmpeg is from 2022, which is a bit recent, so the access to the duration is hidden behind a compatibility API. --- intern/ffmpeg/ffmpeg_compat.h | 11 +++++++++++ source/blender/imbuf/intern/anim_movie.cc | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/intern/ffmpeg/ffmpeg_compat.h b/intern/ffmpeg/ffmpeg_compat.h index 53f28239760..53c4e100e26 100644 --- a/intern/ffmpeg/ffmpeg_compat.h +++ b/intern/ffmpeg/ffmpeg_compat.h @@ -123,6 +123,17 @@ int64_t av_get_pts_from_frame(AVFrame *picture) return timestamp_from_pts_or_dts(picture->pts, picture->pkt_dts); } +/* Duration of the frame, in the same units as pts. 0 if unknown. */ +FFMPEG_INLINE +int64_t av_get_frame_duration_in_pts_units(const AVFrame *picture) +{ +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 30, 100) + return picture->pkt_duration; +#else + return picture->duration; +#endif +} + /* -------------------------------------------------------------------- */ /** \name Deinterlace code block * diff --git a/source/blender/imbuf/intern/anim_movie.cc b/source/blender/imbuf/intern/anim_movie.cc index 89341f7635d..e244e0e3b24 100644 --- a/source/blender/imbuf/intern/anim_movie.cc +++ b/source/blender/imbuf/intern/anim_movie.cc @@ -955,7 +955,7 @@ static AVFrame *ffmpeg_frame_by_pts_get(struct anim *anim, int64_t pts_to_search const bool backup_frame_ready = anim->pFrame_backup_complete; const int64_t recent_start = av_get_pts_from_frame(anim->pFrame); - const int64_t recent_end = recent_start + anim->pFrame->pkt_duration; + const int64_t recent_end = recent_start + av_get_frame_duration_in_pts_units(anim->pFrame); const int64_t backup_start = backup_frame_ready ? av_get_pts_from_frame(anim->pFrame_backup) : 0; AVFrame *best_frame = nullptr; @@ -1164,7 +1164,7 @@ static bool ffmpeg_is_first_frame_decode(struct anim *anim) static void ffmpeg_scan_log(struct anim *anim, int64_t pts_to_search) { int64_t frame_pts_start = av_get_pts_from_frame(anim->pFrame); - int64_t frame_pts_end = frame_pts_start + anim->pFrame->pkt_duration; + int64_t frame_pts_end = frame_pts_start + av_get_frame_duration_in_pts_units(anim->pFrame); av_log(anim->pFormatCtx, AV_LOG_DEBUG, " SCAN WHILE: PTS range %" PRId64 " - %" PRId64 " in search of %" PRId64 "\n", -- 2.30.2