mirror of
https://github.com/androidx/media.git
synced 2025-05-08 08:00:49 +08:00
MP4 edit lists: Use floor rather than ceil to find first sample
If the start time of the edit falls within a sample, start from that sample rather than the next one. This ensures playback can start from the correct point if the sample is a keyframe, rather than having to start from the next one. Issue: #7133 PiperOrigin-RevId: 302639115
This commit is contained in:
parent
d18292c9c9
commit
1d6bd0de15
@ -433,10 +433,15 @@ import java.util.List;
|
|||||||
long editDuration =
|
long editDuration =
|
||||||
Util.scaleLargeTimestamp(
|
Util.scaleLargeTimestamp(
|
||||||
track.editListDurations[i], track.timescale, track.movieTimescale);
|
track.editListDurations[i], track.timescale, track.movieTimescale);
|
||||||
startIndices[i] = Util.binarySearchCeil(timestamps, editMediaTime, true, true);
|
startIndices[i] =
|
||||||
|
Util.binarySearchFloor(
|
||||||
|
timestamps, editMediaTime, /* inclusive= */ true, /* stayInBounds= */ true);
|
||||||
endIndices[i] =
|
endIndices[i] =
|
||||||
Util.binarySearchCeil(
|
Util.binarySearchCeil(
|
||||||
timestamps, editMediaTime + editDuration, omitClippedSample, false);
|
timestamps,
|
||||||
|
editMediaTime + editDuration,
|
||||||
|
/* inclusive= */ omitClippedSample,
|
||||||
|
/* stayInBounds= */ false);
|
||||||
while (startIndices[i] < endIndices[i]
|
while (startIndices[i] < endIndices[i]
|
||||||
&& (flags[startIndices[i]] & C.BUFFER_FLAG_KEY_FRAME) == 0) {
|
&& (flags[startIndices[i]] & C.BUFFER_FLAG_KEY_FRAME) == 0) {
|
||||||
// Applying the edit correctly would require prerolling from the previous sync sample. In
|
// Applying the edit correctly would require prerolling from the previous sync sample. In
|
||||||
@ -474,7 +479,7 @@ import java.util.List;
|
|||||||
long ptsUs = Util.scaleLargeTimestamp(pts, C.MICROS_PER_SECOND, track.movieTimescale);
|
long ptsUs = Util.scaleLargeTimestamp(pts, C.MICROS_PER_SECOND, track.movieTimescale);
|
||||||
long timeInSegmentUs =
|
long timeInSegmentUs =
|
||||||
Util.scaleLargeTimestamp(
|
Util.scaleLargeTimestamp(
|
||||||
timestamps[j] - editMediaTime, C.MICROS_PER_SECOND, track.timescale);
|
Math.max(0, timestamps[j] - editMediaTime), C.MICROS_PER_SECOND, track.timescale);
|
||||||
editedTimestamps[sampleIndex] = ptsUs + timeInSegmentUs;
|
editedTimestamps[sampleIndex] = ptsUs + timeInSegmentUs;
|
||||||
if (copyMetadata && editedSizes[sampleIndex] > editedMaximumSize) {
|
if (copyMetadata && editedSizes[sampleIndex] > editedMaximumSize) {
|
||||||
editedMaximumSize = sizes[j];
|
editedMaximumSize = sizes[j];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user