Add track count limit checking

This commit is contained in:
Vanilagy
2025-01-17 12:26:12 +01:00
parent 7b6567fcf0
commit d323c2be8e
4 changed files with 124 additions and 4 deletions
+39 -2
View File
@@ -2,18 +2,28 @@ import { AUDIO_CODECS, MediaCodec, PCM_CODECS, SUBTITLE_CODECS, VIDEO_CODECS } f
import { IsobmffMuxer } from './isobmff/isobmff-muxer';
import { MatroskaMuxer } from './matroska/matroska-muxer';
import { Muxer } from './muxer';
import { Output } from './output';
import { Output, TrackType } from './output';
import { WaveMuxer } from './wave/wave-muxer';
/** @public */
export type InclusiveRange = { min: number; max: number };
/** @public */
export type TrackCountLimits = {
[K in TrackType]: InclusiveRange;
} & {
total: InclusiveRange;
};
/** @public */
export abstract class OutputFormat {
/** @internal */
abstract _createMuxer(output: Output): Muxer;
/** @internal */
abstract _getName(): string;
abstract getFileExtension(): string;
abstract getSupportedCodecs(): MediaCodec[];
abstract getSupportedTrackCounts(): TrackCountLimits;
getSupportedVideoCodecs() {
return this.getSupportedCodecs().filter(codec => (VIDEO_CODECS as readonly string[]).includes(codec));
@@ -57,6 +67,15 @@ export abstract class IsobmffOutputFormat extends OutputFormat {
this._options = options;
}
getSupportedTrackCounts(): TrackCountLimits {
return {
video: { min: 0, max: Infinity },
audio: { min: 0, max: Infinity },
subtitle: { min: 0, max: Infinity },
total: { min: 1, max: 2 ** 32 - 1 }, // Have fun reaching this one
};
}
/** @internal */
_createMuxer(output: Output) {
return new IsobmffMuxer(output, this);
@@ -161,6 +180,15 @@ export class MkvOutputFormat extends OutputFormat {
return 'Matroska';
}
getSupportedTrackCounts(): TrackCountLimits {
return {
video: { min: 0, max: Infinity },
audio: { min: 0, max: Infinity },
subtitle: { min: 0, max: Infinity },
total: { min: 1, max: 127 },
};
}
getFileExtension() {
return '.mkv';
}
@@ -228,6 +256,15 @@ export class WaveOutputFormat extends OutputFormat {
return 'WAVE';
}
getSupportedTrackCounts(): TrackCountLimits {
return {
video: { min: 0, max: 0 },
audio: { min: 1, max: 1 },
subtitle: { min: 0, max: 0 },
total: { min: 1, max: 1 },
};
}
getFileExtension() {
return '.wav';
}