supervision 0.1.0 → 0.1.1
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/README.md +3 -4
- package/dist/index.js +19 -12
- package/dist/index.js.map +1 -1
- package/dist/media/media-normalization.d.ts.map +1 -1
- package/dist/media/media-probe.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -8,12 +8,11 @@ styling, interaction, and editing for images, video, and browser media streams.
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
|
-
npm install supervision
|
|
11
|
+
npm install supervision
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
The
|
|
15
|
-
|
|
16
|
-
its internal core dependency. Consumers import the public browser entrypoints:
|
|
14
|
+
The package includes its internal core dependency. Consumers import the public
|
|
15
|
+
browser entrypoints:
|
|
17
16
|
|
|
18
17
|
```ts
|
|
19
18
|
import { createMediaSession } from "supervision";
|
package/dist/index.js
CHANGED
|
@@ -624,7 +624,7 @@ const DEFAULT_MEDIA_PROBE_TARGETS = [
|
|
|
624
624
|
},
|
|
625
625
|
];
|
|
626
626
|
async function probeMedia(source, options = {}) {
|
|
627
|
-
const { ALL_FORMATS, BlobSource, Input, canEncodeVideo } = await import('mediabunny');
|
|
627
|
+
const { ALL_FORMATS, BlobSource, Input, Quality, canEncodeVideo } = await import('mediabunny');
|
|
628
628
|
const input = new Input({
|
|
629
629
|
formats: ALL_FORMATS,
|
|
630
630
|
source: new BlobSource(source),
|
|
@@ -681,6 +681,7 @@ async function probeMedia(source, options = {}) {
|
|
|
681
681
|
const target = await selectMediaProbeTarget({
|
|
682
682
|
canEncodeVideo,
|
|
683
683
|
primaryVideo,
|
|
684
|
+
Quality,
|
|
684
685
|
targets: options.targets ?? DEFAULT_MEDIA_PROBE_TARGETS,
|
|
685
686
|
});
|
|
686
687
|
if (!target) {
|
|
@@ -719,8 +720,10 @@ async function selectMediaProbeTarget(options) {
|
|
|
719
720
|
for (const target of options.targets) {
|
|
720
721
|
const canEncode = await options.canEncodeVideo(target.videoCodec, {
|
|
721
722
|
...includeDefined({
|
|
722
|
-
bitrate: target.bitrate,
|
|
723
723
|
height: target.height ?? options.primaryVideo.height,
|
|
724
|
+
quality: target.bitrate === undefined
|
|
725
|
+
? undefined
|
|
726
|
+
: new options.Quality({ bitrate: target.bitrate }),
|
|
724
727
|
width: target.width ?? options.primaryVideo.width,
|
|
725
728
|
}),
|
|
726
729
|
});
|
|
@@ -751,7 +754,7 @@ const DEFAULT_KEY_FRAME_INTERVAL = 1;
|
|
|
751
754
|
const MEDIA_NORMALIZATION_ABORT_MESSAGE = "Media normalization was aborted.";
|
|
752
755
|
async function normalizeMedia(source, options = {}) {
|
|
753
756
|
throwIfAborted(options.signal);
|
|
754
|
-
const { ALL_FORMATS, BlobSource, BufferTarget, Conversion, Input, Mp4OutputFormat, Output, WebMOutputFormat, } = await import('mediabunny');
|
|
757
|
+
const { ALL_FORMATS, BlobSource, BufferTarget, Conversion, Input, Mp4OutputFormat, Output, Quality, WebMOutputFormat, } = await import('mediabunny');
|
|
755
758
|
const container = options.container ?? MediaNormalizationContainer.WebM;
|
|
756
759
|
const target = new BufferTarget();
|
|
757
760
|
const output = new Output({
|
|
@@ -770,12 +773,12 @@ async function normalizeMedia(source, options = {}) {
|
|
|
770
773
|
const inputMetadata = await collectInputMetadata(input, source);
|
|
771
774
|
throwIfAborted(options.signal);
|
|
772
775
|
conversion = await Conversion.init({
|
|
773
|
-
audio: buildAudioOptions(options.audio),
|
|
776
|
+
audio: buildAudioOptions(Quality, options.audio),
|
|
774
777
|
input,
|
|
775
778
|
output,
|
|
776
779
|
showWarnings: false,
|
|
777
780
|
tracks: "primary",
|
|
778
|
-
video: buildVideoOptions(container, options.video),
|
|
781
|
+
video: buildVideoOptions(Quality, container, options.video),
|
|
779
782
|
});
|
|
780
783
|
if (options.signal) {
|
|
781
784
|
abortConversion = () => {
|
|
@@ -825,7 +828,7 @@ async function normalizeMedia(source, options = {}) {
|
|
|
825
828
|
}
|
|
826
829
|
async function normalizeMediaProgressively(source, options = {}) {
|
|
827
830
|
throwIfAborted(options.signal);
|
|
828
|
-
const { ALL_FORMATS, AppendOnlyStreamTarget, BlobSource, Conversion, Input, Output, ReadableStreamSource, WEBM, WebMOutputFormat, } = await import('mediabunny');
|
|
831
|
+
const { ALL_FORMATS, AppendOnlyStreamTarget, BlobSource, Conversion, Input, Output, Quality, ReadableStreamSource, WEBM, WebMOutputFormat, } = await import('mediabunny');
|
|
829
832
|
const container = options.container ?? MediaNormalizationContainer.WebM;
|
|
830
833
|
if (container !== MediaNormalizationContainer.WebM) {
|
|
831
834
|
throw new Error("Progressive media normalization currently requires WebM.");
|
|
@@ -864,12 +867,12 @@ async function normalizeMediaProgressively(source, options = {}) {
|
|
|
864
867
|
target,
|
|
865
868
|
});
|
|
866
869
|
conversion = await Conversion.init({
|
|
867
|
-
audio: buildAudioOptions(options.audio),
|
|
870
|
+
audio: buildAudioOptions(Quality, options.audio),
|
|
868
871
|
input,
|
|
869
872
|
output,
|
|
870
873
|
showWarnings: false,
|
|
871
874
|
tracks: "primary",
|
|
872
|
-
video: buildVideoOptions(container, options.video),
|
|
875
|
+
video: buildVideoOptions(Quality, container, options.video),
|
|
873
876
|
});
|
|
874
877
|
if (!conversion.isValid) {
|
|
875
878
|
throw new Error(`Mediabunny conversion is invalid: ${formatDiscardedTracks(conversion.discardedTracks)}.`);
|
|
@@ -985,12 +988,14 @@ function isConversionAbortError(error, signal) {
|
|
|
985
988
|
return (signal?.aborted === true ||
|
|
986
989
|
(error instanceof Error && error.name === "ConversionCanceledError"));
|
|
987
990
|
}
|
|
988
|
-
function buildVideoOptions(container, options = {}) {
|
|
991
|
+
function buildVideoOptions(Quality, container, options = {}) {
|
|
989
992
|
return {
|
|
990
993
|
...includeDefined({
|
|
991
|
-
bitrate: options.bitrate,
|
|
992
994
|
fit: options.fit,
|
|
993
995
|
height: options.height,
|
|
996
|
+
quality: options.bitrate === undefined
|
|
997
|
+
? undefined
|
|
998
|
+
: new Quality({ bitrate: options.bitrate }),
|
|
994
999
|
width: options.width,
|
|
995
1000
|
}),
|
|
996
1001
|
codec: (options.codec ??
|
|
@@ -1002,12 +1007,14 @@ function buildVideoOptions(container, options = {}) {
|
|
|
1002
1007
|
keyFrameInterval: options.keyFrameInterval ?? DEFAULT_KEY_FRAME_INTERVAL,
|
|
1003
1008
|
};
|
|
1004
1009
|
}
|
|
1005
|
-
function buildAudioOptions(options = {}) {
|
|
1010
|
+
function buildAudioOptions(Quality, options = {}) {
|
|
1006
1011
|
return {
|
|
1007
1012
|
...includeDefined({
|
|
1008
|
-
bitrate: options.bitrate,
|
|
1009
1013
|
codec: options.codec,
|
|
1010
1014
|
numberOfChannels: options.numberOfChannels,
|
|
1015
|
+
quality: options.bitrate === undefined
|
|
1016
|
+
? undefined
|
|
1017
|
+
: new Quality({ bitrate: options.bitrate }),
|
|
1011
1018
|
sampleRate: options.sampleRate,
|
|
1012
1019
|
}),
|
|
1013
1020
|
discard: options.discard ?? true,
|