Lesson 4 of 7

Extract and Add Audio

Extract audio from video, replace audio tracks, adjust volume, mix streams, and convert between audio formats.

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 — set the audio codec
  • -an — remove all audio streams
  • -vn — remove all video streams (audio-only output)
  • -af — apply audio filters (like -vf for video)
  • -map — select 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.

Removing Audio from Video

Sometimes you need a silent video — 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 — take the video stream from the first input (video.mp4)
  • -map 1:a — take the audio stream from the second input (new-audio.mp3)
  • -shortest — stop when the shorter input ends (so the output does not have trailing silence or video)

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

Try This With FFmpeg Micro

Instead of running FFmpeg locally, you can use FFmpeg Micro's API to process videos in the cloud. No installation required.