Skip to content

/commands/ffmpeg/ffmpeg-extract-audio

ffmpeg: extract audio from a video (with and without re-encoding)

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · ffmpeg version 9.0.2-full_build-www.gyan.devupdated 2026-10-20
tool
FFmpeg
versions
FFmpeg 4 – 9
os
linux, macos, windows

ffmpeg -i input.mp4 -vn -c:a copy audio.m4a extracts the audio track without re-encoding: -vn drops the video and -c:a copy copies the audio bytes as they are, which is fast and lossless. To get an MP3, re-encode with -c:a libmp3lame.

Make a sample video

The examples use a generated 2-second clip with a 440 Hz tone, so they run anywhere:

bash
ffmpeg -hide_banner -loglevel error -f lavfi -i testsrc=size=320x240:duration=2 -f lavfi -i sine=frequency=440:duration=2 \
  -c:v libx264 -pix_fmt yuv420p -c:a aac -shortest -y input.mp4
ffprobe -v error -show_entries stream=codec_type,codec_name -of csv=p=0 input.mp4

Output

h264,video
aac,audio

Extract without re-encoding

bash
ffmpeg -hide_banner -loglevel error -f lavfi -i testsrc=size=320x240:duration=2 -f lavfi -i sine=frequency=440:duration=2 \
  -c:v libx264 -pix_fmt yuv420p -c:a aac -shortest -y input.mp4
ffmpeg -hide_banner -loglevel error -i input.mp4 -vn -c:a copy -y audio.m4a
ffprobe -v error -show_entries stream=codec_type,codec_name -of csv=p=0 audio.m4a

Output

aac,audio

Pick an extension that matches the codec: AAC goes in .m4a, Opus in .opus or .ogg, MP3 in .mp3. ffprobe input.mp4 tells you which codec the file has.

Convert to MP3

bash
ffmpeg -hide_banner -loglevel error -f lavfi -i sine=frequency=440:duration=2 -c:a aac -y input.m4a
ffmpeg -hide_banner -loglevel error -i input.m4a -vn -c:a libmp3lame -q:a 2 -y audio.mp3
ffprobe -v error -show_entries stream=codec_name,sample_rate -of csv=p=0 audio.mp3

Output

mp3,44100

-q:a 2 selects LAME's variable bitrate preset of roughly 170–210 kbit/s; use -b:a 192k for a constant bitrate.

Extract one of several audio tracks

bash
ffmpeg -i movie.mkv -map 0:a:1 -c copy second-track.mka

-map 0:a:1 selects the second audio stream of the first input (counting from 0).

Sources