mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 19:03:46 +02:00
Slightly modify input formats
This commit is contained in:
+57
-13
@@ -10,22 +10,28 @@ export abstract class InputFormat {
|
||||
|
||||
/** @internal */
|
||||
abstract _createDemuxer(input: Input): Demuxer;
|
||||
|
||||
abstract getName(): string;
|
||||
abstract getMimeType(): string;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export class IsobmffInputFormat extends InputFormat {
|
||||
/** @internal */
|
||||
override async _canReadInput(input: Input) {
|
||||
export abstract class IsobmffInputFormat extends InputFormat {
|
||||
protected async _getMajorBrand(input: Input) {
|
||||
const sourceSize = await input._mainReader.source._getSize();
|
||||
if (sourceSize < 8) {
|
||||
return false;
|
||||
if (sourceSize < 12) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isobmffReader = new IsobmffReader(input._mainReader);
|
||||
isobmffReader.pos = 4;
|
||||
const fourCc = isobmffReader.readAscii(4);
|
||||
|
||||
return fourCc === 'ftyp';
|
||||
if (fourCc !== 'ftyp') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return isobmffReader.readAscii(4);
|
||||
}
|
||||
|
||||
/** @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 */
|
||||
export class MatroskaInputFormat extends InputFormat {
|
||||
/** @internal */
|
||||
@@ -45,20 +85,24 @@ export class MatroskaInputFormat extends InputFormat {
|
||||
override _createDemuxer(): never {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
getName() {
|
||||
return 'Matroska';
|
||||
}
|
||||
|
||||
getMimeType() {
|
||||
return 'video/x-matroska';
|
||||
}
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export const ISOBMFF = new IsobmffInputFormat();
|
||||
export const MP4 = new Mp4InputFormat();
|
||||
/** @public */
|
||||
export const MP4 = ISOBMFF;
|
||||
/** @public */
|
||||
export const MOV = ISOBMFF;
|
||||
export const QTFF = new QuickTimeInputFormat();
|
||||
/** @public */
|
||||
export const MATROSKA = new MatroskaInputFormat();
|
||||
/** @public */
|
||||
export const MKV = MATROSKA;
|
||||
/** @public */
|
||||
export const WEBM = MATROSKA;
|
||||
|
||||
/** @public */
|
||||
export const ALL_FORMATS: InputFormat[] = [ISOBMFF, MKV];
|
||||
export const ALL_FORMATS: InputFormat[] = [MP4, QTFF, MATROSKA];
|
||||
|
||||
Reference in New Issue
Block a user