# Adding Your Own Licensed Sound to a Silent AI Clip with ffmpeg

Some AI video effects return a clip with no audio track at all. Crazy Frog AI, a two-photo highway-chase template on MixVio, is one of them: its page says the effect does not generate audio and suggests adding a licensed sound when you publish. That leaves a small, very scriptable job: put a track you have the rights to under a 15-second 16:9 clip, trim it to length, fade the edges and normalise loudness for the platform.

This post walks through that job with ffmpeg and ffprobe. Nothing here is specific to one product; it works for any silent MP4.

![AI-generated frame of the example clip: two people on an elevated highway, a rider on an invisible motorbike and a chaser behind.](https://cdn.hashnode.com/uploads/covers/6ac7155f8cadc38d9e483af7/051e996a-9e16-41d1-ac6b-f8aa0b46e9ea.jpg align="center")

*Frame from an AI-generated example clip (two AI-generated people, no real persons).*

## What we are working with

The input is an MP4 with one H.264 video stream and no audio stream. The clip is 15 seconds long, 16:9, 720p. The second input is a music file you licensed, for example `track.m4a` or `track.wav`.

Goals for the output:

*   Video stream copied untouched (no re-encode, no quality loss).
    
*   Audio cut to the exact clip length, with a short fade in and fade out.
    
*   AAC, 48 kHz, stereo, around -14 LUFS integrated, true peak below -1 dBTP.
    

## Step 1: confirm the clip really has no audio

Do not assume. Ask ffprobe for audio streams only:

```bash
ffprobe -v error -select_streams a \
  -show_entries stream=index,codec_name \
  -of csv=p=0 clip.mp4
```

Empty output means there is no audio stream. If you see a line such as `1,aac`, the file already has audio and you need to decide whether to replace it (`-map` handles that below).

Also grab the exact duration, because "15 seconds" is rarely 15.000:

```bash
ffprobe -v error -show_entries format=duration \
  -of default=nw=1:nk=1 clip.mp4
```

Store it in a shell variable for the next steps:

```bash
DUR=$(ffprobe -v error -show_entries format=duration \
  -of default=nw=1:nk=1 clip.mp4)
echo "$DUR"
```

## Step 2: the minimal mux

If you searched for how to add licensed audio to an AI video with ffmpeg, this is the command you need:

```bash
ffmpeg -i clip.mp4 -i track.m4a \
  -map 0:v:0 -map 1:a:0 \
  -c:v copy -c:a aac -b:a 192k -ar 48000 -ac 2 \
  -shortest out_basic.mp4
```

What each part does:

*   `-map 0:v:0` takes the first video stream from the clip.
    
*   `-map 1:a:0` takes the first audio stream from the track. Any audio in the clip is ignored.
    
*   `-c:v copy` keeps the video bit-for-bit.
    
*   `-shortest` stops when the shorter input ends, usually the video.
    

`-shortest` is convenient but can leave a few hundred milliseconds of drift because of encoder frame padding. For a clean end, cut the audio to the measured duration instead.

## Step 3: trim, fade and pad

Use `atrim` to cut, `afade` for the edges and `apad` so the audio is never shorter than the video: Calculate the fade-out start from the shorter of the track and video durations. If the track is shorter, apad fills the remaining time with silence until the video ends.

```bash
FADE=0.5
TRACK_DUR=$(ffprobe -v error -show_entries format=duration \
  -of default=nw=1:nk=1 track.m4a)
AUDIO_DUR=$(python3 -c "print(min(float('$DUR'), float('$TRACK_DUR')))")
OUT_START=$(echo "$AUDIO_DUR - $FADE" | bc -l)
ffmpeg -i clip.mp4 -i track.m4a \
  -filter_complex "[1:a]atrim=0:${AUDIO_DUR},asetpts=N/SR/TB,\
afade=t=in:st=0:d=${FADE},\
afade=t=out:st=${OUT_START}:d=${FADE},apad[a]" \
  -map 0:v:0 -map "[a]" -t "$DUR" \
  -c:v copy -c:a aac -b:a 192k -ar 48000 -ac 2 \
  out_faded.mp4
```

If the interesting part of the track starts later, add an offset with `-ss` before the audio input, for example `-ss 12 -i track.m4a`.

## Step 4: loudness for short-video platforms

Most short-video platforms normalise around -14 LUFS. Running `loudnorm` in two passes gives a more accurate result than one pass. First, measure:

```bash
ffmpeg -i out_faded.mp4 -map 0:a:0 \
  -af loudnorm=I=-14:TP=-1.5:LRA=11:print_format=json \
  -f null - 2>&1 | tail -n 12
```

Copy the measured values into the second pass:

```bash
ffmpeg -i out_faded.mp4 -map 0:v:0 -map 0:a:0 \
  -af "loudnorm=I=-14:TP=-1.5:LRA=11:\
measured_I=-19.2:measured_TP=-3.1:\
measured_LRA=6.0:measured_thresh=-29.4:\
offset=0.3:linear=true" \
  -c:v copy -c:a aac -b:a 192k -ar 48000 -ac 2 \
  out_final.mp4
```

The numbers above are placeholders from one run; always paste your own.

## Step 5: verify before you upload

Check streams, duration and loudness one last time:

```bash
ffprobe -v error \
  -show_entries stream=codec_type,codec_name,sample_rate,channels \
  -show_entries format=duration -of compact out_final.mp4

ffmpeg -i out_final.mp4 -map 0:a:0 -af ebur128=peak=true \
  -f null - 2>&1 | tail -n 14
```

You want one video stream, one AAC stream at 48000 Hz with 2 channels, the same duration as the original clip, integrated loudness near -14 LUFS and a true peak below -1 dBTP.

## A small batch script

If you make several clips, wrap the steps in a function:

```bash
add_track() {
  clip="$1"; track="$2"; out="$3"; fade=0.5
  dur=$(ffprobe -v error -show_entries format=duration \
    -of default=nw=1:nk=1 "$clip")
  track_dur=$(ffprobe -v error -show_entries format=duration \
    -of default=nw=1:nk=1 "$track")
  audio_dur=$(python3 -c "print(min(float('$dur'), float('$track_dur')))")
  start=$(echo "$audio_dur - $fade" | bc -l)
  ffmpeg -y -i "$clip" -i "$track" \
    -filter_complex "[1:a]atrim=0:${audio_dur},asetpts=N/SR/TB,\
afade=t=in:st=0:d=${fade},afade=t=out:st=${start}:d=${fade},\
apad,loudnorm=I=-14:TP=-1.5:LRA=11[a]" \
    -map 0:v:0 -map "[a]" -t "$dur" \
    -c:v copy -c:a aac -b:a 192k -ar 48000 -ac 2 "$out"
}
add_track clip.mp4 track.m4a clip_with_sound.mp4
```

This uses single-pass `loudnorm`, which is fine for drafts. Use the two-pass version for the final upload.

## Common errors and fixes

A few messages you are likely to see, and what they mean:

*   `Stream map '1:a:0' matches no streams`: the second input has no audio, or you pointed at the wrong file. Run the Step 1 probe on the track.
    
*   **Video re-encodes even with** `-c:v copy`: a video filter slipped into `-vf` or the `filter_complex` touches `[0:v]`. Keep filters on the audio branch only.
    
*   **Audio ends early**: the track is shorter than the clip. Base the fade-out start on the shorter of the track and video durations so it lands before the music ends, then `apad` fills the rest with silence, and `-t "$DUR"` stops at the right point.
    
*   **Output plays, but the platform rejects it**: check that the audio is 48000 Hz stereo AAC and the container is MP4 with `+faststart` if you serve it from your own site (`-movflags +faststart`).
    
*   **Clipping after loudnorm**: lower the target to `TP=-2` or use the two-pass version.
    

## Licensing is part of the pipeline

The command line is the easy part. The track itself needs a licence that covers the platform you post to. Practical options:

*   Use the sound library inside the app you publish on, which is licensed for that app.
    
*   Use a stock or library track whose licence explicitly covers social video.
    
*   Use music you made yourself.
    

Keep a note of where each track came from next to the output file, including the licence name and date. If a platform later asks, you have the answer.

A note on the example effect's name, quoted from its page FAQ: "No. This is an independent highway-chase effect for two consenting adults. There are no weapons, no blood, and no crash, and it is not a frog character."

## Related

*   [Bulin 47 AI, another effect page](https://mixvio.ai/ai-effects/bulin-47-ai?utm_source=hashnode&utm_medium=article&utm_campaign=crazy-frog-ai&utm_content=crazy-frog-ai-hashnode-related-bulin#effect-workspace): a one-photo, 15-second vertical clip; the same audio steps apply after a 9:16 export.
    
*   [Burning Bridges AI, a party-video template](https://mixvio.ai/ai-effects/burning-bridges-ai?utm_source=hashnode&utm_medium=article&utm_campaign=crazy-frog-ai&utm_content=crazy-frog-ai-hashnode-related-bb#effect-workspace): a 16:9 party video with one lead photo and optional background guests.
    
*   [MixVio, the AI effects site](https://mixvio.ai/?utm_source=hashnode&utm_medium=article&utm_campaign=crazy-frog-ai&utm_content=crazy-frog-ai-hashnode-related-home) lists the other effects.
    

To try the workflow end to end: [Generate the silent clip here](https://mixvio.ai/ai-effects/crazy-frog-ai?utm_source=hashnode&utm_medium=article&utm_campaign=crazy-frog-ai&utm_content=crazy-frog-ai-hashnode-cta#effect-workspace), then run the script on the result.

*Written by the MixVio team. Example frame is AI-generated. AI assisted with writing.*
