> ## Documentation Index
> Fetch the complete documentation index at: https://rendi.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate multiple thumbnails from a video

> Extract several frames at different timestamps in one FFmpeg call using Rendi. Node.js, Python, and cURL examples.

Extract multiple frames from a video in a single call, each at its own timestamp. Cheaper than N separate calls since the input is decoded once.

## Code

<Tabs>
  <Tab title="Node.js">
    ```js theme={null}
    const API_KEY = process.env.RENDI_API_KEY;

    const submit = await fetch("https://api.rendi.dev/v1/run-ffmpeg-command", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-API-KEY": API_KEY,
      },
      body: JSON.stringify({
        input_files: {
          in_1: "https://storage.rendi.dev/sample/sample.avi",
        },
        output_files: {
          out_1: "thumbnail1.jpg",
          out_2: "thumbnail2.jpg",
        },
        ffmpeg_command:
          "-i {{in_1}} -filter_complex \"[0:v]split=2[first][second];[first]select='gte(t,10)'[thumb1];[second]select='gte(t,20)'[thumb2]\" -map [thumb1] -frames:v 1 {{out_1}} -map [thumb2] -frames:v 1 {{out_2}}",
      }),
    });
    const { command_id } = await submit.json();

    while (true) {
      const res = await fetch(`https://api.rendi.dev/v1/commands/${command_id}`, {
        headers: { "X-API-KEY": API_KEY },
      });
      const data = await res.json();
      if (data.status === "SUCCESS") {
        console.log("Thumb 1:", data.output_files.out_1.storage_url);
        console.log("Thumb 2:", data.output_files.out_2.storage_url);
        break;
      }
      if (data.status === "FAILED") throw new Error("Command failed");
      await new Promise((r) => setTimeout(r, 2000));
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import os
    import time
    import requests

    API_KEY = os.environ["RENDI_API_KEY"]
    BASE = "https://api.rendi.dev/v1"
    headers = {"X-API-KEY": API_KEY}

    submit = requests.post(
        f"{BASE}/run-ffmpeg-command",
        headers=headers,
        json={
            "input_files": {"in_1": "https://storage.rendi.dev/sample/sample.avi"},
            "output_files": {"out_1": "thumbnail1.jpg", "out_2": "thumbnail2.jpg"},
            "ffmpeg_command": "-i {{in_1}} -filter_complex \"[0:v]split=2[first][second];[first]select='gte(t,10)'[thumb1];[second]select='gte(t,20)'[thumb2]\" -map [thumb1] -frames:v 1 {{out_1}} -map [thumb2] -frames:v 1 {{out_2}}",
        },
    )
    command_id = submit.json()["command_id"]

    while True:
        res = requests.get(f"{BASE}/commands/{command_id}", headers=headers).json()
        if res["status"] == "SUCCESS":
            print("Thumb 1:", res["output_files"]["out_1"]["storage_url"])
            print("Thumb 2:", res["output_files"]["out_2"]["storage_url"])
            break
        if res["status"] == "FAILED":
            raise RuntimeError("Command failed")
        time.sleep(2)
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl --request POST \
      --url https://api.rendi.dev/v1/run-ffmpeg-command \
      --header 'Content-Type: application/json' \
      --header 'X-API-KEY: <api-key>' \
      --data '{
        "input_files": {"in_1": "https://storage.rendi.dev/sample/sample.avi"},
        "output_files": {"out_1": "thumbnail1.jpg", "out_2": "thumbnail2.jpg"},
        "ffmpeg_command": "-i {{in_1}} -filter_complex \"[0:v]split=2[first][second];[first]select='\''gte(t,10)'\''[thumb1];[second]select='\''gte(t,20)'\''[thumb2]\" -map [thumb1] -frames:v 1 {{out_1}} -map [thumb2] -frames:v 1 {{out_2}}"
      }'

    curl --request GET \
      --url https://api.rendi.dev/v1/commands/<command_id> \
      --header 'X-API-KEY: <api-key>'
    ```
  </Tab>
</Tabs>

## How the FFmpeg command works

* `split=2[first][second]` — duplicate the video stream so we can select frames at two different times
* `select='gte(t,10)'[thumb1]` — pick the first frame at or after 10 s
* `select='gte(t,20)'[thumb2]` — pick the first frame at or after 20 s
* `-map [thumb1] -frames:v 1 {{out_1}}` — write one frame to `thumbnail1.jpg`
* `-map [thumb2] -frames:v 1 {{out_2}}` — write one frame to `thumbnail2.jpg`

For N thumbnails, extend the split count and add another `select` + `-map` pair per output.

## Response

```json theme={null}
{
  "output_files": {
    "out_1": {
      "file_id": "eba1a713-...",
      "size_mbytes": 0.085,
      "file_type": "image",
      "file_format": "jpg",
      "storage_url": "https://storage.rendi.dev/temp_files/.../thumbnail1.jpg",
      "width": 1280,
      "height": 720
    },
    "out_2": {
      "file_id": "d8278ca9-...",
      "size_mbytes": 0.039,
      "file_type": "image",
      "file_format": "jpg",
      "storage_url": "https://storage.rendi.dev/temp_files/.../thumbnail2.jpg",
      "width": 1280,
      "height": 720
    }
  },
  "status": "SUCCESS",
  "command_type": "FFMPEG_COMMAND"
}
```

## Related

* [Generate a thumbnail](/examples/generate-thumbnail)
* [Thumbnail + GIF (chained)](/examples/thumbnail-and-gif-chained)
* [Cheatsheet — Create thumbnails from video](https://github.com/rendi-api/ffmpeg-cheatsheet#create-thumbnails-from-video)
