Pass initial timestamp offset to EncodedSampleExporter

When transmuxing, we usually only need to offset the timestamp by the position of a mediaItem in a sequence.

Trim optimization introduces another type of offset: for the transmux of the second part of the video we need to offset the timestamps by the total duration already trancoded by transformer.

PiperOrigin-RevId: 576134656
This commit is contained in:
tofunmi 2023-10-24 07:36:22 -07:00 committed by Copybara-Service
parent d6b11738e2
commit beed1bd76e
2 changed files with 7 additions and 3 deletions

View File

@ -33,6 +33,7 @@ import java.util.concurrent.atomic.AtomicLong;
private static final int MAX_INPUT_BUFFER_COUNT = 10;
private final Format format;
private final long initialTimestampOffsetUs;
private final AtomicLong nextMediaItemOffsetUs;
private final Queue<DecoderInputBuffer> availableInputBuffers;
private final Queue<DecoderInputBuffer> pendingInputBuffers;
@ -45,9 +46,11 @@ import java.util.concurrent.atomic.AtomicLong;
Format format,
TransformationRequest transformationRequest,
MuxerWrapper muxerWrapper,
FallbackListener fallbackListener) {
FallbackListener fallbackListener,
long initialTimestampOffsetUs) {
super(format, muxerWrapper);
this.format = format;
this.initialTimestampOffsetUs = initialTimestampOffsetUs;
nextMediaItemOffsetUs = new AtomicLong();
availableInputBuffers = new ConcurrentLinkedDeque<>();
ByteBuffer emptyBuffer = ByteBuffer.allocateDirect(0).order(ByteOrder.nativeOrder());
@ -82,7 +85,7 @@ import java.util.concurrent.atomic.AtomicLong;
if (inputBuffer.isEndOfStream()) {
inputEnded = true;
} else {
inputBuffer.timeUs += mediaItemOffsetUs;
inputBuffer.timeUs += mediaItemOffsetUs + initialTimestampOffsetUs;
pendingInputBuffers.add(inputBuffer);
}
return true;

View File

@ -617,7 +617,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
assetLoaderInputTracker.getAssetLoaderInputFormat(sequenceIndex, trackType),
transformationRequest,
muxerWrapper,
fallbackListener));
fallbackListener,
videoSampleTimestampOffsetUs));
}
/**