Extracting audio from video: Opus, AAC, MP3 without quality loss
Key takeaways
- Most online video carries its sound as AAC or Opus; extracting that stream as it is, with FFmpeg's -c:a copy, is instant and loses no quality.
- Converting to MP3 is a second lossy encode: it can only keep or lose detail, never add any back, so do it only when a device really needs MP3.
- Opus is an open, royalty-free codec standardised by the IETF in RFC 6716 and is very efficient for both speech and music.
- With yt-dlp, -x extracts audio and --audio-format best (the default) keeps the original codec without re-encoding.
- Converting a lossy file to FLAC or WAV makes it bigger without improving it; lossless formats only make sense when the source is lossless.

To extract audio from a video without losing quality, copy the audio stream as it is instead of converting it. Online video almost always carries its sound as AAC or Opus. FFmpeg’s -c:a copy or yt-dlp’s -x put that stream into an audio-only file in seconds, bit for bit. Converting to MP3 is a second lossy encode: useful for old devices, never an improvement. This guide shows how to identify the codec, extract it cleanly and convert only when you must.
Use these methods on your own recordings, public-domain or openly licensed works, or content you have permission to keep (see is downloading videos legal?).
Which audio codecs are inside online video?
| Codec | Standard | Licence situation | Usual container for audio-only file | Notes |
|---|---|---|---|---|
| AAC | ISO/IEC MPEG-2 / MPEG-4 Audio | Patent licensing applies to products | .m4a |
Default in MP4 and HLS |
| Opus | IETF RFC 6716 (2012) | Royalty-free | .opus (Ogg) or .mka |
Default in WebM; very efficient for speech and music |
| Vorbis | Xiph.Org | Royalty-free | .ogg |
Older WebM files |
| MP3 | ISO/IEC MPEG-1/2 Audio Layer III | Patents expired | .mp3 |
Universal compatibility, less efficient |
| FLAC | Xiph.Org | Royalty-free, lossless | .flac |
Rare in streaming; for lossless sources |
The Opus RFC defines bitrates from 6 kbit/s to 510 kbit/s, which explains its flexibility: the same codec handles phone-quality speech and high-quality stereo music.
How do I find out which audio codec a video uses?
ffprobe -v error -select_streams a \
-show_entries stream=index,codec_name,sample_rate,channels,bit_rate:stream_tags=language \
-of compact video.mkv
The codec_name field (aac, opus, vorbis, mp3) decides the right file extension for a lossless extraction. A video may have several audio streams (languages, commentary); the index and language fields tell them apart.
How do I extract audio losslessly with FFmpeg?
Pick the extension that matches the codec, and copy:
# AAC audio from an MP4
ffmpeg -i video.mp4 -vn -c:a copy audio.m4a
# Opus audio from a WebM or MKV
ffmpeg -i video.webm -vn -c:a copy audio.opus
# Second audio stream only (for example the French track)
ffmpeg -i video.mkv -map 0:a:1 -c:a copy audio_fr.mka
-vndrops the video.-c:a copycopies the audio stream without decoding it.-map 0:a:1selects the second audio stream of the input (counting from 0)..mkais Matroska’s audio-only container: it accepts any codec, which makes it a safe fallback.
If FFmpeg reports that the codec is not supported in the chosen container, the extension does not match the codec: check ffprobe and change it. More on wrappers in MP4 vs MKV vs WebM.
How do I download audio only with yt-dlp?
# Best audio stream, kept in its original codec
yt-dlp -x URL
# Same, but download only the audio stream in the first place
yt-dlp -f "ba" -x URL
# MP3 for an old player (this re-encodes)
yt-dlp -x --audio-format mp3 --audio-quality 0 URL
-x (--extract-audio) runs FFmpeg after the download. With the default --audio-format best, the original codec is kept. --audio-quality 0 asks for the best variable-bitrate setting when a re-encode is unavoidable. Add --embed-metadata and --embed-thumbnail to keep the title and cover art. The full option set is in our yt-dlp guide.
When should I convert to MP3, AAC or FLAC?
- MP3: only for players or workflows that accept nothing else. Since its patents expired, MP3 is free to use, but it needs more bitrate than AAC or Opus for the same result.
- AAC (.m4a): for Apple devices and older phones that do not play Opus.
- FLAC or WAV: only for lossless sources, or as an intermediate format for audio editing. Converting a lossy AAC or Opus stream to FLAC preserves the existing losses in a much bigger file.
Every lossy-to-lossy conversion (“transcoding”) stacks artefacts. If you need several formats, always convert from the best original, never from a previous conversion.
# Opus to AAC for an Apple device, from the original
ffmpeg -i audio.opus -c:a aac -b:a 192k audio.m4a
The FFmpeg wiki’s high-quality audio guide lists encoder-specific recommendations; it is the reference to follow when choosing a bitrate.
How do I clean up audio for listening or a podcast?
Loudness normalisation, noise reduction and trimming all require decoding and re-encoding, so do them once, at the end:
# EBU R128 loudness normalisation, single pass
ffmpeg -i talk.m4a -af loudnorm -c:a aac -b:a 160k talk_normalised.m4a
The loudnorm filter implements EBU R128 loudness normalisation. For editing by ear, Audacity (open source) opens the extracted file directly. This is a common workflow for lectures you study offline or for turning your own webinar into a podcast episode.
What goes wrong when extracting audio, and how do I fix it?
| Symptom | Cause | Fix |
|---|---|---|
| The file will not play in a car or older player | Opus in .opus or .webm is not supported by that device |
Convert once to AAC: ffmpeg -i in.opus -c:a aac -b:a 192k out.m4a |
| “Codec not currently supported in container” | The stream was copied into a container that cannot hold it, such as Opus into .mp3 |
Use a matching extension: .opus or .ogg for Opus, .m4a for AAC |
| Very quiet recording | The source was mastered quietly, common with lectures and talks | Normalise loudness: ffmpeg -i in.m4a -af loudnorm -c:a aac -b:a 160k out.m4a |
| Long file with no way to navigate | A whole concert or course in one track | Split it on the uploader’s chapters with yt-dlp -x --split-chapters URL |
Which format should I keep for each use?
| Use | Recommended | Why |
|---|---|---|
| Archive of the original | The codec the site delivered (often Opus or AAC), stream-copied | No generation loss, smallest file for the quality |
| Phone and podcast apps | AAC in .m4a |
Plays almost everywhere, efficient at moderate bitrates |
| Very old hardware | MP3 | Universal support; accept a small quality loss from conversion |
| Editing in an audio workstation | WAV or FLAC decoded from the source | Avoids repeated lossy encoding during edits |
Remember that converting a lossy file to FLAC or WAV does not restore quality: it only makes the file bigger. Convert to an uncompressed format only when an editing tool needs it, and keep the original stream next to it.
Checklist
- Identify the codec with ffprobe.
- Extract with
-c:a copyinto the matching container. - Keep the original audio file as your master.
- Convert only for a specific device, always from the master.
- Never convert lossy audio to FLAC hoping to improve it.
For the video side of the same question, see AV1 vs VP9 vs H.264 vs HEVC.
Open-source tools in this guide
| Tool | Licence |
|---|---|
| FFmpeg | LGPL 2.1+ (some builds GPL) |
| yt-dlp | Unlicense (public domain) |
| Opus (libopus) | BSD-3-Clause |
Frequently asked questions
Is MP3 still worth using?
MP3 is still the most universally playable audio format, and its patents have expired, so it is free to use. But it is less efficient than AAC or Opus. Use it when an old car stereo, player or workflow requires it, and keep the original stream otherwise.
Why does my extracted .m4a file not play in some apps?
Check the codec with ffprobe. An .m4a should contain AAC (or ALAC). If the stream is actually Opus, some apps refuse it in an M4A wrapper; save it as .opus instead, or keep it in MKA, Matroska's audio-only container.
Does yt-dlp -x re-encode the audio?
Not by default. With --audio-format best, which is the default, yt-dlp keeps the codec of the downloaded stream and only changes the container. If you request mp3, aac or another specific format that differs from the source, it re-encodes with FFmpeg.
Can I make a podcast from a recorded talk?
If you own the recording or have the speaker's permission, yes. Extract the audio losslessly, then edit and normalise it in an editor such as Audacity before exporting. Normalising loudness always requires a re-encode, so do it once, at the end.
What bitrate should I choose when I must re-encode?
There is no single answer: it depends on codec, content and listener. The FFmpeg wiki's high-quality audio guide gives recommended ranges for each encoder. As a rule, never encode at a higher bitrate than the source; it only wastes space.
Sources and open data
- RFC 6716: Definition of the Opus Audio Codec · IETF / RFC Editor
- Opus codec official site · Xiph.Org Foundation
- FFmpeg wiki: Guidelines for high quality lossy audio encoding · FFmpeg wiki
- yt-dlp README: post-processing options · yt-dlp project
- FLAC: Free Lossless Audio Codec · Xiph.Org Foundation
Related guides
- AV1 vs VP9 vs H.264
Compare AV1, VP9, H.264 and HEVC for downloaded video: efficiency, compatibility, royalties and archiving, plus how to pick a codec with yt-dlp and FFmpeg.
- MP4 vs MKV vs WebM
Container or codec? What MP4, MKV, WebM and MPEG-TS can hold, which one to keep for a downloaded video, and how to switch containers without quality loss.
- yt-dlp guide
A practical yt-dlp guide: install and update it safely, pick formats with -f and -S, name files, grab subtitles and keep a download archive.
- FFmpeg for video files
FFmpeg commands for downloaded video: merge separate audio and video, remux TS to MP4 without quality loss, cut clips, join parts and convert only when needed.
- Lectures offline
Watch university lectures offline legally: MIT OpenCourseWare course packages, CC BY-NC-SA rules, official video downloads and a tidy offline library.