Skip to content

Commit

Permalink
Fix off-by-one in MP4 CTTS processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevcairiel committed Nov 11, 2022
1 parent 9fcd220 commit fd3c1c0
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions demuxer/Demuxers/LAVFDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2084,22 +2084,17 @@ STDMETHODIMP CLAVFDemuxer::GetKeyFrames(const GUID *pFormat, REFERENCE_TIME *pKF
timestamp += (sc->sample_offsets[i] + sc->dts_shift);
else if (sc->ctts_count)
{
if (ctts_sample_counter > i)
// find the next CTTS entry, if needed
while (ctts_sample_counter <= i && ctts_index < sc->ctts_count)
{
timestamp += (sc->ctts_data[ctts_index].duration + sc->dts_shift);
ctts_sample_counter += sc->ctts_data[ctts_index++].count;
}

// apply the CTTS offset to the timestamp
if (ctts_sample_counter > i)
timestamp += (sc->ctts_data[ctts_index - 1].duration + sc->dts_shift);
else
{
for (; ctts_index < sc->ctts_count; ctts_index++)
{
ctts_sample_counter += sc->ctts_data[ctts_index].count;
if (ctts_sample_counter > i)
{
timestamp += (sc->ctts_data[ctts_index].duration + sc->dts_shift);
break;
}
}
}
timestamp += (sc->min_corrected_pts + sc->dts_shift);
}
else
timestamp += (sc->min_corrected_pts + sc->dts_shift);
Expand Down

0 comments on commit fd3c1c0

Please sign in to comment.