@margoengine/headless 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +768 -3
- package/dist/accumulate.d.ts +123 -0
- package/dist/accumulate.js +198 -0
- package/dist/avc-range.d.ts +15 -0
- package/dist/compare.d.ts +97 -0
- package/dist/compare.js +320 -0
- package/dist/crc32-Cc3b8qnn.js +23 -0
- package/dist/errors-CDgOgzCd.js +7 -0
- package/dist/ffmpeg-colour-Cg00HQ4H.js +15 -0
- package/dist/ffmpeg-colour.d.ts +4 -0
- package/dist/ffmpeg-files.d.ts +129 -0
- package/dist/ffmpeg-files.js +406 -0
- package/dist/ffmpeg.d.ts +159 -0
- package/dist/ffmpeg.js +372 -0
- package/dist/formats.d.ts +46 -0
- package/dist/formats.js +685 -0
- package/dist/frames.d.ts +33 -0
- package/dist/frames.js +70 -0
- package/dist/gif.d.ts +20 -0
- package/dist/gif.js +7 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +1 -0
- package/dist/look.d.ts +553 -0
- package/dist/look.js +1277 -0
- package/dist/null.d.ts +39 -0
- package/dist/null.js +61 -0
- package/dist/readback-HJLttuJt.js +122 -0
- package/dist/readback.d.ts +55 -0
- package/dist/src-VufTH2fo.js +154 -0
- package/dist/stage.d.ts +52 -0
- package/dist/stage.js +106 -0
- package/dist/tiles.d.ts +38 -0
- package/dist/tiles.js +79 -0
- package/dist/video-mux.d.ts +77 -0
- package/dist/video.d.ts +176 -0
- package/dist/video.js +1114 -0
- package/package.json +122 -6
package/dist/tiles.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const r=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { i as e } from "./src-VufTH2fo.js";
|
|
5
|
+
import { n as t, t as n } from "./errors-CDgOgzCd.js";
|
|
6
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
7
|
+
import { Camera as i } from "@margoengine/core";
|
|
8
|
+
//#region src/tiles.ts
|
|
9
|
+
var a = /* @__PURE__ */ new WeakSet(), o = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4, s = (e) => 255 * (e <= .0031308 ? e * 12.92 : 1.055 * e ** (1 / 2.4) - .055);
|
|
10
|
+
function c(e, t) {
|
|
11
|
+
let n = 0;
|
|
12
|
+
for (let r = 1 / t; e; e = Math.floor(e / t), r /= t) n += e % t * r;
|
|
13
|
+
return n;
|
|
14
|
+
}
|
|
15
|
+
async function* l(l, u) {
|
|
16
|
+
let { width: d, height: f, samples: p = 1, padding: m = 0, signal: h } = u;
|
|
17
|
+
h?.throwIfAborted();
|
|
18
|
+
let g = r(l), _ = g.gpu;
|
|
19
|
+
if (!_) throw n("unsupported", "Tiled headless capture requires WebGPU", "headless");
|
|
20
|
+
let v = _.limits.maxTextureDimension2D, y = u.tileSize ?? Math.min(1024, v);
|
|
21
|
+
if (![d, f].every((e) => Number.isSafeInteger(e) && e > 0)) throw t("Tiled width and height must be positive safe integers", "headless");
|
|
22
|
+
if (!Number.isInteger(p) || p < 1 || p > 1024) throw t("Tiled samples must be in 1..1024", "headless");
|
|
23
|
+
if (!Number.isInteger(y) || y < 1 || y > v || !Number.isInteger(m) || m < 0 || m * 2 >= y) throw t("Tile size must fit the device and leave space after padding", "headless");
|
|
24
|
+
if (a.has(g)) throw n("state", "A tiled capture is already active on this engine", "headless");
|
|
25
|
+
let b = g.canvas, x = [b.width, b.height], S = u.camera ?? g.camera, C = new i(S), w = y - 2 * m;
|
|
26
|
+
C.up = S.up, C.project = S.project, a.add(g);
|
|
27
|
+
try {
|
|
28
|
+
for (let t = 0; t < f; t += w) for (let n = 0; n < d; n += w) {
|
|
29
|
+
let r = Math.min(w, d - n), a = Math.min(w, f - t), u = r + m * 2, _ = a + m * 2, v = new Float64Array(r * a * 4);
|
|
30
|
+
for (let s = 0; s < p; s++) {
|
|
31
|
+
h?.throwIfAborted();
|
|
32
|
+
let y = p === 1 ? 0 : c(s + 1, 2) - .5, x = p === 1 ? 0 : c(s + 1, 3) - .5;
|
|
33
|
+
C.update = (e, r) => {
|
|
34
|
+
i.prototype.update.call(C, d / f, r);
|
|
35
|
+
for (let e = 0; e < 16; e += 4) C.matrix[e] = (C.matrix[e] * d + (d - 2 * (n - m) - u - 2 * y) * C.matrix[e + 3]) / u, C.matrix[e + 1] = (C.matrix[e + 1] * f + (2 * (t - m) + _ - f + 2 * x) * C.matrix[e + 3]) / _;
|
|
36
|
+
}, b.width = u, b.height = _, g.render({
|
|
37
|
+
camera: C,
|
|
38
|
+
delta: 0,
|
|
39
|
+
culling: !1
|
|
40
|
+
});
|
|
41
|
+
let S = await e(l, { signal: h });
|
|
42
|
+
for (let e = 0; e < a; e++) for (let t = 0; t < r; t++) {
|
|
43
|
+
let n = ((e + m) * u + t + m) * 4, i = (e * r + t) * 4, a = S.data[n + 3] / 255;
|
|
44
|
+
for (let e = 0; e < 3; e++) v[i + e] += o(S.data[n + e] / 255) * a;
|
|
45
|
+
v[i + 3] += a;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
let y = new Uint8Array(r * a * 4);
|
|
49
|
+
for (let e = 0; e < y.length; e += 4) {
|
|
50
|
+
let t = v[e + 3];
|
|
51
|
+
for (let n = 0; n < 3; n++) y[e + n] = t ? Math.round(s(v[e + n] / t)) : 0;
|
|
52
|
+
y[e + 3] = Math.round(255 * t / p);
|
|
53
|
+
}
|
|
54
|
+
[b.width, b.height] = x, yield {
|
|
55
|
+
x: n,
|
|
56
|
+
y: t,
|
|
57
|
+
width: r,
|
|
58
|
+
height: a,
|
|
59
|
+
data: y
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
} finally {
|
|
63
|
+
[b.width, b.height] = x, a.delete(g);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function u(e, t) {
|
|
67
|
+
let n;
|
|
68
|
+
for await (let r of l(e, t)) {
|
|
69
|
+
n ??= new Uint8Array(t.width * t.height * 4);
|
|
70
|
+
for (let e = 0; e < r.height; e++) n.set(r.data.subarray(e * r.width * 4, (e + 1) * r.width * 4), ((r.y + e) * t.width + r.x) * 4);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
width: t.width,
|
|
74
|
+
height: t.height,
|
|
75
|
+
data: n
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { u as renderTiled, l as renderTiles };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** One encoded frame in decode order. Times are microseconds. */
|
|
2
|
+
export interface VideoSample {
|
|
3
|
+
data: Uint8Array;
|
|
4
|
+
timestamp: number;
|
|
5
|
+
duration: number;
|
|
6
|
+
key: boolean;
|
|
7
|
+
/** The alpha plane coded as a frame of the same codec, which WebM carries beside the colour (BlockAddID 1). */
|
|
8
|
+
alpha?: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
/** What a container records about the stream. */
|
|
11
|
+
export interface VideoTrack {
|
|
12
|
+
/** JSON provenance carried by the containing file. Default none. */
|
|
13
|
+
provenance?: Readonly<Record<string, unknown>>;
|
|
14
|
+
codec: string;
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
fps: number;
|
|
18
|
+
/** The encoder's codec configuration, when it gives one. */
|
|
19
|
+
description?: Uint8Array;
|
|
20
|
+
colorSpace?: VideoColorSpaceInit;
|
|
21
|
+
/** Frames have their own times, not 1 / fps apart: WebM then states no DefaultDuration. Default false. */
|
|
22
|
+
variable?: boolean;
|
|
23
|
+
/** Frames carry `alpha` (WebM with VP8 or VP9 only). Default false. */
|
|
24
|
+
alpha?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** An encoded sound stream beside the video. Sample times are microseconds. */
|
|
27
|
+
export interface SoundTrack {
|
|
28
|
+
/** `'opus'`, or `'aac'` in MP4 only. */
|
|
29
|
+
codec: 'opus' | 'aac';
|
|
30
|
+
sampleRate: number;
|
|
31
|
+
channels: number;
|
|
32
|
+
/** The encoder's configuration: `OpusHead` for Opus when it gives one, the AudioSpecificConfig for AAC. */
|
|
33
|
+
description?: Uint8Array;
|
|
34
|
+
samples: readonly VideoSample[];
|
|
35
|
+
/** Samples the encoder put before the sound, which an MP4 edit list cuts. AAC only: Opus states its own pre-skip. */
|
|
36
|
+
leadIn?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* An AV1 temporal unit without its temporal delimiter and padding OBUs, which the AV1 ISOBMFF binding (2.4) and the
|
|
40
|
+
* Matroska AV1 mapping both say SHOULD NOT be stored: a WebCodecs chunk may start with a delimiter (WebCodecs AV1
|
|
41
|
+
* registration, section 2). OBU headers per AV1 5.3.1 to 5.3.3; sizes are leb128 (4.10.5). A unit that cannot be walked
|
|
42
|
+
* is kept as it is.
|
|
43
|
+
*/
|
|
44
|
+
export declare function av1StoredUnit(data: Uint8Array): Uint8Array;
|
|
45
|
+
/** A WebM file: header, one cluster per key frame, then cues for seeking. Timestamps are whole milliseconds. */
|
|
46
|
+
export declare function muxWebM(track: VideoTrack, frames: readonly VideoSample[], sound?: SoundTrack): Uint8Array;
|
|
47
|
+
/**
|
|
48
|
+
* Writes a WebM as frames arrive, as a live stream is written (RFC 9559 6.2, unknown sizes): the Segment's size is
|
|
49
|
+
* unknown, as the end is not known when the header goes out, and so the header states no duration and has no SeekHead.
|
|
50
|
+
* {@link add} takes each video sample in decode order and gives back the pieces now complete: the header first, then
|
|
51
|
+
* each cluster once the next key frame shows where it ends. Each cluster is whole when written, so its size is known.
|
|
52
|
+
* {@link finish} gives the last clusters and the Cues, which a reader that walks the file finds at its end. The joined
|
|
53
|
+
* pieces are one file; the header and clusters are what Media Source Extensions take.
|
|
54
|
+
*/
|
|
55
|
+
export declare class StreamedWebM {
|
|
56
|
+
#private;
|
|
57
|
+
constructor(track: VideoTrack, sound?: SoundTrack);
|
|
58
|
+
/** Takes the next video sample in decode order; returns the header and any clusters it completes. */
|
|
59
|
+
add(frame: VideoSample): Uint8Array[];
|
|
60
|
+
/** The last clusters, with the sound after the last frame, and the Cues. */
|
|
61
|
+
finish(): Uint8Array[];
|
|
62
|
+
}
|
|
63
|
+
/** A progressive MP4: `moov` first so playback can start before the end arrives, each track's samples in one chunk. */
|
|
64
|
+
export declare function muxMP4(video: VideoTrack, frames: readonly VideoSample[], sound?: SoundTrack): Uint8Array;
|
|
65
|
+
/**
|
|
66
|
+
* Writes a fragmented MP4 as samples arrive: {@link add} takes each video sample in decode order and gives back the
|
|
67
|
+
* pieces now complete, {@link finish} the rest. The sound, given whole, is cut into each fragment beside its frames.
|
|
68
|
+
* The joined pieces are one file.
|
|
69
|
+
*/
|
|
70
|
+
export declare class FragmentedMP4 {
|
|
71
|
+
#private;
|
|
72
|
+
constructor(track: VideoTrack, sound?: SoundTrack);
|
|
73
|
+
/** Takes the next video sample in decode order; returns the header and any fragment it completes. */
|
|
74
|
+
add(sample: VideoSample): Uint8Array[];
|
|
75
|
+
/** The last fragment and the random access index. */
|
|
76
|
+
finish(): Uint8Array[];
|
|
77
|
+
}
|
package/dist/video.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { Camera, Engine } from '@margoengine/core';
|
|
2
|
+
import { type HeadlessPixels } from './index.js';
|
|
3
|
+
import type { AccumulateTarget, SubFrameOptions, SubFrameTiming } from '@margoengine/headless/accumulate';
|
|
4
|
+
/** Where a frame sits in a sequence. */
|
|
5
|
+
export interface FrameTiming {
|
|
6
|
+
/** From 0. */
|
|
7
|
+
index: number;
|
|
8
|
+
/** Seconds since the first frame. */
|
|
9
|
+
time: number;
|
|
10
|
+
/** Seconds since the frame before: 0 on the first frame, then `1 / fps`. */
|
|
11
|
+
delta: number;
|
|
12
|
+
/** `index / frames`: from 0 up to but never 1, so a full turn at `progress * 2 * Math.PI` loops with no repeat. */
|
|
13
|
+
progress: number;
|
|
14
|
+
}
|
|
15
|
+
/** A frame from {@link renderFrames}: RGBA pixels and where it sits. */
|
|
16
|
+
export interface RenderedFrame extends HeadlessPixels, FrameTiming {
|
|
17
|
+
}
|
|
18
|
+
/** Options of {@link renderFrames}. */
|
|
19
|
+
export interface RenderFramesOptions extends Pick<SubFrameOptions, 'shutterPhase' | 'filter' | 'filterWidth' | 'seed' | 'pattern' | 'startFrame'> {
|
|
20
|
+
/** How many frames, a whole number from 1. Required. */
|
|
21
|
+
frames: number;
|
|
22
|
+
/** Frames per second. Default 30. */
|
|
23
|
+
fps?: number;
|
|
24
|
+
/** Camera to render through. Default the engine's camera. */
|
|
25
|
+
camera?: Camera;
|
|
26
|
+
/** Runs before each frame is drawn; move the scene here. May be async. With `samples` or `shutter` it runs before
|
|
27
|
+
* every render of a frame, with that render's time (a {@link SubFrameTiming}). Default none. */
|
|
28
|
+
update?: (frame: FrameTiming | SubFrameTiming) => unknown;
|
|
29
|
+
/** Stops the sequence; the iterator rejects with the signal's reason. Default none. */
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
/** Renders per frame averaged in linear light, for anti-aliasing and motion blur (`renderAccumulated` from
|
|
32
|
+
* `@margoengine/headless/accumulate`, loaded on first use). Default 1: one render a frame, as before. */
|
|
33
|
+
samples?: number;
|
|
34
|
+
/** Share of the frame interval the shutter is open, 0 to 1, for motion blur. Default 0: no blur. */
|
|
35
|
+
shutter?: number;
|
|
36
|
+
/** The Accumulate stage in your PostStack, for `samples` or `shutter`. Default one attached alone. */
|
|
37
|
+
accumulate?: AccumulateTarget;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Renders a sequence one frame at a time on an engine on a headless canvas, reading each back. Time is the sequence's
|
|
41
|
+
* own, not the wall clock, so a slow machine gives the same frames as a fast one. The next frame is not drawn until
|
|
42
|
+
* the consumer asks for it, so one frame of pixels is alive at a time unless the consumer keeps them. With `samples`
|
|
43
|
+
* above 1 or `shutter` above 0 each frame is `samples` renders over the open shutter averaged in linear light
|
|
44
|
+
* (`renderAccumulated`; `startFrame`, `shutterPhase`, `filter`, `filterWidth`, `seed` and `pattern` apply then);
|
|
45
|
+
* otherwise each frame is one render, exactly as before.
|
|
46
|
+
*/
|
|
47
|
+
export declare function renderFrames(engine: Engine, options: RenderFramesOptions): AsyncGenerator<RenderedFrame, void, void>;
|
|
48
|
+
/** A file of an image sequence. */
|
|
49
|
+
export interface SequenceFile {
|
|
50
|
+
/** From 0. */
|
|
51
|
+
index: number;
|
|
52
|
+
/** For example `frame_0007.png`. */
|
|
53
|
+
name: string;
|
|
54
|
+
/** PNG file bytes. */
|
|
55
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
56
|
+
}
|
|
57
|
+
/** Options of {@link imageSequence}. */
|
|
58
|
+
export interface ImageSequenceOptions {
|
|
59
|
+
/** Start of each file name. Default `'frame_'`. */
|
|
60
|
+
prefix?: string;
|
|
61
|
+
/** Digits of the number in each file name, padded with zeros. Default 4. */
|
|
62
|
+
digits?: number;
|
|
63
|
+
}
|
|
64
|
+
/** Turns frames into numbered PNG files, one at a time. Writing them is the caller's, so it runs anywhere. */
|
|
65
|
+
export declare function imageSequence(frames: AsyncIterable<HeadlessPixels> | Iterable<HeadlessPixels>, { prefix, digits }?: ImageSequenceOptions): AsyncGenerator<SequenceFile, void, void>;
|
|
66
|
+
/** The part of WebCodecs {@link encodeVideo} uses. */
|
|
67
|
+
export interface WebCodecsBinding {
|
|
68
|
+
VideoEncoder: typeof VideoEncoder;
|
|
69
|
+
VideoFrame: typeof VideoFrame;
|
|
70
|
+
/** Needed only with the `audio` option. */
|
|
71
|
+
AudioEncoder?: typeof AudioEncoder;
|
|
72
|
+
/** Needed only with the `audio` option. */
|
|
73
|
+
AudioData?: typeof AudioData;
|
|
74
|
+
/**
|
|
75
|
+
* Lets an AAC track start on time: the encoder's lead-in is measured through it and cut by the file's edit list.
|
|
76
|
+
* Without it the sound plays late by that lead-in (2112 samples, 44 ms at 48 kHz, from Chromium's AAC on macOS).
|
|
77
|
+
*/
|
|
78
|
+
AudioDecoder?: typeof AudioDecoder;
|
|
79
|
+
}
|
|
80
|
+
/** Sound to put in the file with the frames. */
|
|
81
|
+
export interface VideoAudio {
|
|
82
|
+
/** Samples from -1 to 1, one array per channel, one or two channels of one length. */
|
|
83
|
+
channels: readonly Float32Array[];
|
|
84
|
+
/** Samples per second. */
|
|
85
|
+
sampleRate: number;
|
|
86
|
+
/** Bits per second. Default 128000. */
|
|
87
|
+
bitrate?: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A frame for {@link encodeVideo}: RGBA pixels, and optionally when it is shown. Give `timestamp` on every frame or on
|
|
91
|
+
* none: without it frame n shows at n / fps.
|
|
92
|
+
*/
|
|
93
|
+
export interface VideoInputFrame extends HeadlessPixels {
|
|
94
|
+
/** Seconds, counted from the first frame's `timestamp`; each frame's later than the one before. Default none. */
|
|
95
|
+
timestamp?: number;
|
|
96
|
+
/** Seconds the last timed frame is shown. Default the gap before it, or 1 / fps for a single frame. Other frames last
|
|
97
|
+
* until the next one. */
|
|
98
|
+
duration?: number;
|
|
99
|
+
}
|
|
100
|
+
/** Options of {@link encodeVideo}. */
|
|
101
|
+
export interface EncodeVideoOptions {
|
|
102
|
+
/** JSON provenance embedded in WebM tags or an MP4 user-data box. Default none. */
|
|
103
|
+
provenance?: Readonly<Record<string, unknown>>;
|
|
104
|
+
/** Maximum retained encoded video payload bytes. Default 512 MiB. Audio is separately owned. */
|
|
105
|
+
maxBytes?: number;
|
|
106
|
+
/** Container. Default `'webm'`. */
|
|
107
|
+
format?: 'webm' | 'mp4';
|
|
108
|
+
/** Frames per second. Default 30. */
|
|
109
|
+
fps?: number;
|
|
110
|
+
/** WebCodecs codec string. WebM takes `vp8`, `vp09.*` and `av01.*`; MP4 takes `avc1.*`, `hvc1.*`, `hev1.*`,
|
|
111
|
+
* `vp09.*` and `av01.*`.
|
|
112
|
+
* Default the first the runtime supports: VP9, VP8, AV1 for WebM; H.264, VP9, AV1 for MP4. */
|
|
113
|
+
codec?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Bits per second. Default `width * height * fps / 10`, about 6 Mbit/s at 1920 x 1080 and 30 fps, and at least
|
|
116
|
+
* 100,000, so a thumbnail keeps its colours.
|
|
117
|
+
*/
|
|
118
|
+
bitrate?: number;
|
|
119
|
+
/** Seconds between key frames, which is how finely a player can seek. Default 2. */
|
|
120
|
+
keyFrameInterval?: number;
|
|
121
|
+
/** Sound for the file: Opus in WebM, and AAC or else Opus in MP4. Default none. */
|
|
122
|
+
audio?: VideoAudio;
|
|
123
|
+
/** Keep the frames' alpha: a second encoder codes it, and WebM carries it beside each frame (VP9, else VP8; WebM
|
|
124
|
+
* only, as MP4 has no binding for it). Pixels are straight alpha, as `readPixels` gives them. Default false. */
|
|
125
|
+
alpha?: boolean;
|
|
126
|
+
/** Where `VideoEncoder` and `VideoFrame` come from. Default `globalThis`. */
|
|
127
|
+
webCodecs?: WebCodecsBinding;
|
|
128
|
+
/** Stops encoding; the promise rejects with the signal's reason. Default none. */
|
|
129
|
+
signal?: AbortSignal;
|
|
130
|
+
}
|
|
131
|
+
/** What {@link encodeVideo} gives back. */
|
|
132
|
+
export interface EncodedVideo {
|
|
133
|
+
/** The whole file. */
|
|
134
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
135
|
+
/** For example `video/webm; codecs="vp09.00.51.08"`, for a `Blob` or an HTTP header. */
|
|
136
|
+
mimeType: string;
|
|
137
|
+
/** The codec string used. */
|
|
138
|
+
codec: string;
|
|
139
|
+
width: number;
|
|
140
|
+
height: number;
|
|
141
|
+
frames: number;
|
|
142
|
+
/** Seconds. */
|
|
143
|
+
duration: number;
|
|
144
|
+
/** The sound codec used, when the file has sound. */
|
|
145
|
+
audioCodec?: 'opus' | 'aac';
|
|
146
|
+
/** True when the file carries alpha. */
|
|
147
|
+
alpha?: boolean;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Encodes frames to a WebM or MP4 file in memory with WebCodecs. Frames are all one size; alpha is dropped unless
|
|
151
|
+
* `alpha` keeps it (WebM, VP9 or VP8). Frames are asked for only as the encoder keeps up, so {@link renderFrames} can
|
|
152
|
+
* feed it directly. `audio` adds a sound track.
|
|
153
|
+
*/
|
|
154
|
+
export declare function encodeVideo(frames: AsyncIterable<VideoInputFrame> | Iterable<VideoInputFrame>, { format, fps, codec, bitrate, keyFrameInterval, audio, alpha, provenance, maxBytes, webCodecs, signal, }?: EncodeVideoOptions): Promise<EncodedVideo>;
|
|
155
|
+
/** Options of {@link streamVideo}: those of {@link encodeVideo} less `maxBytes`, as only one key frame interval is held. */
|
|
156
|
+
export interface StreamVideoOptions extends Omit<EncodeVideoOptions, 'format' | 'maxBytes'> {
|
|
157
|
+
/** Container: fragmented MP4, or WebM written as a live stream. Default `'mp4'`. */
|
|
158
|
+
format?: 'mp4' | 'webm';
|
|
159
|
+
}
|
|
160
|
+
/** What {@link streamVideo} returns when its iteration ends: {@link EncodedVideo} without the bytes, already given. */
|
|
161
|
+
export type StreamedVideo = Omit<EncodedVideo, 'bytes'>;
|
|
162
|
+
/**
|
|
163
|
+
* Encodes frames to a video file and yields it in pieces as it is made, so only one key frame interval of encoded video
|
|
164
|
+
* is held at a time and a long render needs no `maxBytes`. Write each piece as it comes, to a file, a socket or a
|
|
165
|
+
* `WritableStream` (`ReadableStream.from(streamVideo(...))`). The pieces joined are a whole file, and all but the last
|
|
166
|
+
* are what Media Source Extensions take.
|
|
167
|
+
*
|
|
168
|
+
* - `'mp4'` (the default): a fragmented MP4 (ISO/IEC 14496-12 8.8): the header (`ftyp` and `moov`) once the encoder has
|
|
169
|
+
* given its configuration, one `moof` and `mdat` per key frame interval, then an `mfra` index for seeking.
|
|
170
|
+
* - `'webm'`: a WebM written as a live stream (RFC 9559 6.2): the header, whose Segment has an unknown size and which so
|
|
171
|
+
* states no duration, one Cluster per key frame interval, then the Cues. `alpha` keeps the frames' alpha (VP9 or VP8),
|
|
172
|
+
* as {@link encodeVideo} does.
|
|
173
|
+
*
|
|
174
|
+
* The iteration's return value describes the file. Stopping the iteration (`break`, or `signal`) closes the encoder.
|
|
175
|
+
*/
|
|
176
|
+
export declare function streamVideo(frames: AsyncIterable<VideoInputFrame> | Iterable<VideoInputFrame>, given?: StreamVideoOptions): AsyncGenerator<Uint8Array<ArrayBuffer>, StreamedVideo, void>;
|