Originally published at ffmpeg-micro.com
You recorded a webinar, a YouTube video, or a product demo. Now you need the audio track as a standalone file. Maybe you're repurposing video content as podcast episodes. Maybe your app needs to strip audio from user uploads for transcription. FFmpeg handles this in a single command, but getting the codec and container options right takes some trial and error.
How to Extract Audio from Video with FFmpeg
The core command is simple. The -vn flag tells FFmpeg to drop the video stream, and you specify the output format through the file extension or codec flag.
ffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 192k output.mp3
This extracts the audio from input.mp4, re-encodes it as MP3 at 192 kbps, and writes output.mp3. The -c:a libmp3lame flag selects the LAME MP3 encoder, and -b:a 192k sets a bitrate that balances quality and file size.
If you just need the raw audio without re-encoding, use -c:a copy to stream-copy the existing audio codec:
ffmpeg -i input.mp4 -vn -c:a copy output.aac
Stream copying is faster because FFmpeg skips the decode/encode cycle entirely. But the output container must support whatever codec the source video uses. An MP4 with AAC audio can stream-copy to .aac or .m4a, but not directly to .mp3.
Extract Audio as WAV (Uncompressed)
WAV is the go-to when you need lossless audio for editing, transcription pipelines, or feeding into speech-to-text models like Whisper.
ffmpeg -i input.mp4 -vn -acodec pcm_s16le output.wav
The pcm_s16le codec produces 16-bit signed PCM, which is what most audio tools expect. WAV files are large. A 5-minute video produces roughly 50 MB of uncompressed audio. If storage matters, use FLAC instead for lossless compression at about half the size:
ffmpeg -i input.mp4 -vn -c:a flac output.flac
Convert Video to MP3 with Custom Quality
MP3 is still the most universal audio format. For podcasts and general distribution, 128-192 kbps covers most use cases. For music or high-fidelity content, bump it to 320 kbps:
ffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 320k output.mp3
You can also use FFmpeg's variable bitrate mode with -q:a instead of -b:a. Lower values mean higher quality:
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3
A -q:a value of 2 averages around 190 kbps and produces better quality than a fixed 192k bitrate at roughly the same file size.
Common Gotchas When Extracting Audio
Container vs. codec mismatch. The most common error is trying to stream-copy audio into an incompatible container. If your source has Opus audio and you try -c:a copy output.mp3, FFmpeg will fail. Either re-encode or pick a container that supports the source codec (.ogg or .webm for Opus).
No audio stream. Some screen recordings and generated videos don't have an audio track at all. FFmpeg will error with "Output file does not contain any stream." Check first with ffprobe:
ffprobe -v quiet -show_streams -select_streams a input.mp4
If this returns nothing, the video has no audio to extract.
Sample rate mismatches. When feeding extracted audio into pipelines that expect a specific sample rate (like 16kHz for Whisper), set it explicitly:
ffmpeg -i input.mp4 -vn -c:a libmp3lame -ar 16000 -ac 1 -b:a 64k output.mp3
The -ar 16000 flag resamples to 16kHz, and -ac 1 downmixes to mono.
Extract Audio via API (No FFmpeg Installation)
All those CLI commands work great on your local machine. But if you're building an app that needs to extract audio from user uploads, or automating extraction across hundreds of videos, you don't want to install FFmpeg on a server and manage the infrastructure.
FFmpeg Micro is a cloud API that handles this with a single HTTP request. Send the video URL and your desired output format:
curl -X POST "https://www.ffmpeg-micro.com/v1/transcodes" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"inputs": [{"url": "https://example.com/video.mp4"}],
"outputFormat": "mp3",
"options": [
{"option": "-vn", "argument": ""},
{"option": "-b:a", "argument": "192k"}
]
}'
The API queues the job, processes it in the cloud, and gives you a download URL when it's done. No FFmpeg binary to install. No server to scale. No codec dependencies to manage.
Top comments (0)