mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
add keyFrameInterval to ConversionVideoOptions
This commit is contained in:
@@ -124,6 +124,7 @@ type ConversionVideoOptions = {
|
|||||||
codec?: VideoCodec;
|
codec?: VideoCodec;
|
||||||
bitrate?: number | Quality;
|
bitrate?: number | Quality;
|
||||||
alpha?: 'discard' | 'keep'; // Defaults to 'discard'
|
alpha?: 'discard' | 'keep'; // Defaults to 'discard'
|
||||||
|
keyFrameInterval?: number;
|
||||||
forceTranscode?: boolean;
|
forceTranscode?: boolean;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@@ -180,7 +181,9 @@ Use the `codec` property to control the codec of the output track. This should b
|
|||||||
|
|
||||||
Use the `bitrate` property to control the bitrate of the output video. For example, you can use this field to compress the video track. Accepted values are the number of bits per second or a [subjective quality](./media-sources#subjective-qualities). If this property is set, transcoding will always happen. If this property is not set but transcoding is still required, `QUALITY_HIGH` will be used as the value.
|
Use the `bitrate` property to control the bitrate of the output video. For example, you can use this field to compress the video track. Accepted values are the number of bits per second or a [subjective quality](./media-sources#subjective-qualities). If this property is set, transcoding will always happen. If this property is not set but transcoding is still required, `QUALITY_HIGH` will be used as the value.
|
||||||
|
|
||||||
If you want to prevent direct copying of media data and force a transcoding step, use `forceTranscode: true`.
|
Use the `keyFrameInterval` property to control the interval in seconds between key frames in the output video.
|
||||||
|
|
||||||
|
If you want to prevent direct copying of media data and force a transcoding step, use `forceTranscode: true`. Setting `keyFrameInterval` or `frameRate` will automatically force transcoding, even if `forceTranscode` is not explicitly set to `true`.
|
||||||
|
|
||||||
## Audio options
|
## Audio options
|
||||||
|
|
||||||
|
|||||||
+14
-1
@@ -166,6 +166,11 @@ export type ConversionVideoOptions = {
|
|||||||
* VP9.
|
* VP9.
|
||||||
*/
|
*/
|
||||||
alpha?: 'discard' | 'keep';
|
alpha?: 'discard' | 'keep';
|
||||||
|
/**
|
||||||
|
* The desired interval in seconds between key frames in the output video.
|
||||||
|
* Setting this value will force transcoding (even if `forceTranscode` is not explicitly set to `true`).
|
||||||
|
*/
|
||||||
|
keyFrameInterval?: number;
|
||||||
/** When `true`, video will always be re-encoded instead of directly copying over the encoded samples. */
|
/** When `true`, video will always be re-encoded instead of directly copying over the encoded samples. */
|
||||||
forceTranscode?: boolean;
|
forceTranscode?: boolean;
|
||||||
};
|
};
|
||||||
@@ -252,6 +257,12 @@ const validateVideoOptions = (videoOptions: ConversionVideoOptions | undefined)
|
|||||||
if (videoOptions?.alpha !== undefined && !['discard', 'keep'].includes(videoOptions.alpha)) {
|
if (videoOptions?.alpha !== undefined && !['discard', 'keep'].includes(videoOptions.alpha)) {
|
||||||
throw new TypeError('options.video.alpha, when provided, must be either \'discard\' or \'keep\'.');
|
throw new TypeError('options.video.alpha, when provided, must be either \'discard\' or \'keep\'.');
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
videoOptions?.keyFrameInterval !== undefined
|
||||||
|
&& (!Number.isFinite(videoOptions.keyFrameInterval) || videoOptions.keyFrameInterval <= 0)
|
||||||
|
) {
|
||||||
|
throw new TypeError('options.video.keyFrameInterval, when provided, must be a finite positive number.');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateAudioOptions = (audioOptions: ConversionAudioOptions | undefined) => {
|
const validateAudioOptions = (audioOptions: ConversionAudioOptions | undefined) => {
|
||||||
@@ -775,7 +786,8 @@ export class Conversion {
|
|||||||
const needsTranscode = !!trackOptions.forceTranscode
|
const needsTranscode = !!trackOptions.forceTranscode
|
||||||
|| this._startTimestamp > 0
|
|| this._startTimestamp > 0
|
||||||
|| firstTimestamp < 0
|
|| firstTimestamp < 0
|
||||||
|| !!trackOptions.frameRate;
|
|| !!trackOptions.frameRate
|
||||||
|
|| trackOptions.keyFrameInterval !== undefined;
|
||||||
let needsRerender = width !== originalWidth
|
let needsRerender = width !== originalWidth
|
||||||
|| height !== originalHeight
|
|| height !== originalHeight
|
||||||
|| (totalRotation !== 0 && !outputSupportsRotation)
|
|| (totalRotation !== 0 && !outputSupportsRotation)
|
||||||
@@ -858,6 +870,7 @@ export class Conversion {
|
|||||||
const encodingConfig: VideoEncodingConfig = {
|
const encodingConfig: VideoEncodingConfig = {
|
||||||
codec: encodableCodec,
|
codec: encodableCodec,
|
||||||
bitrate,
|
bitrate,
|
||||||
|
keyFrameInterval: trackOptions.keyFrameInterval,
|
||||||
sizeChangeBehavior: trackOptions.fit ?? 'passThrough',
|
sizeChangeBehavior: trackOptions.fit ?? 'passThrough',
|
||||||
alpha,
|
alpha,
|
||||||
onEncodedPacket: sample => this._reportProgress(track.id, sample.timestamp + sample.duration),
|
onEncodedPacket: sample => this._reportProgress(track.id, sample.timestamp + sample.duration),
|
||||||
|
|||||||
Reference in New Issue
Block a user