Add "force" transform option, formalize that transformations bake in rotation

This commit is contained in:
Vanilagy
2026-04-01 14:34:05 +02:00
parent 024660773b
commit 1c08589021
3 changed files with 49 additions and 3 deletions
+8
View File
@@ -112,6 +112,11 @@ export type VideoEncodingConfig = {
process?: (sample: VideoSample) => MaybePromise<
CanvasImageSource | VideoSample | (CanvasImageSource | VideoSample)[] | null
>;
/**
* Forces every video frame through the transformation step even if no transformation properties are defined.
* This can be used, for example, to bake rotation into the encoded video frames.
*/
force?: boolean;
};
/** Called for each successfully encoded packet. Both the packet and the encoding metadata are passed. */
@@ -202,6 +207,9 @@ export const validateVideoEncodingConfig = (config: VideoEncodingConfig) => {
) {
throw new TypeError('config.transform.frameRate, when provided, must be a finite positive number.');
}
if (config.transform.force !== undefined && typeof config.transform.force !== 'boolean') {
throw new TypeError('config.transform.force, when provided, must be a boolean.');
}
}
if (config.onEncodedPacket !== undefined && typeof config.onEncodedPacket !== 'function') {
throw new TypeError('config.onEncodedChunk, when provided, must be a function.');
+2 -1
View File
@@ -309,7 +309,8 @@ class VideoEncoderWrapper {
const hasTransformConfig = config.transform?.width !== undefined
|| config.transform?.height !== undefined
|| config.transform?.rotate !== undefined
|| config.transform?.crop !== undefined;
|| config.transform?.crop !== undefined
|| config.transform?.force === true;
const needsTransform = hasTransformConfig || (isSizeChange && sizeChangeBehavior !== 'passThrough');
if (needsTransform) {