Skip to content

Commit

Permalink
[web-wasm] Fix incorrent chunk timestamps (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
noituri authored Jan 8, 2025
1 parent 55cddb9 commit 21253b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ts/@live-compositor/web-wasm/src/input/mp4/demuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ export class MP4Demuxer {
assert(this.samplesCount !== undefined);

for (const sample of samples) {
const pts = (sample.cts * 1_000) / sample.timescale;
const pts = (sample.cts * 1_000_000) / sample.timescale;
if (this.ptsOffset === undefined) {
this.ptsOffset = -pts;
}

const chunk = new EncodedVideoChunk({
type: sample.is_sync ? 'key' : 'delta',
timestamp: pts + this.ptsOffset,
duration: (sample.duration * 1_000) / sample.timescale,
duration: (sample.duration * 1_000_000) / sample.timescale,
data: sample.data,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ export default class DecodingFrameProducer implements InputFrameProducer {
assert(framerate);

const frameDuration = framerateToDurationMs(framerate);
const targetPts = framePts + frameDuration * MAX_BUFFERING_SIZE;
const targetPtsUs = (framePts + frameDuration * MAX_BUFFERING_SIZE) * 1000;

let chunk = this.source.peekChunk();
while (chunk && chunk.timestamp <= targetPts) {
while (chunk && chunk.timestamp <= targetPtsUs) {
this.decoder.decode(chunk);
this.source.nextChunk();
chunk = this.source.peekChunk();
Expand Down

0 comments on commit 21253b0

Please sign in to comment.