Skip to content

Commit

Permalink
Merge pull request #61 from Lumen5/LU-3510-WebmDuration
Browse files Browse the repository at this point in the history
LU-3510 Adding duration support for webm
  • Loading branch information
animanathome authored Oct 28, 2024
2 parents a70d489 + 060f966 commit 9228fc8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/backends/beamcoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion test/framefusion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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({
Expand Down

0 comments on commit 9228fc8

Please sign in to comment.