@vestra-player/sdk - v1.11.3
    Preparing search index...

    Interface MediaCapture

    plugin.media: snapshots and exports. Exports decode offline and do not disturb playback.

    The frame on screen, with the plugin's own picture effects, is saved where the user chooses. capture freezes the source as it was in seen (and fails with stale if the user opened another file while the dialog was open); export decodes offline without disturbing playback, and done resolves with the job's final status.

    const seen = plugin.player.state;
    const destination = await plugin.dialogs.saveFile({ fileName: "frame.jpg" });
    if (!destination) return;
    const snapshot = await plugin.media.capture({ ifCurrent: seen, processed: true });
    // Release the frozen frame whatever happens to the export.
    try {
    const job = await snapshot.export({ format: "jpeg", destination, quality: 85 });
    const end = await job.done;
    if (end.status !== "completed") throw new Error(`export ${end.status}`);
    } finally {
    await snapshot.dispose();
    }

    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.

    1.0.0

    interface MediaCapture {
        capture(options?: CaptureOptions): Promise<Snapshot>;
        sources: MediaSources;
        export(options: PartsExportOptions): Promise<ExportJob>;
        exportCheck(
            input: { snapshot: Snapshot; end: number } | ExportPart[],
            options?: { encoding?: ExportEncoding },
        ): Promise<WireExportCheck>;
    }
    Index
    • 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.

      Parameters

      Returns Promise<Snapshot>

      stale (rejects) The source changed since ifCurrent.

      noSource (rejects) Nothing is playing.

      invalid (rejects) at at or after the end of the source.

      busy (rejects) This plugin holds 4 snapshots (or the player 16); release one.

      unavailable (rejects) A processed snapshot while the picture is still being prepared.

      unsupported (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
      }

      1.0.0

    • 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.

      Parameters

      Returns Promise<ExportJob>

      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).

      busy (rejects) This plugin runs 2 exports (or the player 8).

      unavailable (rejects) No FFmpeg, or the export worker could not start.

      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]);

      1.7.8

    • 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.

      Parameters

      Returns Promise<WireExportCheck>

      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.

      released (rejects) The snapshot was released.

      busy (rejects) This plugin has 4 checks or source requests running.

      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");

      1.7.8

    sources: MediaSources

    Remembered local files: tokens for files the user opened, kept across restarts, for exports made later (MediaCapture.export) and for opening them again (MediaSources.open).

    1.7.8