/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:
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.mp4Output
h264,video aac,audio
Extract without re-encoding
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.m4aOutput
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
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.mp3Output
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
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
Related pages
compare · ffmpegffmpeg -c copy vs re-encoding: speed, quality and limits-c copy remuxes streams without decoding: fast and lossless, but cuts snap to keyframes and filters are impossible. Re-encoding is slower, lossy, flexible.cheat sheets · ffmpegFFmpeg cheat sheet: convert, cut, scale, extract and inspectFFmpeg cheat sheet: inspect files with ffprobe, change containers, encode H.264, cut without re-encoding, scale, extract audio, make GIFs and thumbnails.compat · ffmpegWhich codec in which container? MP4, WebM, MKV, MOV with FFmpegCodec and container compatibility tested with FFmpeg 9: H.264 and AAC fit MP4 and MKV but not WebM, which accepts only VP8, VP9, AV1, Vorbis and Opus.