From 7d2771c2002da98e38fd927491d9ed49d36ae93c Mon Sep 17 00:00:00 2001 From: Mirco Tornow Date: Thu, 16 Jan 2025 16:41:32 +0100 Subject: [PATCH] 600: Fix mov container getting wrong frame rate (#662) ### Linked issues Fixes #600 ### Summarize your change. add fix for mov container files, using avg_frame_rate instead of time_base ### Describe the reason for the change. The ffmpeg update causes this issue. ### Describe what you have tested and on which operating system. Tested on: Windows 10, Centos7, AlmaLinux9 Tested for .mov, .mp4, .mxf (not affected by change) --------- Signed-off-by: Mirco Tornow --- src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp b/src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp index 45267f488..e6a6f9290 100644 --- a/src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp +++ b/src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp @@ -712,6 +712,15 @@ isMP4format(AVFormatContext* avFormatContext) && strstr(avFormatContext->iformat->name, "mp4") != nullptr; } +bool +isMOVformat(AVFormatContext* avFormatContext) +{ + return avFormatContext!=nullptr + && avFormatContext->iformat!=nullptr + && avFormatContext->iformat->name!=nullptr + && strstr(avFormatContext->iformat->name, "mov") != nullptr; +} + int64_t findBestTS(int64_t goalTS, double frameDur, VideoTrack* track, bool finalPacket) { @@ -1340,7 +1349,12 @@ MovieFFMpegReader::getFirstFrame(AVRational rate) AVStream *tsStream = m_avFormatContext->streams[i]; AVRational tcRate = {tsStream->time_base.den, - tsStream->time_base.num}; + tsStream->time_base.num}; + + if (isMOVformat(m_avFormatContext)) + { + tcRate = tsStream->avg_frame_rate; + } AVDictionaryEntry *tcrEntry; tcrEntry = av_dict_get(tsStream->metadata, "reel_name", NULL, 0); @@ -3621,6 +3635,11 @@ MovieFFMpegReader::decodeImageAtFrame(int inframe, VideoTrack* track) AVRational rate = {tsStream->time_base.den, tsStream->time_base.num}; + if (isMOVformat(m_avFormatContext)) + { + rate = tsStream->avg_frame_rate; + } + // Correct wrong frame rates that seem to be generated by some codecs if ( rate.num > 1000 && rate.den == 1) {