mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
Add WebMInputFormat, add OutputFormat.getFileExtension()
This commit is contained in:
+1
-1
@@ -174,5 +174,5 @@ Testing... <00:17.350>One... <00:18.125>Two...
|
|||||||
await output.finalize();
|
await output.finalize();
|
||||||
|
|
||||||
console.log(target);
|
console.log(target);
|
||||||
download(new Blob([target.buffer]), 'test.webm');
|
download(new Blob([target.buffer]), 'test' + format.getFileExtension());
|
||||||
</script>
|
</script>
|
||||||
+2
-1
@@ -52,8 +52,9 @@ export {
|
|||||||
InputFormat,
|
InputFormat,
|
||||||
IsobmffInputFormat,
|
IsobmffInputFormat,
|
||||||
Mp4InputFormat,
|
Mp4InputFormat,
|
||||||
QuickTimeInputFormat as MovInputFormat,
|
QuickTimeInputFormat,
|
||||||
MatroskaInputFormat,
|
MatroskaInputFormat,
|
||||||
|
WebMInputFormat,
|
||||||
WaveInputFormat,
|
WaveInputFormat,
|
||||||
ALL_FORMATS,
|
ALL_FORMATS,
|
||||||
MP4,
|
MP4,
|
||||||
|
|||||||
+26
-5
@@ -81,7 +81,7 @@ export class QuickTimeInputFormat extends IsobmffInputFormat {
|
|||||||
/** @public */
|
/** @public */
|
||||||
export class MatroskaInputFormat extends InputFormat {
|
export class MatroskaInputFormat extends InputFormat {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
async _canReadInput(input: Input) {
|
protected async isSupportedEBMLOfDocType(input: Input, desiredDocType: string) {
|
||||||
const sourceSize = await input._mainReader.source._getSize();
|
const sourceSize = await input._mainReader.source._getSize();
|
||||||
if (sourceSize < 8) {
|
if (sourceSize < 8) {
|
||||||
return false;
|
return false;
|
||||||
@@ -89,7 +89,7 @@ export class MatroskaInputFormat extends InputFormat {
|
|||||||
|
|
||||||
const ebmlReader = new EBMLReader(input._mainReader);
|
const ebmlReader = new EBMLReader(input._mainReader);
|
||||||
const varIntSize = ebmlReader.readVarIntSize();
|
const varIntSize = ebmlReader.readVarIntSize();
|
||||||
if (varIntSize < 1 || varIntSize > 6) {
|
if (varIntSize < 1 || varIntSize > 8) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ export class MatroskaInputFormat extends InputFormat {
|
|||||||
}; break;
|
}; break;
|
||||||
case EBMLId.DocType: {
|
case EBMLId.DocType: {
|
||||||
const docType = ebmlReader.readString(size);
|
const docType = ebmlReader.readString(size);
|
||||||
if (docType !== 'matroska' && docType !== 'webm') {
|
if (docType !== desiredDocType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}; break;
|
}; break;
|
||||||
@@ -142,6 +142,11 @@ export class MatroskaInputFormat extends InputFormat {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
_canReadInput(input: Input) {
|
||||||
|
return this.isSupportedEBMLOfDocType(input, 'matroska');
|
||||||
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_createDemuxer(input: Input) {
|
_createDemuxer(input: Input) {
|
||||||
return new MatroskaDemuxer(input);
|
return new MatroskaDemuxer(input);
|
||||||
@@ -156,6 +161,22 @@ export class MatroskaInputFormat extends InputFormat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export class WebMInputFormat extends MatroskaInputFormat {
|
||||||
|
/** @internal */
|
||||||
|
override _canReadInput(input: Input) {
|
||||||
|
return this.isSupportedEBMLOfDocType(input, 'webm');
|
||||||
|
}
|
||||||
|
|
||||||
|
override getName() {
|
||||||
|
return 'WebM';
|
||||||
|
}
|
||||||
|
|
||||||
|
override getMimeType() {
|
||||||
|
return 'video/webm';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export class WaveInputFormat extends InputFormat {
|
export class WaveInputFormat extends InputFormat {
|
||||||
async _canReadInput(input: Input) {
|
async _canReadInput(input: Input) {
|
||||||
@@ -196,9 +217,9 @@ export const QTFF = new QuickTimeInputFormat();
|
|||||||
/** @public */
|
/** @public */
|
||||||
export const MATROSKA = new MatroskaInputFormat();
|
export const MATROSKA = new MatroskaInputFormat();
|
||||||
/** @public */
|
/** @public */
|
||||||
export const WEBM = MATROSKA;
|
export const WEBM = new WebMInputFormat();
|
||||||
/** @public */
|
/** @public */
|
||||||
export const WAVE = new WaveInputFormat();
|
export const WAVE = new WaveInputFormat();
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export const ALL_FORMATS: InputFormat[] = [MP4, QTFF, MATROSKA, WAVE];
|
export const ALL_FORMATS: InputFormat[] = [MP4, QTFF, MATROSKA, WEBM, WAVE];
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export abstract class OutputFormat {
|
|||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
abstract _getName(): string;
|
abstract _getName(): string;
|
||||||
|
abstract getFileExtension(): string;
|
||||||
abstract getSupportedCodecs(): MediaCodec[];
|
abstract getSupportedCodecs(): MediaCodec[];
|
||||||
|
|
||||||
getSupportedVideoCodecs() {
|
getSupportedVideoCodecs() {
|
||||||
@@ -69,6 +70,10 @@ export class Mp4OutputFormat extends IsobmffOutputFormat {
|
|||||||
return 'MP4';
|
return 'MP4';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFileExtension() {
|
||||||
|
return '.mp4';
|
||||||
|
}
|
||||||
|
|
||||||
getSupportedCodecs() {
|
getSupportedCodecs() {
|
||||||
return Mp4OutputFormat.getSupportedCodecs();
|
return Mp4OutputFormat.getSupportedCodecs();
|
||||||
}
|
}
|
||||||
@@ -98,6 +103,10 @@ export class MovOutputFormat extends IsobmffOutputFormat {
|
|||||||
return 'MOV';
|
return 'MOV';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFileExtension() {
|
||||||
|
return '.mov';
|
||||||
|
}
|
||||||
|
|
||||||
getSupportedCodecs() {
|
getSupportedCodecs() {
|
||||||
return MovOutputFormat.getSupportedCodecs();
|
return MovOutputFormat.getSupportedCodecs();
|
||||||
}
|
}
|
||||||
@@ -152,6 +161,10 @@ export class MkvOutputFormat extends OutputFormat {
|
|||||||
return 'Matroska';
|
return 'Matroska';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFileExtension() {
|
||||||
|
return '.mkv';
|
||||||
|
}
|
||||||
|
|
||||||
getSupportedCodecs() {
|
getSupportedCodecs() {
|
||||||
return MkvOutputFormat.getSupportedCodecs();
|
return MkvOutputFormat.getSupportedCodecs();
|
||||||
}
|
}
|
||||||
@@ -181,6 +194,10 @@ export class WebMOutputFormat extends MkvOutputFormat {
|
|||||||
return 'WebM';
|
return 'WebM';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override getFileExtension() {
|
||||||
|
return '.webm';
|
||||||
|
}
|
||||||
|
|
||||||
static override getSupportedCodecs(): MediaCodec[] {
|
static override getSupportedCodecs(): MediaCodec[] {
|
||||||
return [
|
return [
|
||||||
'vp8', 'vp9', 'av1',
|
'vp8', 'vp9', 'av1',
|
||||||
@@ -211,6 +228,10 @@ export class WaveOutputFormat extends OutputFormat {
|
|||||||
return 'WAVE';
|
return 'WAVE';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFileExtension() {
|
||||||
|
return '.wav';
|
||||||
|
}
|
||||||
|
|
||||||
getSupportedCodecs() {
|
getSupportedCodecs() {
|
||||||
return WaveOutputFormat.getSupportedCodecs();
|
return WaveOutputFormat.getSupportedCodecs();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user