CH02 / Formats & streaming

Extracting audio from video: Opus, AAC, MP3 without quality loss

Last updated Editorial team Video Downloader Info9 segments~5 min

Key takeaways

  1. 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.
  2. 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.
  3. Opus is an open, royalty-free codec standardised by the IETF in RFC 6716 and is very efficient for both speech and music.
  4. With yt-dlp, -x extracts audio and --audio-format best (the default) keeps the original codec without re-encoding.
  5. Converting a lossy file to FLAC or WAV makes it bigger without improving it; lossless formats only make sense when the source is lossless.
Pair of headphones lying on a desk
Image: Headphones on desk,Lirazelf,CC BY-SA 3.0,via Wikimedia Commons.

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
  • -vn drops the video.
  • -c:a copy copies the audio stream without decoding it.
  • -map 0:a:1 selects the second audio stream of the input (counting from 0).
  • .mka is 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

  1. Identify the codec with ffprobe.
  2. Extract with -c:a copy into the matching container.
  3. Keep the original audio file as your master.
  4. Convert only for a specific device, always from the master.
  5. 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

ToolLicence
FFmpegLGPL 2.1+ (some builds GPL)
yt-dlpUnlicense (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

  1. RFC 6716: Definition of the Opus Audio Codec · IETF / RFC Editor
  2. Opus codec official site · Xiph.Org Foundation
  3. FFmpeg wiki: Guidelines for high quality lossy audio encoding · FFmpeg wiki
  4. yt-dlp README: post-processing options · yt-dlp project
  5. FLAC: Free Lossless Audio Codec · Xiph.Org Foundation