# Add Audio to Video: Replace or Mix Soundtrack, Music, Voice (`data-done-right/add-audio-to-video`) Actor

Replace or mix a soundtrack into videos from direct file URLs: add music or a voice-over, set volumes, duck music under speech, loop short tracks, fade and delay. Video is copied, not re-encoded. mp4 out with signed links. No YouTube. Free when a video fails.

- **URL**: https://apify.com/data-done-right/add-audio-to-video.md
- **Developed by:** [Data Done Right](https://apify.com/data-done-right) (community)
- **Categories:** Videos, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 88.9% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $24.00 / 1,000 video with audio addeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Add Audio to Video: Replace or Mix Soundtrack, Music, Voice

This tool will **add audio to video** files: give it direct video URLs and one audio file (music, a voice-over, a sound effect), and it returns an mp4 for every video with the **soundtrack replaced** or **mixed with the original audio**. Set the volumes, let the music **duck under speech**, **loop** a short track to fill the video, start it at a chosen second and fade it in and out. The picture is **copied, not re-encoded**, in the normal case. It runs ffmpeg in the cloud, so there is nothing to install and no API key.

> **What it does not do.** It does not create audio: no text-to-speech, no music generation, no transcription. You bring the audio file. It reads **direct video and audio files** (mp4, mov, webm, mkv, avi; mp3, wav, m4a, aac, flac, ogg) from a public URL; it **does not download from YouTube, Vimeo, TikTok, Spotify, SoundCloud or other streaming sites** and rejects those links without charge. HLS/DASH playlists are not supported. It follows the robots.txt of the host that serves your files. It does not cut, trim or merge video, does not match audio to the picture automatically (no beat sync, no lip sync) and does not normalise loudness. Only the first audio track of each file is used. The result is always an mp4 with one AAC audio track. Use it only on files you own or have the right to process.

**What you get**

- One dataset row per video: source and audio URLs, mode, how often the audio was looped, whether the video had to be re-encoded, measured duration, size, width, height, a signed download link, and a status or a clear error.
- The result is as long as the video: longer audio is cut at the end of the video, shorter audio is looped (or left silent if you turn `loop` off).
- Bad inputs never stop the run, say exactly what is wrong, and are free: a private or streaming-site link, a file that is not media, an audio file with no audio stream, a start time past the end of the video.

### How to add audio to a video

1. Put one or more **direct video URLs** in `videoUrls`.
2. Put the **audio file URL** in `audioUrl`. It is used for every video in the list.
3. Leave `mode` on `replace` to swap the soundtrack, or choose `mix` to keep the original audio and play the new audio with it.
4. Run it. Open the dataset: every row has a `url` to the finished mp4. The `SUMMARY` record lists each video's duration, resolution and notes.

### How to add background music under speech (ducking)

Use `mode: "mix"`, set `audioVolume` low (0.2 to 0.4 suits background music) and turn on `duck`. While the original audio is loud, the music is pushed down; in the pauses it comes back to the volume you set. Ducking works on loudness only: it cannot tell speech from other loud sounds, so loud background noise in the original also lowers the music. Example: `{"mode": "mix", "audioVolume": 0.3, "duck": true, "fadeOutSeconds": 2}`.

### How to replace the audio of a video

`mode: "replace"` (the default) removes the original audio completely and uses the new audio at `audioVolume`. If the video has no audio track at all, both modes simply add the new audio, and the row says so.

### How to give every video its own audio file

Use `videos`: `[{"url": "https://example.com/ep1.mp4", "audioUrl": "https://example.com/ep1.mp3", "name": "episode-1"}, {"url": "https://example.com/ep2.mp4", "audioUrl": "https://example.com/ep2.wav", "mode": "mix", "audioVolume": 0.4, "delaySeconds": 2}]`. Videos listed there are added to `videoUrls`, and an entry can set `mode`, `audioVolume`, `originalVolume`, `duck`, `loop`, `delaySeconds`, `fadeInSeconds` and `fadeOutSeconds` for that video only. Each distinct audio URL is downloaded once per run.

### Looping, cutting, delay and fades

- **Shorter audio, `loop` on (default):** repeated until the video ends. There is no crossfade, so a hard cut can be heard at each repeat; use a longer file or fade out at the end. The row's `audioLoops` and `note` say how often it repeated.
- **Shorter audio, `loop` off:** the rest of the video is silent in replace mode, or has only the original audio in mix mode.
- **Longer audio:** always cut at the end of the video. `fadeOutSeconds` fades the new audio out over the last seconds of the video, so the cut is not abrupt.
- `delaySeconds` starts the new audio that many seconds into the video (before that, silence in replace mode, the original audio in mix mode). `fadeInSeconds` fades in from that point.
- The result has the same length as the video. If a video's own audio track is longer or shorter than its picture, the result still ends with the picture.

### Video copy or re-encode

| | Video copied (normal) | Video re-encoded (fallback) |
|---|---|---|
| When | the video codec fits an mp4 (H.264, HEVC, AV1, VP9, MPEG-4) | the codec does not (for example VP8 from a webm, MJPEG) or the copy fails |
| What happens | the picture stream is copied bit for bit; only the audio is processed | the picture is re-encoded to H.264 (`crf` sets quality) with an even width and height |
| Quality and speed | no quality loss; seconds per video | one re-compression generation; much slower |
| Limit | the default limits (60 minutes, 500 MB) | **15 minutes**: longer videos that need a re-encode are rejected without charge |

`videoReencoded` in the row tells you which happened. Other streams of the source (extra audio tracks, subtitles, data tracks) are dropped.

### Input

| Field | Default | What it does |
|---|---|---|
| `videoUrls` | sample video | Direct video file links (required). |
| `audioUrl` | sample audio | Direct link to an audio file (or a video file whose audio is used). Max 200 MB by default. |
| `videos` | empty | Per-video audio and options: `[{"url", "audioUrl", "name", ...}]`. |
| `mode` | `replace` | `replace` or `mix`. |
| `audioVolume` | 1 | Volume of the new audio (0 to 4; 1 = unchanged). |
| `originalVolume` | 1 | Mix mode: volume of the video's own audio. |
| `duck` | false | Mix mode: lower the new audio while the original is loud. |
| `loop` | true | Repeat short audio until the video ends. |
| `delaySeconds` | 0 | Start the new audio this many seconds into the video. |
| `fadeInSeconds` / `fadeOutSeconds` | 0 / 0 | Fade the new audio in at its start / out at the end of the video. |
| `audioBitrateKbps` | 192 | AAC bitrate of the result (64 to 320). |
| `crf` | 23 | Quality when the video has to be re-encoded (16 best, 35 smallest). |
| `maxVideosPerRun` | 50 | Hard cap on videos per run (max 1000). |
| `maxVideoSizeMb` / `maxAudioSizeMb` | 500 / 200 | Source size caps (max 2048). |
| `maxDurationMinutes` | 60 | Video duration cap. |
| `videoTimeoutSecs` | 900 | Per download and per ffmpeg job. |
| `outputStoreName` | empty | Save the files in a named store that is kept until you delete it. |

Input example:

```json
{
  "videoUrls": ["https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"],
  "audioUrl": "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
  "mode": "mix",
  "audioVolume": 0.4,
  "duck": true,
  "fadeOutSeconds": 1.5
}
```

### Output

One row per video, from a real local run of the input above:

```json
{
  "sourceUrl": "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4",
  "videoIndex": 1,
  "name": null,
  "audioSource": "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
  "mode": "mix",
  "originalAudioKept": true,
  "audioLoops": 2,
  "videoReencoded": false,
  "durationSeconds": 5.055,
  "width": 960,
  "height": 540,
  "bytes": 1088781,
  "url": "https://api.apify.com/v2/key-value-stores/<store>/records/v01-with-audio.mp4",
  "key": "v01-with-audio.mp4",
  "status": "ok",
  "error": null,
  "note": "the audio (2.1s) is shorter than the video, so it was looped 2 more times (a hard cut at each seam; use a longer file or fadeOutSeconds)"
}
```

A failure row has `status: "error"`, an `error` that names the problem, and `url: null`, for example `the audio file has no audio stream`. On Apify the `url` is a signed link that downloads without a token. `status` is `ok`, `error` or `skipped` (spending limit or `maxVideosPerRun` reached).

### Use with the Apify API, MCP, n8n and Make

Python:

```python
from apify_client import ApifyClient

client = ApifyClient("<APIFY_TOKEN>")
run = client.actor("data-done-right/add-audio-to-video").call(run_input={
    "videoUrls": ["https://example.com/promo.mp4"],
    "audioUrl": "https://example.com/music.mp3",
    "mode": "mix", "audioVolume": 0.3, "duck": True})
for row in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(row["status"], row["url"] or row["error"])
```

JavaScript:

```js
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: '<APIFY_TOKEN>' });
const run = await client.actor('data-done-right/add-audio-to-video').call({
  videoUrls: ['https://example.com/promo.mp4'], audioUrl: 'https://example.com/voiceover.wav', mode: 'replace' });
const { items } = await client.dataset(run.defaultDatasetId).listItems();
```

In n8n or Make use the Apify node with the actor name and the same JSON. With Apify's MCP server (mcp.apify.com) an AI assistant can call it: "put this music under this video". It needs only a video URL and an audio URL.

### Use cases

- Put a music bed under a batch of product or social videos, lowered automatically under any speech.
- Replace the soundtrack of a video after a licensing change, or swap a scratch track for the final mix.
- Add a voice-over (made by a text-to-speech tool or a person) to a screen recording or slideshow video.
- Dub a video: replace the original speech with a translated audio file, one file per video.
- Finish a video pipeline: frames or clips from earlier steps, then an audio track from a generator, then this step.

### How much does it cost

Pay per event: **$0.03 per video delivered** (`video-audio-added`, $30 per 1,000). Failed and skipped videos, rejected links and the `SUMMARY` record are free. Plan discounts apply (Silver about 10%, Gold and higher about 20%).

- 1,000 videos: $30.
- 10,000 videos: $300.
- 100,000 videos: $3,000.

The price is per video whatever its length, size or mode; Apify platform usage is included. `maxVideosPerRun` caps a run, and if you set a maximum spend per run the Actor stops cleanly when it is reached and removes the file it could not charge for. When the video is copied, the ffmpeg step took well under a second for a 1-minute 1280x720 file in a local test; download and upload of the files is most of the time. Re-encoding (see above) is much slower, which is why it is limited to 15 minutes of video.

### FAQ

#### Does it re-encode my video?

Normally not. If the video codec fits an mp4 (H.264, HEVC, AV1, VP9, MPEG-4) the picture is copied unchanged and only the audio is processed, so quality is not lost and it is fast. For other codecs, for example VP8 in a webm, the video is re-encoded to H.264, the row says so (`videoReencoded: true`), and videos over 15 minutes are rejected in that case.

#### Can it keep the original audio and add music?

Yes: `mode: "mix"` with `audioVolume` for the music and `originalVolume` for the original. Turn on `duck` to lower the music while someone is speaking. If the video has no audio, the new audio is added as it is.

#### How well does ducking work?

It compresses the new audio with the original audio as the trigger (ffmpeg `sidechaincompress`: threshold about -30 dB, ratio 8, 20 ms attack, 400 ms release). In tests the music is lowered while the original is loud and returns to its normal level in the silence after it. It reacts to loudness, not to speech, and the settings are not adjustable. Mixed output is passed through a limiter so the sum cannot clip.

#### What if the audio is shorter or longer than the video?

Shorter audio is looped by default (a hard cut at each repeat, noted in the row); turn `loop` off to leave the rest silent. Longer audio is cut at the end of the video. The result always has the length of the video.

#### Which audio formats work?

Whatever ffmpeg can read from a file: mp3, wav, m4a/aac, flac, ogg/opus, and the audio of a video file. The file must be a direct link. Files with no audio stream are rejected without charge. Only the first audio stream is used.

#### Which limits apply?

Videos up to 2 GB (default 500 MB) and 60 minutes by default (set `maxDurationMinutes` for more), audio files up to 2 GB (default 200 MB), up to 1,000 videos per run. Links to private or internal addresses are blocked, and the hosts of your files must allow automated fetching in their robots.txt. The whole source file is downloaded once per video.

#### How long are the files kept?

They live in the run's key-value store, which expires with your plan's retention period. Set `outputStoreName` to keep them in a named store until you delete it.

### Related tools

- **Video Frame Extractor: Keyframes, Scenes & Thumbnails for AI** pulls still images from the same videos.
- **Audio & Video to Text: Whisper Transcription, SRT & VTT** turns speech into a transcript or subtitle file.
- **Remove Silence from Audio & Video: Cut Pauses, Jump Cuts** cuts pauses out before you add the music.
- **Video Compressor & Resizer: Shrink MP4 for Web, Social & AI** shrinks the finished file for web or social.
- **Extract Audio from Video: MP3, WAV & FLAC in Bulk** pulls the audio out of a video, the opposite of this step.

# Actor input Schema

## `videoUrls` (type: `array`):

Direct links to video files (mp4, mov, webm, mkv, avi). Example: https://example.com/clip.mp4. Every video gets the audio given in 'Audio file URL', unless its entry in 'Videos with their own audio' says otherwise. YouTube, Vimeo, TikTok and other streaming-page links are rejected, with no charge.

## `audioUrl` (type: `string`):

Direct link to the new soundtrack: an mp3, wav, m4a, aac, flac or ogg file (a video file works too: its audio is used). Example: https://example.com/music.mp3. Used for every video without its own audio. Max 200 MB by default.

## `videos` (type: `array`):

One audio file per video: \[{"url": "https://example.com/a.mp4", "audioUrl": "https://example.com/a.mp3", "name": "intro", "audioVolume": 0.3}]. An entry can also set mode, audioVolume, originalVolume, duck, loop, delaySeconds, fadeInSeconds and fadeOutSeconds for that video only. Videos listed here are added to 'Video URLs'.

## `mode` (type: `string`):

Replace removes the original audio and uses the new one. Mix keeps the original audio and plays the new one with it (a video with no audio just gets the new audio).

## `audioVolume` (type: `number`):

Loudness of the new audio: 1 = unchanged, 0.3 = quiet background music, 2 = twice as loud (peaks are limited in mix mode). Example: 0.3.

## `originalVolume` (type: `number`):

Mix mode only: loudness of the video's own audio. 1 = unchanged, 0.5 = half. Ignored in replace mode.

## `duck` (type: `boolean`):

Mix mode only: automatically lower the new audio (music) while the original audio (speech) is loud, and bring it back in the pauses. It reacts to loudness, so loud background noise in the original also lowers the music.

## `loop` (type: `boolean`):

When the audio is shorter than the video, repeat it until the video ends (a hard cut at each repeat). Off = the rest of the video is silent (replace mode) or has only the original audio (mix mode). Audio that is longer than the video is always cut at the end of the video.

## `delaySeconds` (type: `number`):

Start the new audio this many seconds into the video. 0 = from the first frame. Example: 2.5.

## `fadeInSeconds` (type: `number`):

Fade the new audio in over this many seconds from where it starts. 0 = no fade. Example: 1.5.

## `fadeOutSeconds` (type: `number`):

Fade the new audio out over the last seconds of the video. 0 = no fade. Example: 3.

## `audioBitrateKbps` (type: `integer`):

AAC bitrate of the result's audio track. 192 is high quality for music, 128 is fine for speech.

## `crf` (type: `integer`):

Only used when the video has to be re-encoded (a codec that does not fit an mp4). Lower = better quality and bigger files: 18 is near-lossless, 23 is the default, 28 is small. Videos that can be copied are never re-encoded.

## `outputStoreName` (type: `string`):

Optional key-value store name. Named stores are kept until you delete them, while the store of a run expires after your plan's retention period. Example: my-soundtracked-videos.

## `maxVideosPerRun` (type: `integer`):

Hard cap on videos processed in one run (and so on what you can be charged). Further videos are listed as skipped.

## `maxVideoSizeMb` (type: `integer`):

Source videos above this size are rejected before the download finishes, without charge.

## `maxAudioSizeMb` (type: `integer`):

Audio files above this size are rejected before the download finishes, without charge.

## `maxDurationMinutes` (type: `number`):

Longer videos are rejected without charge. Example: 60 = one hour.

## `videoTimeoutSecs` (type: `integer`):

Applies separately to each download and to the ffmpeg job of each video. Example: 900 = 15 minutes.

## Actor input object example

```json
{
  "videoUrls": [
    "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"
  ],
  "audioUrl": "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
  "mode": "replace",
  "audioVolume": 1,
  "originalVolume": 1,
  "duck": false,
  "loop": true,
  "delaySeconds": 0,
  "fadeInSeconds": 0,
  "fadeOutSeconds": 0,
  "audioBitrateKbps": 192,
  "crf": 23,
  "maxVideosPerRun": 50,
  "maxVideoSizeMb": 500,
  "maxAudioSizeMb": 200,
  "maxDurationMinutes": 60,
  "videoTimeoutSecs": 900
}
```

# Actor output Schema

## `results` (type: `string`):

One row per video with its download link, size, mode and status, as JSON, CSV, Excel and more.

## `records` (type: `string`):

Key-value store records: the mp4 files and the run summary.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "videoUrls": [
        "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"
    ],
    "audioUrl": "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"
};

// Run the Actor and wait for it to finish
const run = await client.actor("data-done-right/add-audio-to-video").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "videoUrls": ["https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"],
    "audioUrl": "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
}

# Run the Actor and wait for it to finish
run = client.actor("data-done-right/add-audio-to-video").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "videoUrls": [
    "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"
  ],
  "audioUrl": "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"
}' |
apify call data-done-right/add-audio-to-video --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,data-done-right/add-audio-to-video"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/c0oFOrVp2j2UXmbE6/builds/CbDGY8VuK1kUEM3jx/openapi.json
