diff --git a/package.json b/package.json index 7bf6f55..cb524f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lumen5/framefusion", - "version": "1.0.6", + "version": "1.0.7", "type": "module", "scripts": { "docs": "typedoc framefusion.ts", diff --git a/src/backends/beamcoder.ts b/src/backends/beamcoder.ts index 71681a1..def3674 100644 --- a/src/backends/beamcoder.ts +++ b/src/backends/beamcoder.ts @@ -242,7 +242,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 2420d5b..2400a32 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({