diff --git a/src/backends/beamcoder.ts b/src/backends/beamcoder.ts index 2a17919..e813e2b 100644 --- a/src/backends/beamcoder.ts +++ b/src/backends/beamcoder.ts @@ -243,7 +243,11 @@ export class BeamcoderExtractor extends BaseExtractor implements Extractor { * This is the duration of the first video stream in the file expressed in seconds. */ get duration(): number { - return this.ptsToTime(this.#demuxer.streams[this.#streamIndex].duration); + const stream = this.#demuxer.streams[this.#streamIndex]; + if (stream.duration !== null) { + return this.ptsToTime(stream.duration); + } + return this.ptsToTime(this.#demuxer.duration) / 1000; } /** diff --git a/test/framefusion.test.ts b/test/framefusion.test.ts index a013405..9553d21 100644 --- a/test/framefusion.test.ts +++ b/test/framefusion.test.ts @@ -60,7 +60,7 @@ describe('FrameFusion', () => { await extractor.dispose(); }); - it('can get duration', async() => { + it('can get duration from mp4', async() => { // Arrange const extractor = await BeamcoderExtractor.create({ inputFileOrUrl: 'https://storage.googleapis.com/lumen5-prod-images/countTo60.mp4', @@ -73,6 +73,19 @@ describe('FrameFusion', () => { await extractor.dispose(); }); + it.only('can get duration from webm', async() => { + // Arrange + const extractor = await BeamcoderExtractor.create({ + inputFileOrUrl: 'https://storage.googleapis.com/lumen5-prod-video/anita-6uTzyZtNRKztypC.webm', + }); + + // Act and Assert + expect(extractor.duration).to.equal(115.248); + + // Cleanup + await extractor.dispose(); + }); + it('can get duration when audio stream is longer than video stream', async() => { // Arrange const extractor = await BeamcoderExtractor.create({