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

    Interface Tools

    plugin.tools: ffmpeg and ffprobe, run in this plugin's process.

    The plugin gets a media file's container details as JSON. available says whether ffprobe can be found (VESTRA_FFPROBE, then PATH); run starts it from the plugin's own process without a shell and resolves with its output as bytes once it exits, or rejects when it fails (failed, with the last stderr line) or takes longer than timeoutMs.

    if (await plugin.tools.available("ffprobe")) {
    const { stdout } = await plugin.tools.run(
    "ffprobe",
    ["-v", "error", "-show_format", "-of", "json", path],
    { timeoutMs: 10_000 }, // give up on a stuck file after 10 s
    );
    const info = JSON.parse(new TextDecoder().decode(stdout));
    void info.format; // container, duration, bit rate…
    }

    ffmpeg and ffprobe run as child processes of the plugin. When VESTRA_FFMPEG / VESTRA_FFPROBE is set, only that path is used (an invalid one means the tool is not found); otherwise the tool is searched on PATH. A found path is kept for the plugin's run, a miss is looked up again next time. Disposing the scope ends a running process.

    1.0.0

    interface Tools {
        run(
            tool: "ffmpeg" | "ffprobe",
            args: string[],
            options: { timeoutMs: number; maxOutput?: number; signal?: AbortSignal },
        ): Promise<ToolResult>;
        available(tool: "ffmpeg" | "ffprobe"): Promise<boolean>;
    }
    Index
    • Run ffmpeg or ffprobe (VESTRA_FFMPEG / VESTRA_FFPROBE when set, else found on PATH) without a shell. Rejects unavailable (not found), timeout, failed (non-zero exit; message is the last stderr line), invalid (output over maxOutput, default 16 MiB), aborted (signal). Timeout, signal and disposing the scope end the process.

      Arguments are passed as-is (no quoting needed). On Windows PATHEXT is honoured. Ending sends SIGTERM, then SIGKILL after 300 ms (immediate on Windows).

      Parameters

      • tool: "ffmpeg" | "ffprobe"
      • args: string[]
      • options: { timeoutMs: number; maxOutput?: number; signal?: AbortSignal }

      Returns Promise<ToolResult>

      unavailable (rejects) The tool was not found.

      timeout (rejects) It ran longer than timeoutMs; the process is ended.

      failed (rejects) A non-zero exit; message is the last stderr line.

      invalid (rejects) Bad arguments or options, or output over maxOutput.

      aborted (rejects) signal aborted, or the scope was disposed.

      The plugin writes the first ten seconds of the file to a new file. run starts ffmpeg without a shell (arguments pass as they are, no quoting) and resolves with its output once it exits with 0; a failure rejects with the last line ffmpeg printed.

      await plugin.tools.run(
      "ffmpeg",
      ["-y", "-i", input, "-t", "10", "-c", "copy", output],
      { timeoutMs: 60_000 }, // give up after a minute
      );

      1.0.0

    • Whether the tool can be found.

      Parameters

      • tool: "ffmpeg" | "ffprobe"

      Returns Promise<boolean>

      Never; it resolves false when the tool cannot be found.

      The Export item is disabled with a reason when ffmpeg is not installed. available looks the tool up (a found path is kept, a miss is looked up again on the next call, so installing it later is noticed).

      const hasFfmpeg = await plugin.tools.available("ffmpeg");
      plugin.commands.add({
      id: "export",
      path: ["@video", "Export…"],
      enabled: hasFfmpeg,
      // Shown with the greyed-out item.
      reason: hasFfmpeg ? null : "Install ffmpeg to export",
      run() {},
      });

      1.0.0