Commit 39718b37 by tonihei Committed by Tianyi Feng

Do not trim audio samples by changing their timestamp

MP4 edit lists sometimes ask to start playback between two samples.
If this happens, we currently change the timestamp of the first
sample to zero to trim it (e.g. to display the first frame for a
slightly shorter period of time). However, we can't do this to audio
samples are they have an inherent duration and trimming them this
way is not possible.

PiperOrigin-RevId: 543420218
(cherry picked from commit 2cdc964066b1c9c9c4e90583b3f4b1579290c69b)
parent cc06f275
...@@ -783,7 +783,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -783,7 +783,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
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(
max(0, timestamps[j] - editMediaTime), C.MICROS_PER_SECOND, track.timescale); timestamps[j] - editMediaTime, C.MICROS_PER_SECOND, track.timescale);
if (canTrimSamplesWithTimestampChange(track.type)) {
timeInSegmentUs = max(0, timeInSegmentUs);
}
editedTimestamps[sampleIndex] = ptsUs + timeInSegmentUs; editedTimestamps[sampleIndex] = ptsUs + timeInSegmentUs;
if (copyMetadata && editedSizes[sampleIndex] > editedMaximumSize) { if (copyMetadata && editedSizes[sampleIndex] > editedMaximumSize) {
editedMaximumSize = sizes[j]; editedMaximumSize = sizes[j];
...@@ -804,6 +807,12 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -804,6 +807,12 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
editedDurationUs); editedDurationUs);
} }
private static boolean canTrimSamplesWithTimestampChange(@C.TrackType int trackType) {
// Audio samples have an inherent duration and we can't trim data by changing the sample
// timestamp alone.
return trackType != C.TRACK_TYPE_AUDIO;
}
@Nullable @Nullable
private static Metadata parseUdtaMeta(ParsableByteArray meta, int limit) { private static Metadata parseUdtaMeta(ParsableByteArray meta, int limit) {
meta.skipBytes(Atom.HEADER_SIZE); meta.skipBytes(Atom.HEADER_SIZE);
......
...@@ -22,7 +22,7 @@ track 0: ...@@ -22,7 +22,7 @@ track 0:
data = length 8, hash 72CBCBF5 data = length 8, hash 72CBCBF5
data = length 8, hash 79C07075 data = length 8, hash 79C07075
sample 0: sample 0:
time = 0 time = -6500
flags = 1 flags = 1
data = length 3, hash 4732 data = length 3, hash 4732
sample 1: sample 1:
......
...@@ -22,7 +22,7 @@ track 0: ...@@ -22,7 +22,7 @@ track 0:
data = length 8, hash 72CBCBF5 data = length 8, hash 72CBCBF5
data = length 8, hash 79C07075 data = length 8, hash 79C07075
sample 0: sample 0:
time = 0 time = -6500
flags = 1 flags = 1
data = length 3, hash 4732 data = length 3, hash 4732
sample 1: sample 1:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment