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

# Extract audio from a video

> Extract the audio track from MP4/MOV/AVI to MP3, WAV, or AAC using Rendi's FFmpeg API. Node.js, Python, and curl examples.

Extract the audio track from a video and save it as MP3. Useful when you want to strip audio out for transcription, podcast generation, or separate audio processing.

## Code

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

    // Submit the FFmpeg command
    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: "audio.mp3",
        },
        ffmpeg_command: "-i {{in_1}} -vn -c:a libmp3lame -q:a 2 {{out_1}}",
      }),
    });
    const { command_id } = await submit.json();

    // Poll until complete
    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("Audio 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 the FFmpeg command
    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": "audio.mp3"},
            "ffmpeg_command": "-i {{in_1}} -vn -c:a libmp3lame -q:a 2 {{out_1}}",
        },
    )
    command_id = submit.json()["command_id"]

    # Poll until complete
    while True:
        res = requests.get(f"{BASE}/commands/{command_id}", headers=headers).json()
        if res["status"] == "SUCCESS":
            print("Audio 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}
    # Submit the FFmpeg command
    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": "audio.mp3"},
        "ffmpeg_command": "-i {{in_1}} -vn -c:a libmp3lame -q:a 2 {{out_1}}"
      }'

    # Response: { "command_id": "..." }

    # Poll until complete
    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
* `-vn` — discard the video stream (audio only)
* `-c:a libmp3lame` — encode audio as MP3
* `-q:a 2` — variable-bitrate quality (0 = best, 9 = worst; 2 is a good balance)
* `{{out_1}}` — output file (`audio.mp3`)

To export as WAV, rename `out_1` to `audio.wav` and drop the `-c:a libmp3lame -q:a 2` flags — FFmpeg picks the codec from the extension.

## Response

```json theme={null}
{
  "output_files": {
    "out_1": {
      "file_id": "eba1a713-4631-4ccb-9ef8-b727a9f7f274",
      "size_mbytes": 4.62,
      "duration": 596.459,
      "file_type": "audio",
      "file_format": "mp3",
      "storage_url": "https://storage.rendi.dev/temp_files/.../audio.mp3",
      "bitrate_audio_kb": 128.0
    }
  },
  "status": "SUCCESS",
  "command_type": "FFMPEG_COMMAND"
}
```

## Related

* [Compress video](/examples/compress-video)
* [Cheatsheet — Extract audio from video](https://github.com/rendi-api/ffmpeg-cheatsheet#extract-audio-from-video)
* [run-ffmpeg-command API reference](/api-reference/endpoint/run-ffmpeg-command)
