Conversion.init(hardwareAcceleration) option (#254)

* Support Conversion.init(hardwareAcceleration) option passed down to the VideoEncodingConfig.

fix #253

* Few changes

---------

Co-authored-by: Raphaël Droz <[email protected]>
Co-authored-by: Vanilagy <[email protected]>
This commit is contained in:
Raphaël Droz
2025-12-17 10:28:29 +00:00
committed by GitHub
co-authored by Raphaël Droz Vanilagy
parent 228721d68f
commit 4dd747a0a6
2 changed files with 19 additions and 2 deletions
+15
View File
@@ -186,6 +186,11 @@ export type ConversionVideoOptions = {
* Setting this fields forces a transcode.
*/
keyFrameInterval?: number;
/**
* A hint that configures the hardware acceleration method used when transcoding. This is best left on
* `'no-preference'`, the default.
*/
hardwareAcceleration?: 'no-preference' | 'prefer-hardware' | 'prefer-software';
/** When `true`, video will always be re-encoded instead of directly copying over the encoded samples. */
forceTranscode?: boolean;
/**
@@ -346,6 +351,15 @@ const validateVideoOptions = (videoOptions: ConversionVideoOptions | undefined)
) {
throw new TypeError('options.video.processedHeight, when provided, must be a positive integer.');
}
if (
videoOptions?.hardwareAcceleration !== undefined
&& !['no-preference', 'prefer-hardware', 'prefer-software'].includes(videoOptions.hardwareAcceleration)
) {
throw new TypeError(
'options.video.hardwareAcceleration, when provided, must be \'no-preference\', \'prefer-hardware\' or'
+ ' \'prefer-software\'.',
);
}
};
const validateAudioOptions = (audioOptions: ConversionAudioOptions | undefined) => {
@@ -984,6 +998,7 @@ export class Conversion {
keyFrameInterval: trackOptions.keyFrameInterval,
sizeChangeBehavior: trackOptions.fit ?? 'passThrough',
alpha,
hardwareAcceleration: trackOptions.hardwareAcceleration,
};
const source = new VideoSampleSource(encodingConfig);