Skip to content

🎥 Make videos programmatically with React

Fix .avi timing out

Jonny Burger420d67f06b01
diff --git a/packages/media-parser/src/boxes/riff/parse-movi.ts b/packages/media-parser/src/boxes/riff/parse-movi.ts
index 887bc4a281..fc1d4aa85f 100644
--- a/packages/media-parser/src/boxes/riff/parse-movi.ts
+++ b/packages/media-parser/src/boxes/riff/parse-movi.ts
@@ -88,23 +88,33 @@ export const handleChunk = async ({
const nthSample = options.parserState.getSamplesForTrack(trackId);
const timeInSec = nthSample / samplesPerSecond;
const timestamp = timeInSec;
- const duration = 1 / samplesPerSecond;
- await options.parserState.onAudioSample(
- trackId,
- convertAudioOrVideoSampleToWebCodecsTimestamps(
- {
- cts: timestamp,
- dts: timestamp,
- data: iterator.getSlice(ckSize),
- duration,
- timestamp,
- trackId,
- type: 'key',
- },
- 1,
- ),
- );
+ const data = iterator.getSlice(ckSize);
+
+ // In example.avi, we have samples with 0 data
+ // Chrome fails on these
+
+ // We must also NOT pass a duration because if the the next sample is 0,
+ // this sample would be longer. Chrome will pad it with silence.
+ // If we'd pass a duration instead, it would shift the audio and we think that audio is not finished
+
+ if (data.length > 0) {
+ await options.parserState.onAudioSample(
+ trackId,
+ convertAudioOrVideoSampleToWebCodecsTimestamps(
+ {
+ cts: timestamp,
+ dts: timestamp,
+ data,
+ duration: undefined,
+ timestamp,
+ trackId,
+ type: 'key',
+ },
+ 1,
+ ),
+ );
+ }
}
};
diff --git a/packages/webcodecs/src/audio-decoder.ts b/packages/webcodecs/src/audio-decoder.ts
index fbd54a8a92..68c3fef238 100644
--- a/packages/webcodecs/src/audio-decoder.ts
+++ b/packages/webcodecs/src/audio-decoder.ts
@@ -130,12 +130,6 @@ export const createAudioDecoder = ({
return {
processSample: (sample: AudioOrVideoSample) => {
- // In example.avi, we have samples with 0 data
- // Chrome fails on these
- if (sample.data.length === 0) {
- return queue;
- }
-
queue = queue.then(() => processSample(sample));
return queue;
},