Slightly modify input formats

This commit is contained in:
Vanilagy
2025-01-06 19:45:47 +01:00
parent 2625dc7662
commit 7c65c2e7e9
2 changed files with 60 additions and 16 deletions
+3 -3
View File
@@ -50,13 +50,13 @@ export { Source, BufferSource, BlobSource, UrlSource } from './source';
export { export {
InputFormat, InputFormat,
IsobmffInputFormat, IsobmffInputFormat,
Mp4InputFormat,
QuickTimeInputFormat as MovInputFormat,
MatroskaInputFormat, MatroskaInputFormat,
ALL_FORMATS, ALL_FORMATS,
ISOBMFF,
MP4, MP4,
MOV, QTFF,
MATROSKA, MATROSKA,
MKV,
WEBM, WEBM,
} from './input-format'; } from './input-format';
export { Input, InputOptions } from './input'; export { Input, InputOptions } from './input';
+57 -13
View File
@@ -10,22 +10,28 @@ export abstract class InputFormat {
/** @internal */ /** @internal */
abstract _createDemuxer(input: Input): Demuxer; abstract _createDemuxer(input: Input): Demuxer;
abstract getName(): string;
abstract getMimeType(): string;
} }
/** @public */ /** @public */
export class IsobmffInputFormat extends InputFormat { export abstract class IsobmffInputFormat extends InputFormat {
/** @internal */ protected async _getMajorBrand(input: Input) {
override async _canReadInput(input: Input) {
const sourceSize = await input._mainReader.source._getSize(); const sourceSize = await input._mainReader.source._getSize();
if (sourceSize < 8) { if (sourceSize < 12) {
return false; return null;
} }
const isobmffReader = new IsobmffReader(input._mainReader); const isobmffReader = new IsobmffReader(input._mainReader);
isobmffReader.pos = 4; isobmffReader.pos = 4;
const fourCc = isobmffReader.readAscii(4); const fourCc = isobmffReader.readAscii(4);
return fourCc === 'ftyp'; if (fourCc !== 'ftyp') {
return null;
}
return isobmffReader.readAscii(4);
} }
/** @internal */ /** @internal */
@@ -34,6 +40,40 @@ export class IsobmffInputFormat extends InputFormat {
} }
} }
/** @public */
export class Mp4InputFormat extends IsobmffInputFormat {
/** @internal */
override async _canReadInput(input: Input) {
const majorBrand = await this._getMajorBrand(input);
return majorBrand !== 'qt ';
}
getName() {
return 'MP4';
}
getMimeType() {
return 'video/mp4';
}
}
/** @public */
export class QuickTimeInputFormat extends IsobmffInputFormat {
/** @internal */
override async _canReadInput(input: Input) {
const majorBrand = await this._getMajorBrand(input);
return majorBrand === 'qt ';
}
getName() {
return 'QuickTime File Format';
}
getMimeType() {
return 'video/quicktime';
}
}
/** @public */ /** @public */
export class MatroskaInputFormat extends InputFormat { export class MatroskaInputFormat extends InputFormat {
/** @internal */ /** @internal */
@@ -45,20 +85,24 @@ export class MatroskaInputFormat extends InputFormat {
override _createDemuxer(): never { override _createDemuxer(): never {
throw new Error('Not implemented'); throw new Error('Not implemented');
} }
getName() {
return 'Matroska';
}
getMimeType() {
return 'video/x-matroska';
}
} }
/** @public */ /** @public */
export const ISOBMFF = new IsobmffInputFormat(); export const MP4 = new Mp4InputFormat();
/** @public */ /** @public */
export const MP4 = ISOBMFF; export const QTFF = new QuickTimeInputFormat();
/** @public */
export const MOV = ISOBMFF;
/** @public */ /** @public */
export const MATROSKA = new MatroskaInputFormat(); export const MATROSKA = new MatroskaInputFormat();
/** @public */ /** @public */
export const MKV = MATROSKA;
/** @public */
export const WEBM = MATROSKA; export const WEBM = MATROSKA;
/** @public */ /** @public */
export const ALL_FORMATS: InputFormat[] = [ISOBMFF, MKV]; export const ALL_FORMATS: InputFormat[] = [MP4, QTFF, MATROSKA];