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

# Transcode a video (change format)

> Convert a video between container formats (MP4, MOV, AVI, WebM) and codecs using Rendi's FFmpeg API. Node.js, Python, and cURL examples.

Convert a video between container formats and codecs — e.g., AVI to MP4, MOV to WebM, or re-encode an existing MP4 with H.264/AAC.

## 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: "output.mp4",
        },
        ffmpeg_command:
          "-i {{in_1}} -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 192k {{out_1}}",
      }),
    });
    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("Output URL:", data.output_files.out_1.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": "output.mp4"},
            "ffmpeg_command": "-i {{in_1}} -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 192k {{out_1}}",
        },
    )
    command_id = submit.json()["command_id"]

    while True:
        res = requests.get(f"{BASE}/commands/{command_id}", headers=headers).json()
        if res["status"] == "SUCCESS":
            print("Output URL:", res["output_files"]["out_1"]["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": "output.mp4"},
        "ffmpeg_command": "-i {{in_1}} -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 192k {{out_1}}"
      }'

    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

* `-i {{in_1}}` — input video URL
* `-c:v libx264` — encode video with H.264
* `-preset medium` — encoder speed/size tradeoff (`ultrafast` → `veryslow`)
* `-crf 23` — quality (lower = better; 18 = near-lossless, 23 = default, 28 = compressed)
* `-c:a aac -b:a 192k` — AAC audio at 192 kbps
* `{{out_1}}` — output file; extension picks the container (`.mp4`, `.webm`, `.mov`)

## Response

```json theme={null}
{
  "output_files": {
    "out_1": {
      "file_id": "f775b15d-67e9-4235-b89f-4bb33c0a5f57",
      "size_mbytes": 12.5,
      "duration": 596.459,
      "file_type": "video",
      "file_format": "mp4",
      "storage_url": "https://storage.rendi.dev/temp_files/.../output.mp4",
      "width": 854,
      "height": 480,
      "codec": "h264",
      "frame_rate": 24.0,
      "bitrate_video_kb": 180.5,
      "bitrate_audio_kb": 192.0
    }
  },
  "status": "SUCCESS",
  "command_type": "FFMPEG_COMMAND"
}
```

## Related

* [Compress video](/examples/compress-video)
* [Resize video](/examples/resize-video)
* [Cheatsheet — Converting formats](https://github.com/rendi-api/ffmpeg-cheatsheet#converting-formats)
