Extract and Add Audio
Work with audio streams: extract, replace, adjust volume, and mix multiple audio tracks.
Skip the install. Run this lesson's commands via the FFmpeg Micro API in 30 seconds.
Get free API keyHow FFmpeg Handles Audio
A video file typically contains at least two streams: one video and one audio. FFmpeg lets you work with each stream independently. You can extract the audio, replace it, adjust the volume, or mix in additional tracks without touching the video at all.
The key flags for audio work:
-c:asets the audio codec-anremoves all audio streams-vnremoves all video streams (audio-only output)-afapplies audio filters (like-vffor video)-mapselects which streams to include in the output
Extracting Audio from Video
Extract without re-encoding
If you just need the audio track in its original format:
The -vn flag drops the video stream. Combined with -c:a copy, the audio is extracted instantly with zero quality loss. Use the file extension that matches the audio codec in the source: .aac for AAC, .mp3 for MP3, .opus for Opus.
Tip: Not sure which audio codec the file uses? Run ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of csv=p=0 input.mp4 to find out.
Extract and convert to MP3
This re-encodes the audio to MP3 at 192 kbps. Common bitrates: 128k (smaller, acceptable quality), 192k (good balance), 320k (maximum MP3 quality).
Extract to WAV (uncompressed)
WAV files are uncompressed and large, but useful when you need to bring the audio into an editor like Audacity or Adobe Audition for further processing.
Or skip the install: run this audio extraction through the FFmpeg Micro API. No local FFmpeg needed. Get a free API key or see the quickstart.
Removing Audio from Video
Sometimes you need a silent video, whether for a muted autoplay embed, a GIF-like loop, or to replace the audio entirely:
The -an flag strips all audio. Combined with -c:v copy, the video passes through untouched.
Replacing Audio
To swap in a new audio track, like background music or a voiceover, use two inputs with the -map flag:
Breaking it down:
-map 0:vtakes the video stream from the first input (video.mp4)-map 1:atakes the audio stream from the second input (new-audio.mp3)-shorteststops when the shorter input ends (so the output does not have trailing silence or video)
Or skip the install: run this audio extraction through the FFmpeg Micro API. No local FFmpeg needed. Get a free API key or see the quickstart.
Adjusting Volume
The volume audio filter adjusts loudness:
Double the volume
Halve the volume
Set volume in decibels
Normalize loudness
If you are stitching clips from different sources, their volumes will be inconsistent. The loudnorm filter normalizes them to broadcast standards:
This targets -16 LUFS (the standard for YouTube and most platforms) with a true peak of -1.5 dB.
Mixing Audio Tracks
To layer background music under a video's existing audio (like adding a soundtrack to a vlog), use the amix filter:
This keeps the original audio at full volume, brings the music to 30% volume, and mixes them together. The duration=first option stops when the video's audio ends.
Common Audio Codecs
| Codec | FFmpeg Encoder | Best For |
|---|---|---|
| AAC | aac | MP4 video (default), streaming |
| MP3 | libmp3lame | Audio-only files, universal compatibility |
| Opus | libopus | WebM video, voice calls, best quality per bit |
| FLAC | flac | Lossless archiving |
Key Takeaways
- Use
-vn -c:a copyto extract audio instantly without quality loss - Use
-an -c:v copyto strip audio from a video - Use
-mapto pick which streams come from which input when replacing audio - The
volumefilter adjusts loudness;loudnormnormalizes across clips - Use
amixwith volume controls to layer music under speech
Run this audio extraction via API. No install
Once your file is uploaded, one call kicks off the job. No local FFmpeg, no servers to run.
curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
-H "Authorization: Bearer $FFMPEG_MICRO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"inputs":[{"url":"gs://your-bucket/input.mp4"}],"outputFormat":"mp4"}'See the full flow in the quickstart.