@alpha2-sh/editor 0.4.2 → 0.4.4
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.
|
@@ -13,8 +13,9 @@ export function resolvedVideoRate({ codec, width, height, frameRate, quality, }:
|
|
|
13
13
|
}): import("alpha2/rate-control").VideoRateControl;
|
|
14
14
|
/**
|
|
15
15
|
* Which video codecs this browser encodes for an export at `width`x`height`, `frameRate`, and
|
|
16
|
-
* `videoQuality` (default `high`), asked with the
|
|
17
|
-
* with: a codec answered `false` is refused when
|
|
16
|
+
* `videoQuality` (default `high`), asked with the configurations that export would open its encoder
|
|
17
|
+
* with (for H.264, High, Main or Constrained Baseline): a codec answered `false` is refused when
|
|
18
|
+
* such an export starts.
|
|
18
19
|
*/
|
|
19
20
|
export function probeEncoders(width: any, height: any, { frameRate, videoQuality }?: {
|
|
20
21
|
frameRate?: {
|
|
@@ -65,6 +66,9 @@ export function exportTimeline({ supplyFrame, renderFrame, sourceTransfer, engin
|
|
|
65
66
|
};
|
|
66
67
|
appliedVideoRateControl: import("alpha2/mediabunny").AppliedVideoRateControl | null;
|
|
67
68
|
videoLatencyMode: import("alpha2/mediabunny").VideoEncoderLatencyMode | null;
|
|
69
|
+
videoCodecString: string | null;
|
|
70
|
+
videoCodecProfile: import("alpha2/mediabunny").AvcProfile | null;
|
|
71
|
+
videoEncoderFallbacks: readonly import("alpha2/mediabunny").VideoEncoderFallback[];
|
|
68
72
|
audioCodec: "aac" | "opus" | undefined;
|
|
69
73
|
audioRateControl: {
|
|
70
74
|
bitrate: number;
|
|
@@ -138,14 +142,16 @@ export function chooseAudioCodec(sampleRate: any, audioQuality: any, { container
|
|
|
138
142
|
sampleRate: number;
|
|
139
143
|
}>;
|
|
140
144
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
145
|
+
* How this browser encodes the export's video (`canEncodeVideoTrack` in `alpha2/mediabunny`: for
|
|
146
|
+
* H.264, the first of High, Main and Constrained Baseline it encodes). Refuses an export whose
|
|
147
|
+
* video codec this browser does not encode at the export's size and rate in any of them, before
|
|
148
|
+
* anything renders, as `INVALID_INPUT`: WebCodecs leaves the codecs to the browser, and a retry
|
|
149
|
+
* would meet the same browser.
|
|
144
150
|
*/
|
|
145
151
|
export function requireVideoEncoder(codec: any, { width, height }: {
|
|
146
152
|
width: any;
|
|
147
153
|
height: any;
|
|
148
|
-
}, rate: any): Promise<
|
|
154
|
+
}, rate: any): Promise<import("alpha2/mediabunny").VideoTrackEncoding>;
|
|
149
155
|
/** The video codecs a browser export may request, with display labels. */
|
|
150
156
|
export const VIDEO_CODECS: {
|
|
151
157
|
value: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Deterministic export: the engine renders offscreen at export quality on its own exact rational
|
|
2
2
|
// frame schedule, so no swapchain race can duplicate a frame and a missing source retries in place.
|
|
3
3
|
import { ExportFormatError, offeredAudioCodecs, resolveExportFormat, } from "alpha2/containers";
|
|
4
|
-
import { audioEncoderSampleRate, canEncodeVideoTrack, MediabunnySink, } from "alpha2/mediabunny";
|
|
4
|
+
import { audioEncoderSampleRate, canEncodeVideoTrack, MediabunnySink, videoEncoderProfiles, } from "alpha2/mediabunny";
|
|
5
5
|
import { engineVideoCodec, qualityLevels, resolveAudioBitrate, resolveVideoRateControl, } from "alpha2/rate-control";
|
|
6
6
|
import { videoFrameFromI420, videoFrameRepackedBytes, } from "alpha2/video-frames";
|
|
7
7
|
import * as engineBinding from "alpha2/wasm";
|
|
@@ -44,23 +44,25 @@ export function resolvedVideoRate({ codec, width, height, frameRate, quality, })
|
|
|
44
44
|
export { engineVideoCodec };
|
|
45
45
|
/**
|
|
46
46
|
* Which video codecs this browser encodes for an export at `width`x`height`, `frameRate`, and
|
|
47
|
-
* `videoQuality` (default `high`), asked with the
|
|
48
|
-
* with: a codec answered `false` is refused when
|
|
47
|
+
* `videoQuality` (default `high`), asked with the configurations that export would open its encoder
|
|
48
|
+
* with (for H.264, High, Main or Constrained Baseline): a codec answered `false` is refused when
|
|
49
|
+
* such an export starts.
|
|
49
50
|
*/
|
|
50
51
|
export async function probeEncoders(width, height, { frameRate = { num: 30, den: 1 }, videoQuality = "high" } = {}) {
|
|
51
52
|
const results = {};
|
|
52
53
|
for (const codec of VIDEO_CODECS)
|
|
53
|
-
results[codec.value] =
|
|
54
|
-
|
|
55
|
-
height,
|
|
56
|
-
rate: resolvedVideoRate({
|
|
57
|
-
codec: engineVideoCodec(codec.value),
|
|
54
|
+
results[codec.value] =
|
|
55
|
+
(await canEncodeVideoTrack(codec.value, {
|
|
58
56
|
width,
|
|
59
57
|
height,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
rate: resolvedVideoRate({
|
|
59
|
+
codec: engineVideoCodec(codec.value),
|
|
60
|
+
width,
|
|
61
|
+
height,
|
|
62
|
+
frameRate,
|
|
63
|
+
quality: videoQuality,
|
|
64
|
+
}),
|
|
65
|
+
})) !== null;
|
|
64
66
|
return results;
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
@@ -107,7 +109,7 @@ export async function exportTimeline({ supplyFrame, renderFrame, sourceTransfer,
|
|
|
107
109
|
frameRate: rate,
|
|
108
110
|
quality: videoQuality,
|
|
109
111
|
});
|
|
110
|
-
await requireVideoEncoder(videoCodec, settings, videoRateControl);
|
|
112
|
+
const videoEncoding = await requireVideoEncoder(videoCodec, settings, videoRateControl);
|
|
111
113
|
const audioBitrate = audioCodec === undefined
|
|
112
114
|
? undefined
|
|
113
115
|
: resolveAudioBitrate(engineBinding, audioCodec, audioQuality);
|
|
@@ -129,6 +131,9 @@ export async function exportTimeline({ supplyFrame, renderFrame, sourceTransfer,
|
|
|
129
131
|
videoCodec,
|
|
130
132
|
audioCodec,
|
|
131
133
|
videoRateControl,
|
|
134
|
+
...(videoEncoding.codecString === undefined
|
|
135
|
+
? {}
|
|
136
|
+
: { videoCodecString: videoEncoding.codecString }),
|
|
132
137
|
audioBitrate,
|
|
133
138
|
audioSampleRate: audioEncoding?.sampleRate,
|
|
134
139
|
audioResampler: engineBinding,
|
|
@@ -405,6 +410,11 @@ export async function exportTimeline({ supplyFrame, renderFrame, sourceTransfer,
|
|
|
405
410
|
// `quantizer` when the encoder accepted constant-quantizer encoding, else the bitrate path.
|
|
406
411
|
appliedVideoRateControl: sink.appliedVideoRateControl ?? null,
|
|
407
412
|
videoLatencyMode: sink.videoLatencyMode ?? null,
|
|
413
|
+
// The codec string the encoder opened (for H.264, its profile and level), and the H.264
|
|
414
|
+
// profiles this browser refused before it: a lower profile of the same codec, not a switch.
|
|
415
|
+
videoCodecString: sink.videoCodecString ?? videoEncoding.codecString ?? null,
|
|
416
|
+
videoCodecProfile: videoEncoding.profile ?? null,
|
|
417
|
+
videoEncoderFallbacks: videoEncoding.fallbacks,
|
|
408
418
|
audioCodec,
|
|
409
419
|
audioRateControl: audioBitrate === undefined
|
|
410
420
|
? null
|
|
@@ -782,17 +792,24 @@ export async function chooseAudioCodec(sampleRate, audioQuality, { container = "
|
|
|
782
792
|
});
|
|
783
793
|
}
|
|
784
794
|
/**
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
*
|
|
795
|
+
* How this browser encodes the export's video (`canEncodeVideoTrack` in `alpha2/mediabunny`: for
|
|
796
|
+
* H.264, the first of High, Main and Constrained Baseline it encodes). Refuses an export whose
|
|
797
|
+
* video codec this browser does not encode at the export's size and rate in any of them, before
|
|
798
|
+
* anything renders, as `INVALID_INPUT`: WebCodecs leaves the codecs to the browser, and a retry
|
|
799
|
+
* would meet the same browser.
|
|
788
800
|
*/
|
|
789
801
|
export async function requireVideoEncoder(codec, { width, height }, rate) {
|
|
790
|
-
|
|
791
|
-
|
|
802
|
+
const encoding = await canEncodeVideoTrack(codec, { width, height, rate });
|
|
803
|
+
if (encoding !== null)
|
|
804
|
+
return encoding;
|
|
792
805
|
const label = VIDEO_CODECS.find((c) => c.value === codec)?.label ?? String(codec);
|
|
806
|
+
const profiles = videoEncoderProfiles(codec, { width, height, rate });
|
|
807
|
+
const tried = profiles.length === 0
|
|
808
|
+
? ""
|
|
809
|
+
: ` in any profile (tried ${profiles.map((p) => `${p.profile} ${p.codecString}`).join(", ")})`;
|
|
793
810
|
throw new ExportFailureError({
|
|
794
811
|
code: "INVALID_INPUT",
|
|
795
|
-
message: `This browser cannot encode ${label} video at ${width}x${height}. Choose another video codec, or use the native exporter.`,
|
|
812
|
+
message: `This browser cannot encode ${label} video at ${width}x${height}${tried}. Choose another video codec, or use the native exporter.`,
|
|
796
813
|
origin: "browser",
|
|
797
814
|
operation: "export",
|
|
798
815
|
backend: "unknown",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpha2-sh/editor",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Headless Project-based editing sessions and browser adapters for alpha2.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
"build": "rm -rf dist && tsc -p tsconfig.json"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"alpha2": "0.4.
|
|
63
|
+
"alpha2": "0.4.4",
|
|
64
64
|
"react": "^19.3.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"alpha2": "0.4.
|
|
67
|
+
"alpha2": "0.4.4",
|
|
68
68
|
"react": "19.3.0",
|
|
69
69
|
"react-dom": "19.3.0",
|
|
70
70
|
"@types/react": "19.3.0",
|