mediabunny 1.45.5 → 1.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles/mediabunny.cjs +32 -9
- package/dist/bundles/mediabunny.min.cjs +2 -2
- package/dist/bundles/mediabunny.min.mjs +7 -7
- package/dist/bundles/mediabunny.mjs +32 -9
- package/dist/bundles/mediabunny.node.cjs +32 -9
- package/dist/mediabunny.d.ts +15 -0
- package/dist/modules/src/index.d.ts +1 -1
- package/dist/modules/src/index.d.ts.map +1 -1
- package/dist/modules/src/media-source.d.ts.map +1 -1
- package/dist/modules/src/media-source.js +9 -7
- package/dist/modules/src/misc.d.ts +8 -0
- package/dist/modules/src/misc.d.ts.map +1 -1
- package/dist/modules/src/sample.d.ts +7 -1
- package/dist/modules/src/sample.d.ts.map +1 -1
- package/dist/modules/src/sample.js +27 -4
- package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/media-source.ts +10 -7
- package/src/misc.ts +9 -0
- package/src/sample.ts +43 -4
|
@@ -19068,7 +19068,7 @@ var Mediabunny = (() => {
|
|
|
19068
19068
|
"init.displayWidth and init.displayHeight must be either both provided or both omitted."
|
|
19069
19069
|
);
|
|
19070
19070
|
}
|
|
19071
|
-
this._data = toUint8Array(data).slice();
|
|
19071
|
+
this._data = init._doNotCopy ? toUint8Array(data) : toUint8Array(data).slice();
|
|
19072
19072
|
this._layout = init.layout ?? createDefaultPlaneLayout(init.format, init.codedWidth, init.codedHeight);
|
|
19073
19073
|
this.format = init.format;
|
|
19074
19074
|
this.rotation = init.rotation ?? 0;
|
|
@@ -19178,7 +19178,11 @@ var Mediabunny = (() => {
|
|
|
19178
19178
|
// Firefox has VideoFrame glitches with opaque canvases
|
|
19179
19179
|
willReadFrequently: true
|
|
19180
19180
|
});
|
|
19181
|
-
|
|
19181
|
+
if (!context) {
|
|
19182
|
+
throw new Error(
|
|
19183
|
+
"OffscreenCanvas must have support for the '2d' context in order to create a VideoSample from this data."
|
|
19184
|
+
);
|
|
19185
|
+
}
|
|
19182
19186
|
context.drawImage(data, 0, 0);
|
|
19183
19187
|
this._data = canvas;
|
|
19184
19188
|
this._layout = null;
|
|
@@ -19243,6 +19247,7 @@ var Mediabunny = (() => {
|
|
|
19243
19247
|
"Invalid data type: Must be a BufferSource, CanvasImageSource, or VideoSampleResource."
|
|
19244
19248
|
);
|
|
19245
19249
|
}
|
|
19250
|
+
this.encodeOptions = init?.encodeOptions ?? {};
|
|
19246
19251
|
this.pixelAspectRatio = simplifyRational({
|
|
19247
19252
|
num: this.squarePixelWidth * this.codedHeight,
|
|
19248
19253
|
den: this.squarePixelHeight * this.codedWidth
|
|
@@ -19290,13 +19295,15 @@ var Mediabunny = (() => {
|
|
|
19290
19295
|
return new _VideoSample(this._data, {
|
|
19291
19296
|
timestamp: this.timestamp,
|
|
19292
19297
|
duration: this.duration,
|
|
19293
|
-
rotation: this.rotation
|
|
19298
|
+
rotation: this.rotation,
|
|
19299
|
+
encodeOptions: this.encodeOptions
|
|
19294
19300
|
});
|
|
19295
19301
|
} else if (isVideoFrame(this._data)) {
|
|
19296
19302
|
return new _VideoSample(this._data.clone(), {
|
|
19297
19303
|
timestamp: this.timestamp,
|
|
19298
19304
|
duration: this.duration,
|
|
19299
|
-
rotation: this.rotation
|
|
19305
|
+
rotation: this.rotation,
|
|
19306
|
+
encodeOptions: this.encodeOptions
|
|
19300
19307
|
});
|
|
19301
19308
|
} else if (this._data instanceof Uint8Array) {
|
|
19302
19309
|
assert(this._layout);
|
|
@@ -19311,7 +19318,10 @@ var Mediabunny = (() => {
|
|
|
19311
19318
|
rotation: this.rotation,
|
|
19312
19319
|
visibleRect: this.visibleRect,
|
|
19313
19320
|
displayWidth: this.displayWidth,
|
|
19314
|
-
displayHeight: this.displayHeight
|
|
19321
|
+
displayHeight: this.displayHeight,
|
|
19322
|
+
encodeOptions: this.encodeOptions,
|
|
19323
|
+
// It's already been copied, if we copy it again we make the clone unnecessarily expensive
|
|
19324
|
+
_doNotCopy: true
|
|
19315
19325
|
});
|
|
19316
19326
|
} else {
|
|
19317
19327
|
return new _VideoSample(this._data, {
|
|
@@ -19324,7 +19334,8 @@ var Mediabunny = (() => {
|
|
|
19324
19334
|
rotation: this.rotation,
|
|
19325
19335
|
visibleRect: this.visibleRect,
|
|
19326
19336
|
displayWidth: this.displayWidth,
|
|
19327
|
-
displayHeight: this.displayHeight
|
|
19337
|
+
displayHeight: this.displayHeight,
|
|
19338
|
+
encodeOptions: this.encodeOptions
|
|
19328
19339
|
});
|
|
19329
19340
|
}
|
|
19330
19341
|
}
|
|
@@ -19886,7 +19897,11 @@ var Mediabunny = (() => {
|
|
|
19886
19897
|
const context = canvas.getContext("2d", {
|
|
19887
19898
|
alpha: true
|
|
19888
19899
|
});
|
|
19889
|
-
|
|
19900
|
+
if (!context) {
|
|
19901
|
+
throw new Error(
|
|
19902
|
+
"The '2d' canvas context is required to transform VideoSamples. Register a custom transformer using registerVideoSampleTransformer to work around this limitation."
|
|
19903
|
+
);
|
|
19904
|
+
}
|
|
19890
19905
|
if (description.alpha === "discard") {
|
|
19891
19906
|
context.fillStyle = "black";
|
|
19892
19907
|
context.fillRect(0, 0, description.width, description.height);
|
|
@@ -19926,6 +19941,13 @@ var Mediabunny = (() => {
|
|
|
19926
19941
|
}
|
|
19927
19942
|
this.duration = newDuration;
|
|
19928
19943
|
}
|
|
19944
|
+
/** Sets the encode options used when this sample is passed to an encoder. */
|
|
19945
|
+
setEncodeOptions(newEncodeOptions) {
|
|
19946
|
+
if (!newEncodeOptions || typeof newEncodeOptions !== "object") {
|
|
19947
|
+
throw new TypeError("newEncodeOptions must be an object.");
|
|
19948
|
+
}
|
|
19949
|
+
this.encodeOptions = newEncodeOptions;
|
|
19950
|
+
}
|
|
19929
19951
|
/** Calls `.close()`. */
|
|
19930
19952
|
[Symbol.dispose]() {
|
|
19931
19953
|
this.close();
|
|
@@ -32430,9 +32452,10 @@ ${cue.notes ?? ""}`;
|
|
|
32430
32452
|
assert(this.encoderInitialized);
|
|
32431
32453
|
const keyFrameInterval = this.encodingConfig.keyFrameInterval ?? 2;
|
|
32432
32454
|
const multipleOfKeyFrameInterval = Math.floor(sampleToEncode.timestamp / keyFrameInterval);
|
|
32455
|
+
const mergedEncodeOptions = { ...sampleToEncode.encodeOptions, ...encodeOptions };
|
|
32433
32456
|
const finalEncodeOptions = {
|
|
32434
|
-
...
|
|
32435
|
-
keyFrame:
|
|
32457
|
+
...mergedEncodeOptions,
|
|
32458
|
+
keyFrame: mergedEncodeOptions.keyFrame !== void 0 ? mergedEncodeOptions.keyFrame : keyFrameInterval === 0 || multipleOfKeyFrameInterval !== this.lastMultipleOfKeyFrameInterval
|
|
32436
32459
|
};
|
|
32437
32460
|
this.lastMultipleOfKeyFrameInterval = multipleOfKeyFrameInterval;
|
|
32438
32461
|
if (this.customEncoder) {
|