mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
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 2322462404)
This commit is contained in:
parent
bf4561c606
commit
ec13c42800
3 changed files with 12 additions and 3 deletions
|
|
@ -775,7 +775,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
|||
long ptsUs = Util.scaleLargeTimestamp(pts, C.MICROS_PER_SECOND, track.movieTimescale);
|
||||
long timeInSegmentUs =
|
||||
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;
|
||||
if (copyMetadata && editedSizes[sampleIndex] > editedMaximumSize) {
|
||||
editedMaximumSize = sizes[j];
|
||||
|
|
@ -796,6 +799,12 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
|||
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
|
||||
private static Metadata parseUdtaMeta(ParsableByteArray meta, int limit) {
|
||||
meta.skipBytes(Atom.HEADER_SIZE);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ track 0:
|
|||
data = length 8, hash 72CBCBF5
|
||||
data = length 8, hash 79C07075
|
||||
sample 0:
|
||||
time = 0
|
||||
time = -6500
|
||||
flags = 1
|
||||
data = length 3, hash 4732
|
||||
sample 1:
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ track 0:
|
|||
data = length 8, hash 72CBCBF5
|
||||
data = length 8, hash 79C07075
|
||||
sample 0:
|
||||
time = 0
|
||||
time = -6500
|
||||
flags = 1
|
||||
data = length 3, hash 4732
|
||||
sample 1:
|
||||
|
|
|
|||
Loading…
Reference in a new issue