Lesson 4 of 9

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 key

How 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:a sets the audio codec
  • -an removes all audio streams
  • -vn removes all video streams (audio-only output)
  • -af applies audio filters (like -vf for video)
  • -map selects 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:

ffmpeg -i input.mp4 -vn -c:a copy audio.aac

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

ffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 192k audio.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)

ffmpeg -i input.mp4 -vn audio.wav

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:

ffmpeg -i input.mp4 -an -c:v copy silent.mp4

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:

ffmpeg -i video.mp4 -i new-audio.mp3 -map 0:v -map 1:a -c:v copy -c:a aac -shortest output.mp4

Breaking it down:

  • -map 0:v takes the video stream from the first input (video.mp4)
  • -map 1:a takes the audio stream from the second input (new-audio.mp3)
  • -shortest stops 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

ffmpeg -i input.mp4 -af "volume=2.0" -c:v copy output.mp4

Halve the volume

ffmpeg -i input.mp4 -af "volume=0.5" -c:v copy output.mp4

Set volume in decibels

# Boost by 10dB ffmpeg -i input.mp4 -af "volume=10dB" -c:v copy output.mp4 # Reduce by 5dB ffmpeg -i input.mp4 -af "volume=-5dB" -c:v copy output.mp4

Normalize loudness

If you are stitching clips from different sources, their volumes will be inconsistent. The loudnorm filter normalizes them to broadcast standards:

ffmpeg -i input.mp4 -af "loudnorm=I=-16:TP=-1.5:LRA=11" -c:v copy output.mp4

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:

ffmpeg -i video.mp4 -i music.mp3 \ -filter_complex "[0:a]volume=1.0[voice];[1:a]volume=0.3[music];[voice][music]amix=inputs=2:duration=first[out]" \ -map 0:v -map "[out]" -c:v copy -c:a aac output.mp4

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

CodecFFmpeg EncoderBest For
AACaacMP4 video (default), streaming
MP3libmp3lameAudio-only files, universal compatibility
OpuslibopusWebM video, voice calls, best quality per bit
FLACflacLossless archiving

Key Takeaways

  • Use -vn -c:a copy to extract audio instantly without quality loss
  • Use -an -c:v copy to strip audio from a video
  • Use -map to pick which streams come from which input when replacing audio
  • The volume filter adjusts loudness; loudnorm normalizes across clips
  • Use amix with 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.