Skip to content

Commit

Permalink
600: Fix mov container getting wrong frame rate (#662)
Browse files Browse the repository at this point in the history
<!--
Thanks for your contribution! Please read this comment in its entirety.
It's quite important.
When a contributor merges the pull request, the title and the
description will be used to build the merge commit!

### Pull Request TITLE

It should be in the following format:

[ 12345: Summary of the changes made ] Where 12345 is the corresponding
Github Issue

OR

[ Summary of the changes made ] If it's solving something trivial, like
fixing a typo.
-->

### Linked issues
<!--
Link the Issue(s) this Pull Request is related to.

Each PR should link to at least one issue, in the form:

Use one line for each Issue. This allows auto-closing the related issue
when the fix is merged.

Fixes #12345
Fixes #54345
-->
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 <[email protected]>
  • Loading branch information
mircotornow authored Jan 16, 2025
1 parent a2f8771 commit 7d2771c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 7d2771c

Please sign in to comment.