Freeze the current source (and optionally this plugin set's effects)
as an input for exports. Fails stale when the source changed since
ifCurrent; unsupported for subtitles that cannot be flattened (only
plain SRT text can) or a picture over the size limits; noSource when
nothing is playing.
Optionaloptions: CaptureOptionsunsupported (rejects) A processed snapshot the player cannot
freeze: subtitles that cannot be flattened (only plain SRT text can),
or a picture over the size limits.
The plugin freezes the frame at 0:10 of the open file, raw, to export it
later. capture resolves with a Snapshot once the player has frozen
that input; the snapshot stays valid when playback moves on or the file
changes, until it is released.
const snapshot = await plugin.media.capture({ at: 10 }); // seconds
try {
// … export it …
} finally {
await snapshot.dispose(); // frees one of the plugin's 4 snapshot slots
}
Export a clip whose input is ranges of remembered files instead of a
snapshot: one part is a clip of one file, several parts are joined in
the order given into one file. The same formats as a clip of a
snapshot (ExportOptions: copy and mp4), the same job
(ExportJob: the queue of 2 per plugin and 8 in the player,
done, cancel, outcome); a snapshot's export is unchanged.
format: "copy" copies each part without re-encoding, from the video
keyframe at or before its start (as a copied clip), and needs every
part to have the same video codec, profile, codec data, size, frame
rate and pixel format and the same audio (or none):
MediaCapture.exportCheck says whether they do and, if not, why.
format: "mp4" re-encodes every part to H.264 + AAC at the first
part's size (square pixels) and frame rate under the
ExportEncoding ceilings, each picture scaled to fit and centred
on black, the sound resampled to 48 kHz stereo (silence for a part
without sound when another part has some).
While it runs, progress covers the whole output (done and
total in seconds) and says which part is being written (part
from 1, of parts). A finished job's facts.join has the range each
part was written from. A part whose file is gone ends the job
failed with source-missing, a file changed since it was remembered
with source-changed, parts a copy cannot write together with unsupported.
Before writing, the player compares the free space with an estimate
(the parts' share of their files for a copy; the picture for a
re-encode) for the intermediate parts, kept in the player's own
temporary folder, and for the output beside destination; too little
ends the job failed with no-space. Cancelling removes everything
written so far, and what a crash leaves in the temporary folder goes
at the player's next start.
invalid (rejects) No part or more than 100, a part whose end
is not after its start, parts longer than 24 hours in all, a relative
destination, encoding with copy or container with mp4, an
ExportEncoding value outside its set.
missing (rejects) A part's token is not one of this
plugin's references (forgotten, or another plugin's).
Two parts from two files become one file, copied as they are when the
check allows it and re-encoded otherwise. exportCheck answers from
the remembered facts; the job then runs in the player's export worker
and done resolves with its terminal state.
const parts = [
{ source: intro.token, start: 0, end: 12 },
{ source: scene.token, start: 95.5, end: 130 },
];
const check = await plugin.media.exportCheck(parts);
if (check.blocking.length > 0) return; // a file is missing, say
const job = await plugin.media.export({
parts,
destination: "/tmp/joined.mp4",
format: check.copy.ok ? "copy" : "mp4",
});
const end = await job.done;
await plugin.osd.show("Export: {}", [end.status]);
Check an export before starting it, of parts or of a snapshot's clip:
what blocks it (a part whose file is missing or changed, an unknown
token, a range outside the file, a file without video), whether a
stream copy (format: "copy") can write it and, if not, each
difference from the first part (effects for a processed snapshot,
whose effects need a re-encode), and what a re-encode (format: "mp4") writes (with encoding, under its ceilings). Parts are
numbered from 0 in the order given; { snapshot, end } is one part,
the snapshot's clip from its time to end. For parts it reads the
facts remembered with each reference and looks at each file on disk
(nothing is decoded, so it is cheap enough to run on every change of
a list); for a snapshot it reads the held file's streams.
Optionaloptions: { encoding?: ExportEncoding }
Optionalencoding?: ExportEncodingThe re-encode's settings, for its size and frame rate.
invalid (rejects) No part or more than 100, a time that is
negative, past 24 hours (24 hours in all) or not finite, a snapshot
end not after its time or past its duration, an invalid
encoding.
The plugin shows a line under its list when the parts need a re-encode. Each reason names the part, the field that differs and both values, so the line can say "part 2 is 1920×818, part 1 is 3840×1714".
const check = await plugin.media.exportCheck(parts);
if (!check.copy.ok) {
// Parts count from 0; the first difference is enough for one line.
const [first] = check.copy.reasons;
if (first)
console.log(`part ${first.part + 1} is ${first.value}, part 1 is ${first.expected}`);
}
The Clip page greys its Fast button when a stream copy of the marked
range cannot be made. The same check takes a snapshot's clip: one part
from the snapshot time to end.
const check = await plugin.media.exportCheck({ snapshot, end: snapshot.time + 20 });
const fast = check.copy.ok;
console.log(fast ? "Fast" : "Precise only");
ReadonlysourcesRemembered local files: tokens for files the user opened, kept across restarts, for exports made later (MediaCapture.export) and for opening them again (MediaSources.open).
plugin.media: snapshots and exports. Exports decode offline and do not disturb playback.Example: Save the current frame as JPEG
The frame on screen, with the plugin's own picture effects, is saved where the user chooses.
capturefreezes the source as it was inseen(and fails withstaleif the user opened another file while the dialog was open);exportdecodes offline without disturbing playback, anddoneresolves with the job's final status.Remarks
Exports run in the player's offline worker from a frozen Snapshot: a still frame or a clip, raw or with this plugin's effects (and the primary subtitle). Playback is not disturbed. A plugin holds at most 4 snapshots at a time (16 in the player); release them when done.
Since
1.0.0