Skip to content

🎥 Make videos programmatically with React

`@remotion/media-parser`: Correct return timestamp of .avi files with more than 1 audio channel

Jonny Burger76730926c197
diff --git a/packages/media-parser/src/containers/riff/parse-movi.ts b/packages/media-parser/src/containers/riff/parse-movi.ts
index 8a8c815f42..8171be1379 100644
--- a/packages/media-parser/src/containers/riff/parse-movi.ts
+++ b/packages/media-parser/src/containers/riff/parse-movi.ts
@@ -61,7 +61,7 @@ export const handleChunk = async ({
cts: timestamp,
dts: timestamp,
data,
- duration: undefined,
+ duration: 1 / samplesPerSecond,
timestamp,
trackId,
type: keyOrDelta,
@@ -84,7 +84,12 @@ export const handleChunk = async ({
const trackId = parseInt(audioChunk[1], 10);
const strh = getStrhForIndex(state.structure.getRiffStructure(), trackId);
- const samplesPerSecond = strh.rate / strh.scale;
+ const {strf} = strh;
+ if (strf.type !== 'strf-box-audio') {
+ throw new Error('audio');
+ }
+
+ const samplesPerSecond = (strh.rate / strh.scale) * strf.numberOfChannels;
const nthSample = state.riff.sampleCounter.getSamplesForTrack(trackId);
const timeInSec = nthSample / samplesPerSecond;
const timestamp = timeInSec;