mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 05:43:50 +02:00
Add ability to group output tracks in Conversion API
This commit is contained in:
+25
-1
@@ -48,7 +48,7 @@ import {
|
|||||||
promiseWithResolvers,
|
promiseWithResolvers,
|
||||||
Rotation,
|
Rotation,
|
||||||
} from './misc';
|
} from './misc';
|
||||||
import { Output, TrackType } from './output';
|
import { Output, OutputTrackGroup, TrackType } from './output';
|
||||||
import { Mp4OutputFormat } from './output-format';
|
import { Mp4OutputFormat } from './output-format';
|
||||||
import { AudioSample, clampCropRectangle, validateCropRectangle, VideoSample } from './sample';
|
import { AudioSample, clampCropRectangle, validateCropRectangle, VideoSample } from './sample';
|
||||||
import { MetadataTags, validateMetadataTags } from './metadata';
|
import { MetadataTags, validateMetadataTags } from './metadata';
|
||||||
@@ -251,6 +251,8 @@ export type ConversionVideoOptions = {
|
|||||||
* encoder configuration.
|
* encoder configuration.
|
||||||
*/
|
*/
|
||||||
processedHeight?: number;
|
processedHeight?: number;
|
||||||
|
/** Defines the group(s) the output track is a part of. Same semantics as {@link BaseTrackMetadata.group}. */
|
||||||
|
group?: OutputTrackGroup | OutputTrackGroup[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -295,6 +297,8 @@ export type ConversionAudioOptions = {
|
|||||||
* encoder configuration.
|
* encoder configuration.
|
||||||
*/
|
*/
|
||||||
processedSampleRate?: number;
|
processedSampleRate?: number;
|
||||||
|
/** Defines the group(s) the output track is a part of. Same semantics as {@link BaseTrackMetadata.group}. */
|
||||||
|
group?: OutputTrackGroup | OutputTrackGroup[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateVideoOptions = (videoOptions: ConversionVideoOptions) => {
|
const validateVideoOptions = (videoOptions: ConversionVideoOptions) => {
|
||||||
@@ -392,6 +396,15 @@ const validateVideoOptions = (videoOptions: ConversionVideoOptions) => {
|
|||||||
+ ' \'prefer-software\'.',
|
+ ' \'prefer-software\'.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
videoOptions?.group !== undefined
|
||||||
|
&& !(
|
||||||
|
videoOptions.group instanceof OutputTrackGroup
|
||||||
|
|| (Array.isArray(videoOptions.group) && videoOptions.group.every(x => x instanceof OutputTrackGroup))
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new TypeError('options.video.group, when provided, must be a string or an array of strings.');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateAudioOptions = (audioOptions: ConversionAudioOptions) => {
|
const validateAudioOptions = (audioOptions: ConversionAudioOptions) => {
|
||||||
@@ -443,6 +456,15 @@ const validateAudioOptions = (audioOptions: ConversionAudioOptions) => {
|
|||||||
) {
|
) {
|
||||||
throw new TypeError('options.audio.processedSampleRate, when provided, must be a positive integer.');
|
throw new TypeError('options.audio.processedSampleRate, when provided, must be a positive integer.');
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
audioOptions?.group !== undefined
|
||||||
|
&& !(
|
||||||
|
audioOptions.group instanceof OutputTrackGroup
|
||||||
|
|| (Array.isArray(audioOptions.group) && audioOptions.group.every(x => x instanceof OutputTrackGroup))
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new TypeError('options.audio.group, when provided, must be a string or an array of strings.');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const FALLBACK_NUMBER_OF_CHANNELS = 2;
|
const FALLBACK_NUMBER_OF_CHANNELS = 2;
|
||||||
@@ -1453,6 +1475,7 @@ export class Conversion {
|
|||||||
name: await track.getName() ?? undefined,
|
name: await track.getName() ?? undefined,
|
||||||
disposition: await track.getDisposition(),
|
disposition: await track.getDisposition(),
|
||||||
rotation: outputTrackRotation,
|
rotation: outputTrackRotation,
|
||||||
|
group: trackOptions.group,
|
||||||
});
|
});
|
||||||
this._addedCounts.video++;
|
this._addedCounts.video++;
|
||||||
this._totalTrackCount++;
|
this._totalTrackCount++;
|
||||||
@@ -1709,6 +1732,7 @@ export class Conversion {
|
|||||||
languageCode: isIso639Dash2LanguageCode(audioTrackLanguageCode) ? audioTrackLanguageCode : undefined,
|
languageCode: isIso639Dash2LanguageCode(audioTrackLanguageCode) ? audioTrackLanguageCode : undefined,
|
||||||
name: await track.getName() ?? undefined,
|
name: await track.getName() ?? undefined,
|
||||||
disposition: await track.getDisposition(),
|
disposition: await track.getDisposition(),
|
||||||
|
group: trackOptions.group,
|
||||||
});
|
});
|
||||||
this._addedCounts.audio++;
|
this._addedCounts.audio++;
|
||||||
this._totalTrackCount++;
|
this._totalTrackCount++;
|
||||||
|
|||||||
Reference in New Issue
Block a user