@vestra-player/sdk 1.6.20 → 1.6.21
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/CHANGELOG.md +11 -0
- package/dist/docs-tree.json.gz +0 -0
- package/dist/i18n-tools.js +7 -2
- package/dist/plugin/types/base.d.ts +1097 -0
- package/dist/plugin/types/base.js +1 -0
- package/dist/plugin/types/commands.d.ts +1189 -0
- package/dist/plugin/types/commands.js +1 -0
- package/dist/plugin/types/packages.d.ts +661 -0
- package/dist/plugin/types/packages.js +1 -0
- package/dist/plugin/types/playback.d.ts +1654 -0
- package/dist/plugin/types/playback.js +1 -0
- package/dist/plugin/types/processing.d.ts +974 -0
- package/dist/plugin/types/processing.js +1 -0
- package/dist/plugin/types/services.d.ts +1132 -0
- package/dist/plugin/types/services.js +1 -0
- package/dist/plugin/types/snapshots.d.ts +491 -0
- package/dist/plugin/types/snapshots.js +1 -0
- package/dist/plugin/types/sources.d.ts +302 -0
- package/dist/plugin/types/sources.js +1 -0
- package/dist/plugin/types/subtitles.d.ts +327 -0
- package/dist/plugin/types/subtitles.js +1 -0
- package/dist/plugin/types/ui-content.d.ts +692 -0
- package/dist/plugin/types/ui-content.js +1 -0
- package/dist/plugin/types/ui-layout.d.ts +1079 -0
- package/dist/plugin/types/ui-layout.js +1 -0
- package/dist/plugin/types/ui-locale.d.ts +490 -0
- package/dist/plugin/types/ui-locale.js +1 -0
- package/dist/plugin/types/ui-shell.d.ts +1072 -0
- package/dist/plugin/types/ui-shell.js +1 -0
- package/dist/plugin/types.d.ts +18 -11072
- package/llms.txt +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import type { AppInfo } from "./base.ts";
|
|
2
|
+
import type { MediaJob } from "../../media.ts";
|
|
3
|
+
import type { Disposable } from "./base.ts";
|
|
4
|
+
import type { Conditional } from "./playback.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Options of {@link MediaCapture.capture}. Conditional on `player.state`
|
|
7
|
+
* like other controls.
|
|
8
|
+
*
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
* @category Media
|
|
11
|
+
*/
|
|
12
|
+
export interface CaptureOptions extends Conditional {
|
|
13
|
+
/** Source time; defaults to the current position at the moment of capture. */
|
|
14
|
+
at?: number;
|
|
15
|
+
/** Include this plugin set's effects (and subtitles unless `subtitles: false`). */
|
|
16
|
+
processed?: boolean;
|
|
17
|
+
/** With `processed`, include the primary subtitle (default true). */
|
|
18
|
+
subtitles?: boolean;
|
|
19
|
+
/** Audio to freeze with the snapshot: the selected track, none, or a track id. */
|
|
20
|
+
audio?: "selected" | "none" | number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A frozen, immutable input for exports. Dispose to release it.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* A frozen input, from {@link MediaCapture.capture}: the source, the time
|
|
27
|
+
* and (processed) the effects and subtitle as they were. Exports read it in
|
|
28
|
+
* the player's offline worker, so one snapshot can be exported several
|
|
29
|
+
* times and playback is unaffected. Disposing it releases the player's
|
|
30
|
+
* copy; an export using it after that fails with `released`.
|
|
31
|
+
*
|
|
32
|
+
* @capability media.read and media.control
|
|
33
|
+
*
|
|
34
|
+
* @example Export one frame as PNG and as JPEG
|
|
35
|
+
* The same frozen frame is written twice, lossless and compressed. Each
|
|
36
|
+
* `export` starts a job of its own; the snapshot is released after both
|
|
37
|
+
* are done.
|
|
38
|
+
* ```ts
|
|
39
|
+
* const snapshot = await plugin.media.capture();
|
|
40
|
+
* try {
|
|
41
|
+
* const png = await snapshot.export({ format: "png", destination: "/tmp/frame.png" });
|
|
42
|
+
* const jpeg = await snapshot.export({ format: "jpeg", destination: "/tmp/frame.jpg", quality: 85 });
|
|
43
|
+
* await Promise.all([png.done, jpeg.done]); // terminal states, not errors
|
|
44
|
+
* } finally {
|
|
45
|
+
* await snapshot.dispose();
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @since 1.0.0
|
|
50
|
+
* @category Media
|
|
51
|
+
*/
|
|
52
|
+
export interface Snapshot extends Disposable {
|
|
53
|
+
/** Without or with effects. */
|
|
54
|
+
readonly kind: "raw" | "processed";
|
|
55
|
+
/** Source time in seconds. */
|
|
56
|
+
readonly time: number;
|
|
57
|
+
/** The source path or URL. */
|
|
58
|
+
readonly source: string;
|
|
59
|
+
/** Media duration in seconds (the backend's estimate). */
|
|
60
|
+
readonly duration: number;
|
|
61
|
+
/** The frozen audio track id, `null` for none. */
|
|
62
|
+
readonly audioTrack: number | null;
|
|
63
|
+
/** Processed snapshots: output size and the frozen processing revision. */
|
|
64
|
+
readonly presentation: {
|
|
65
|
+
/** Output width in pixels. */
|
|
66
|
+
width: number;
|
|
67
|
+
/** Output height in pixels. */
|
|
68
|
+
height: number;
|
|
69
|
+
} | null;
|
|
70
|
+
/** The frozen processing revision (processed snapshots). */
|
|
71
|
+
readonly processingRevision: number | null;
|
|
72
|
+
/**
|
|
73
|
+
* Start exporting; the job runs in the host's offline worker.
|
|
74
|
+
* One snapshot can be exported several times.
|
|
75
|
+
*
|
|
76
|
+
* A **stream copy** (`format: "copy"`, player 0.7.6) writes the video
|
|
77
|
+
* stream and the snapshot's audio track as they are in the file, without
|
|
78
|
+
* decoding: lossless and about as fast as the disk, but a copy can only
|
|
79
|
+
* begin on a keyframe. It starts at the video's last keyframe at or before
|
|
80
|
+
* the snapshot time (its first keyframe when the video itself starts
|
|
81
|
+
* later; keyframes an MP4 edit list discards do not count) and is cut at
|
|
82
|
+
* `end`, where it may run a few frames past `end`. An open GOP can write
|
|
83
|
+
* a frame or two that present before the keyframe; `start` includes them.
|
|
84
|
+
* The finished job's `outcome` gives the `start` and `end` actually
|
|
85
|
+
* written; a plugin that previews the cut (with `plugin.tools.run`
|
|
86
|
+
* and ffprobe's packet flags, say) shows those once the job is done.
|
|
87
|
+
* Copies need a raw snapshot (effects and burned-in subtitles need a
|
|
88
|
+
* re-encode) and leave subtitle tracks and chapters out. `auto` writes
|
|
89
|
+
* MP4 for H.264, HEVC, AV1 or MPEG-4 video with AAC, MP3, AC-3, E-AC-3 or
|
|
90
|
+
* ALAC audio (or none), and MKV for anything else. A copy the player
|
|
91
|
+
* cannot make (no video stream, a cover image, an external audio track,
|
|
92
|
+
* codecs `mp4` cannot hold) ends `failed` with the code `unsupported`.
|
|
93
|
+
*
|
|
94
|
+
* @capability media.read and media.control
|
|
95
|
+
* @throws `released` (rejects) The snapshot was already released.
|
|
96
|
+
* @throws `invalid` (rejects) Bad options (`quality` outside 1–100, a
|
|
97
|
+
* relative destination, a clip `end` not after the snapshot time or
|
|
98
|
+
* past the duration, an {@link ExportEncoding} value outside its set,
|
|
99
|
+
* `copy` from a processed snapshot).
|
|
100
|
+
* @throws `busy` (rejects) This plugin runs 2 exports (or the player 8).
|
|
101
|
+
* @throws `unavailable` (rejects) No FFmpeg, or the export worker could not
|
|
102
|
+
* start.
|
|
103
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
104
|
+
* `media.read` and `media.control`.
|
|
105
|
+
*
|
|
106
|
+
* @example Export a 30-second clip
|
|
107
|
+
* A clip from the snapshot time to 30 seconds later is written as MP4.
|
|
108
|
+
* `export` resolves once the job is accepted; the job then runs in the
|
|
109
|
+
* player's offline worker, and `done` resolves with its terminal state,
|
|
110
|
+
* whose `outcome` has the destination or the error.
|
|
111
|
+
* ```ts
|
|
112
|
+
* declare const snapshot: Snapshot;
|
|
113
|
+
* // ---cut---
|
|
114
|
+
* const job = await snapshot.export({ format: "mp4", destination: "/tmp/clip.mp4", end: snapshot.time + 30 });
|
|
115
|
+
* const end = await job.done;
|
|
116
|
+
* if (end.status !== "completed") await plugin.osd.show("Export {}", [end.status]);
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Cut without re-encoding and report where it starts
|
|
120
|
+
* The clip is copied as it is in the file. A copy starts on a keyframe,
|
|
121
|
+
* so the OSD says where it actually starts; a file the player cannot
|
|
122
|
+
* copy ends with `unsupported`, and the plugin offers a re-encode instead.
|
|
123
|
+
* ```ts
|
|
124
|
+
* declare const snapshot: Snapshot;
|
|
125
|
+
* // ---cut---
|
|
126
|
+
* const job = await snapshot.export({ format: "copy", destination: "/tmp/clip.mp4", end: snapshot.time + 20 });
|
|
127
|
+
* const state = await job.done;
|
|
128
|
+
* const outcome = state.outcome;
|
|
129
|
+
* // The copy starts on a keyframe: outcome.start says where.
|
|
130
|
+
* if (outcome && "destination" in outcome)
|
|
131
|
+
* await plugin.osd.show("Saved {} from {} s", [outcome.destination, (outcome.start ?? snapshot.time).toFixed(1)]);
|
|
132
|
+
* // Codecs the container cannot hold, a cover image, …
|
|
133
|
+
* else if (outcome && "error" in outcome && outcome.error.code === "unsupported")
|
|
134
|
+
* await plugin.osd.show("Fast cut is not possible for this file");
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @since 1.0.0
|
|
138
|
+
*/
|
|
139
|
+
export(options: ExportOptions): Promise<ExportJob>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* One frame as PNG, JPEG (`quality` 1–100, default 90) or BMP (24-bit), or
|
|
143
|
+
* a clip: re-encoded as MP4 (`mp4`, frame-accurate, optional
|
|
144
|
+
* {@link ExportEncoding}) or copied without re-encoding (`copy`, player
|
|
145
|
+
* 0.7.6, starting on a keyframe).
|
|
146
|
+
*
|
|
147
|
+
* `destination` is never overwritten if it exists. The extension does not
|
|
148
|
+
* choose the format (a copy's extension is set to its container).
|
|
149
|
+
* `sampleTime` picks the frame (default: the snapshot time); `end` is the
|
|
150
|
+
* clip's end in source seconds. On Windows the export worker needs FFmpeg
|
|
151
|
+
* 6.1 or newer.
|
|
152
|
+
*
|
|
153
|
+
* **Which players have `copy`, `encoding` and the progress and range of
|
|
154
|
+
* a job**: player 0.7.6 and later. Declare `"minPlayerVersion": "0.7.6"`,
|
|
155
|
+
* or, to keep older players and offer these only where they exist, compare
|
|
156
|
+
* {@link AppInfo.version | plugin.app.version} with `0.7.6`, as for any
|
|
157
|
+
* newer API. Do not probe by trying: on an older player the `plugin`
|
|
158
|
+
* object comes from that player's own, older SDK, which rejects `copy` with
|
|
159
|
+
* `invalid` but builds a re-encode request without the `encoding` it does
|
|
160
|
+
* not know, so the clip is encoded with the fixed settings and no error.
|
|
161
|
+
*
|
|
162
|
+
* @since 1.0.0
|
|
163
|
+
* @category Media
|
|
164
|
+
*/
|
|
165
|
+
export type ExportOptions = {
|
|
166
|
+
/** A lossless frame. */
|
|
167
|
+
format: "png" | "bmp";
|
|
168
|
+
/** Absolute path of the new file. */
|
|
169
|
+
destination: string;
|
|
170
|
+
/** The frame's source time; default the snapshot time. */
|
|
171
|
+
sampleTime?: number;
|
|
172
|
+
} | {
|
|
173
|
+
/** A JPEG frame. */
|
|
174
|
+
format: "jpeg";
|
|
175
|
+
/** Absolute path of the new file. */
|
|
176
|
+
destination: string;
|
|
177
|
+
/** The frame's source time; default the snapshot time. */
|
|
178
|
+
sampleTime?: number;
|
|
179
|
+
/** Integer 1–100, default 90. */
|
|
180
|
+
quality?: number;
|
|
181
|
+
} | {
|
|
182
|
+
/** A clip from the snapshot time, re-encoded as H.264 + AAC. */
|
|
183
|
+
format: "mp4";
|
|
184
|
+
/** Absolute path of the new file. */
|
|
185
|
+
destination: string;
|
|
186
|
+
/** Clip end, source seconds. */
|
|
187
|
+
end: number;
|
|
188
|
+
/**
|
|
189
|
+
* Encoder settings (player 0.7.6); without it, the settings before
|
|
190
|
+
* they existed.
|
|
191
|
+
*
|
|
192
|
+
* @since 1.6.10
|
|
193
|
+
*/
|
|
194
|
+
encoding?: ExportEncoding;
|
|
195
|
+
} | {
|
|
196
|
+
/**
|
|
197
|
+
* A clip copied stream by stream, without re-encoding (player 0.7.6):
|
|
198
|
+
* lossless and about as fast as the disk. It starts on the video
|
|
199
|
+
* keyframe at or before the snapshot time; see {@link Snapshot.export}.
|
|
200
|
+
*
|
|
201
|
+
* @since 1.6.10
|
|
202
|
+
*/
|
|
203
|
+
format: "copy";
|
|
204
|
+
/**
|
|
205
|
+
* Absolute path of the new file. The player gives it the extension of
|
|
206
|
+
* the container it writes (`.mp4` or `.mkv`); the finished job's
|
|
207
|
+
* `outcome.destination` is the actual path.
|
|
208
|
+
*/
|
|
209
|
+
destination: string;
|
|
210
|
+
/** Clip end, source seconds. */
|
|
211
|
+
end: number;
|
|
212
|
+
/**
|
|
213
|
+
* `auto` (default): MP4 when the codecs fit it, otherwise MKV. `mp4`
|
|
214
|
+
* fails with `unsupported` when they do not; `mkv` always writes MKV.
|
|
215
|
+
*/
|
|
216
|
+
container?: "auto" | "mp4" | "mkv";
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* The encoder settings of a re-encoded clip (`format: "mp4"`, player
|
|
220
|
+
* 0.7.6): a closed set of values, never encoder arguments. Every field is
|
|
221
|
+
* optional; the defaults are the settings clips had before: CRF 18, the
|
|
222
|
+
* fastest speed, the source's size and frame rate, AAC 192 kb/s, one thread.
|
|
223
|
+
* A value outside its set rejects the export with `invalid`. `videoBitrate:
|
|
224
|
+
* "source"` replaces the CRF with the source's bitrate, for a "Same as
|
|
225
|
+
* source" preset.
|
|
226
|
+
*
|
|
227
|
+
* @example A small file
|
|
228
|
+
* A 720p, 30 fps clip at a lower quality, encoded with the cores the player
|
|
229
|
+
* can spare.
|
|
230
|
+
* ```ts
|
|
231
|
+
* declare const snapshot: Snapshot;
|
|
232
|
+
* // ---cut---
|
|
233
|
+
* // Each field is a ceiling or a choice from a closed set.
|
|
234
|
+
* const job = await snapshot.export({
|
|
235
|
+
* format: "mp4",
|
|
236
|
+
* destination: "/tmp/small.mp4",
|
|
237
|
+
* end: snapshot.time + 30,
|
|
238
|
+
* encoding: { crf: 26, maxHeight: 720, fps: 30, audioBitrate: 128, threads: "auto" },
|
|
239
|
+
* });
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* @since 1.6.10
|
|
243
|
+
* @category Media
|
|
244
|
+
*/
|
|
245
|
+
export interface ExportEncoding {
|
|
246
|
+
/**
|
|
247
|
+
* H.264 quality, an integer 14–30 (x264's CRF): lower is a better picture
|
|
248
|
+
* and a bigger file. Default 18.
|
|
249
|
+
*/
|
|
250
|
+
crf?: number;
|
|
251
|
+
/**
|
|
252
|
+
* Encoding effort: `faster` (default), `balanced` or `smaller` (slower,
|
|
253
|
+
* a smaller file at the same quality); x264's `veryfast`, `medium` and
|
|
254
|
+
* `slow`.
|
|
255
|
+
*/
|
|
256
|
+
speed?: "faster" | "balanced" | "smaller";
|
|
257
|
+
/**
|
|
258
|
+
* The tallest picture: a taller one is scaled down to this height,
|
|
259
|
+
* keeping its shape; a shorter one is left as it is. Default: the
|
|
260
|
+
* source's size.
|
|
261
|
+
*/
|
|
262
|
+
maxHeight?: 1080 | 720 | 480;
|
|
263
|
+
/**
|
|
264
|
+
* The highest frame rate: a faster source drops frames to it; a slower
|
|
265
|
+
* one is left as it is. Default: the source's rate.
|
|
266
|
+
*/
|
|
267
|
+
fps?: 60 | 30;
|
|
268
|
+
/** AAC audio bitrate in kb/s. Default 192. */
|
|
269
|
+
audioBitrate?: 128 | 192 | 256;
|
|
270
|
+
/**
|
|
271
|
+
* `single` (default) encodes on one thread, leaving the other cores to
|
|
272
|
+
* playback. `auto` lets the player use more: half the logical
|
|
273
|
+
* processors, at most 8, so playback and the interface keep their rate.
|
|
274
|
+
* From player 0.7.6 every export runs at below-normal priority (as
|
|
275
|
+
* HandBrake and OBS run their encoders), with either setting.
|
|
276
|
+
*/
|
|
277
|
+
threads?: "single" | "auto";
|
|
278
|
+
/**
|
|
279
|
+
* `source`: aim at the source video's average bitrate instead of a
|
|
280
|
+
* quality level (peaks up to 1.5 times it), so the file comes out about
|
|
281
|
+
* the size of that stretch of the source: a "Same as source" preset. Not
|
|
282
|
+
* together with `crf` (`invalid`). A source whose bitrate the player
|
|
283
|
+
* cannot tell ends the job `failed` with `unsupported`.
|
|
284
|
+
*/
|
|
285
|
+
videoBitrate?: "source";
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* An export job's state. `status` is `queued`, `running`, `cancelling`,
|
|
289
|
+
* `completed`, `failed` or `cancelled`; once terminal, `outcome` is
|
|
290
|
+
* `{ destination }`, `{ error: { code, message } }` or `{ cancelled: true }`.
|
|
291
|
+
* `facts` describes what the worker produced (versions, range, streams).
|
|
292
|
+
*
|
|
293
|
+
* From player 0.7.6:
|
|
294
|
+
* - a finished clip's `outcome` also has `start` and `end`, the source
|
|
295
|
+
* times of its first frame and of the end of its last frame as written: a
|
|
296
|
+
* copy's earliest written frame (its keyframe, or the leading frames of
|
|
297
|
+
* an open GOP) and actual end; a re-encode's start and start
|
|
298
|
+
* plus the encoded length.
|
|
299
|
+
* - `progress` is `{ done, total }` in seconds of the clip while FFmpeg
|
|
300
|
+
* writes it (at most 4 updates a second; the SDK reads it about every
|
|
301
|
+
* 350 ms), `null` while unknown: before writing starts, and always for a
|
|
302
|
+
* frame. Show an indeterminate bar then. After `done` reaches `total` the
|
|
303
|
+
* player still checks the file before the job completes.
|
|
304
|
+
* - `error.code` is `export-failed`, or `unsupported` for an export the
|
|
305
|
+
* player cannot make as asked (a stream copy it cannot make, a
|
|
306
|
+
* `videoBitrate: "source"` whose source bitrate it cannot tell).
|
|
307
|
+
*
|
|
308
|
+
* @since 1.0.0
|
|
309
|
+
* @category Media
|
|
310
|
+
*/
|
|
311
|
+
export type JobState = Omit<MediaJob, "jobId">;
|
|
312
|
+
/**
|
|
313
|
+
* An export, from {@link Snapshot.export}. Disposing an unfinished job cancels it.
|
|
314
|
+
*
|
|
315
|
+
* @remarks
|
|
316
|
+
* One export, from {@link Snapshot.export}. `state` is the SDK's last copy
|
|
317
|
+
* of the job's state: the SDK polls the player about every 350 ms until the
|
|
318
|
+
* job ends, and `refresh` reads it at once. `done` resolves
|
|
319
|
+
* once the job is terminal (`completed`, `failed` or `cancelled`) and never
|
|
320
|
+
* rejects for a failed export: the failure is in `outcome`. Disposing an
|
|
321
|
+
* unfinished job cancels it.
|
|
322
|
+
*
|
|
323
|
+
* @capability media.read and media.control
|
|
324
|
+
*
|
|
325
|
+
* @example Show export progress and cancel on request
|
|
326
|
+
* The OSD shows the job's status while it runs, and a Cancel command stops
|
|
327
|
+
* it. `onChange` follows the state (`queued`, `running`, `cancelling`,
|
|
328
|
+
* then a terminal one); `cancel` asks the worker to stop. After
|
|
329
|
+
* `requested` the job usually ends `cancelled`, or `failed` when the
|
|
330
|
+
* cleanup failed.
|
|
331
|
+
* ```ts
|
|
332
|
+
* declare const job: ExportJob;
|
|
333
|
+
* // ---cut---
|
|
334
|
+
* job.onChange((state) => void plugin.osd.show("Export: {}", [state.status]));
|
|
335
|
+
* plugin.commands.add({ id: "cancel-export", title: "Cancel export", run: () => job.cancel() });
|
|
336
|
+
* await job.done; // completed, failed or cancelled
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @since 1.0.0
|
|
340
|
+
* @category Media
|
|
341
|
+
*/
|
|
342
|
+
export interface ExportJob extends Disposable {
|
|
343
|
+
/** Latest state. */
|
|
344
|
+
readonly state: JobState;
|
|
345
|
+
/**
|
|
346
|
+
* The state changed.
|
|
347
|
+
*
|
|
348
|
+
* @capability media.read
|
|
349
|
+
*
|
|
350
|
+
* @example Log each state of an export
|
|
351
|
+
* The plugin's log records each status the job goes through (`queued`,
|
|
352
|
+
* `running`, `cancelling` after a cancel, then a terminal one). The listener runs when the SDK learns a
|
|
353
|
+
* new state from its polling.
|
|
354
|
+
* ```ts
|
|
355
|
+
* declare const job: ExportJob;
|
|
356
|
+
* // ---cut---
|
|
357
|
+
* job.onChange((state) => console.log("export", state.status));
|
|
358
|
+
* ```
|
|
359
|
+
*
|
|
360
|
+
* @since 1.0.0
|
|
361
|
+
*/
|
|
362
|
+
onChange(listener: (state: JobState) => void): Disposable;
|
|
363
|
+
/**
|
|
364
|
+
* Resolves with the terminal state (completed, failed or cancelled).
|
|
365
|
+
*
|
|
366
|
+
* @throws `disposed` (rejects) The job handle was disposed while waiting.
|
|
367
|
+
*/
|
|
368
|
+
readonly done: Promise<JobState>;
|
|
369
|
+
/**
|
|
370
|
+
* Ask to cancel: `requested`, `tooLate` (already publishing) or `terminal` (already over).
|
|
371
|
+
*
|
|
372
|
+
* @capability media.control
|
|
373
|
+
* @throws `rejected` (rejects) The player did not accept the request.
|
|
374
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
375
|
+
* `media.control`.
|
|
376
|
+
*
|
|
377
|
+
* @example Cancel an export the user no longer wants
|
|
378
|
+
* The running export stops, unless it is already writing its file.
|
|
379
|
+
* `cancel` resolves `requested` when the worker will stop (the job ends
|
|
380
|
+
* `cancelled`), `tooLate` when it is already publishing the file, and
|
|
381
|
+
* `terminal` when the job had already ended.
|
|
382
|
+
* ```ts
|
|
383
|
+
* declare const job: ExportJob;
|
|
384
|
+
* // ---cut---
|
|
385
|
+
* const answer = await job.cancel();
|
|
386
|
+
* if (answer === "tooLate") await plugin.osd.show("Too late: the file is being written");
|
|
387
|
+
* ```
|
|
388
|
+
*
|
|
389
|
+
* @since 1.0.0
|
|
390
|
+
*/
|
|
391
|
+
cancel(): Promise<"requested" | "tooLate" | "terminal">;
|
|
392
|
+
/**
|
|
393
|
+
* Read the state from the player now.
|
|
394
|
+
*
|
|
395
|
+
* @capability media.read
|
|
396
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
397
|
+
* `media.read`.
|
|
398
|
+
*
|
|
399
|
+
* @example Read a job's state now
|
|
400
|
+
* The plugin reads the newest state of an export without waiting for an
|
|
401
|
+
* event. `refresh` asks the player and resolves with the state, which
|
|
402
|
+
* `state` then holds.
|
|
403
|
+
* ```ts
|
|
404
|
+
* declare const job: ExportJob;
|
|
405
|
+
* // ---cut---
|
|
406
|
+
* const state = await job.refresh();
|
|
407
|
+
* console.log(state.status);
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* @since 1.0.0
|
|
411
|
+
*/
|
|
412
|
+
refresh(): Promise<JobState>;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* `plugin.media`: snapshots and exports. Needs `media.read` and
|
|
416
|
+
* `media.control` (processed snapshots also `playback.read` and
|
|
417
|
+
* `subtitles.read`). Exports decode offline and do not disturb playback.
|
|
418
|
+
*
|
|
419
|
+
* @example Save the current frame as JPEG
|
|
420
|
+
* The frame on screen, with the plugin's own picture effects, is saved
|
|
421
|
+
* where the user chooses. `capture` freezes the source as it was in
|
|
422
|
+
* `seen` (and fails with `stale` if the user opened another file while
|
|
423
|
+
* the dialog was open); `export` decodes offline without disturbing
|
|
424
|
+
* playback, and `done` resolves with the job's final status.
|
|
425
|
+
* ```ts
|
|
426
|
+
* const seen = plugin.player.state;
|
|
427
|
+
* const destination = await plugin.dialogs.saveFile({ fileName: "frame.jpg" });
|
|
428
|
+
* if (!destination) return;
|
|
429
|
+
* const snapshot = await plugin.media.capture({ ifCurrent: seen, processed: true });
|
|
430
|
+
* // Release the frozen frame whatever happens to the export.
|
|
431
|
+
* try {
|
|
432
|
+
* const job = await snapshot.export({ format: "jpeg", destination, quality: 85 });
|
|
433
|
+
* const end = await job.done;
|
|
434
|
+
* if (end.status !== "completed") throw new Error(`export ${end.status}`);
|
|
435
|
+
* } finally {
|
|
436
|
+
* await snapshot.dispose();
|
|
437
|
+
* }
|
|
438
|
+
* ```
|
|
439
|
+
*
|
|
440
|
+
* @remarks
|
|
441
|
+
* Exports run in the player's offline worker from a frozen
|
|
442
|
+
* {@link Snapshot}: a still frame or a clip, raw or with this plugin's
|
|
443
|
+
* effects (and the primary subtitle). Playback is not disturbed. A plugin
|
|
444
|
+
* holds at most 4 snapshots at a time (16 in the player); release them
|
|
445
|
+
* when done.
|
|
446
|
+
*
|
|
447
|
+
* @capability media.read and media.control (processed snapshots also
|
|
448
|
+
* `playback.read` and `subtitles.read`)
|
|
449
|
+
* @since 1.0.0
|
|
450
|
+
* @category Media
|
|
451
|
+
*/
|
|
452
|
+
export interface MediaCapture {
|
|
453
|
+
/**
|
|
454
|
+
* Freeze the current source (and optionally this plugin set's effects)
|
|
455
|
+
* as an input for exports. Fails `stale` when the source changed since
|
|
456
|
+
* `ifCurrent`; `unsupported` for subtitles that cannot be flattened (only
|
|
457
|
+
* plain SRT text can) or a picture over the size limits; `noSource` when
|
|
458
|
+
* nothing is playing.
|
|
459
|
+
*
|
|
460
|
+
* @capability media.read and media.control
|
|
461
|
+
* @throws `stale` (rejects) The source changed since `ifCurrent`.
|
|
462
|
+
* @throws `noSource` (rejects) Nothing is playing.
|
|
463
|
+
* @throws `invalid` (rejects) `at` at or after the end of the source.
|
|
464
|
+
* @throws `busy` (rejects) This plugin holds 4 snapshots (or the player 16);
|
|
465
|
+
* release one.
|
|
466
|
+
* @throws `unavailable` (rejects) A processed snapshot while the picture is
|
|
467
|
+
* still being prepared.
|
|
468
|
+
* @throws `unsupported` (rejects) A processed snapshot the player cannot
|
|
469
|
+
* freeze: subtitles that cannot be flattened (only plain SRT text can),
|
|
470
|
+
* or a picture over the size limits.
|
|
471
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
472
|
+
* `media.read` and `media.control`.
|
|
473
|
+
*
|
|
474
|
+
* @example Freeze the frame at the 10-second mark
|
|
475
|
+
* The plugin freezes the frame at 0:10 of the open file, raw, to export it
|
|
476
|
+
* later. `capture` resolves with a `Snapshot` once the player has frozen
|
|
477
|
+
* that input; the snapshot stays valid when playback moves on or the file
|
|
478
|
+
* changes, until it is released.
|
|
479
|
+
* ```ts
|
|
480
|
+
* const snapshot = await plugin.media.capture({ at: 10 }); // seconds
|
|
481
|
+
* try {
|
|
482
|
+
* // … export it …
|
|
483
|
+
* } finally {
|
|
484
|
+
* await snapshot.dispose(); // frees one of the plugin's 4 snapshot slots
|
|
485
|
+
* }
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @since 1.0.0
|
|
489
|
+
*/
|
|
490
|
+
capture(options?: CaptureOptions): Promise<Snapshot>;
|
|
491
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|