Skip to content

Notes

Get the audio out of a YouTube video without re-encoding it

YouTube already stores the audio as AAC. Extracting it is instant and lossless; converting it to MP3 is slower and worse. The distinction almost nobody makes, and the commands for both.

Almost every guide to getting audio out of a YouTube video tells you to convert it to MP3. That advice makes the file worse, takes longer, and is almost never necessary.

Here is the distinction that everything else follows from.

YouTube already gives you a finished audio file

A YouTube video is not one file. It is a video stream and a separate audio stream, combined by the player. That audio stream is a normal, complete, standalone audio file — usually AAC in an M4A container, sometimes Opus in WebM.

Run this on any video:

yt-dlp -F "URL"

Among the audio only rows, for a typical video:

139  m4a   audio only   mp4a.40.5    48k
140  m4a   audio only   mp4a.40.2   130k
251  webm  audio only   opus        129k
258  m4a   audio only   mp4a.40.2   388k

Format 140 is the workhorse: AAC, around 130 kbps, what almost everything plays.

So there are two possible operations, and they are not the same:

  • Extract the existing stream. A copy. Instant, and byte-for-byte the audio YouTube stored.
  • Convert it to MP3. Decode the AAC, re-compress as MP3. Slower, and lossy on top of lossy.

Extract — the one you almost always want

yt-dlp -f bestaudio[ext=m4a] "URL"

That is it. No --extract-audio, no --audio-format, no FFmpeg step. You downloaded an audio file and it is already an audio file.

Prove nothing was touched:

ffprobe -v error -show_entries stream=codec_name,bit_rate \
        -of default=nw=1 audio.m4a

The codec and bitrate match the row from -F. That is a copy.

With metadata and cover art, which is what makes it usable in Music:

yt-dlp -f bestaudio[ext=m4a] \
       --embed-thumbnail --embed-metadata \
       -o "%(artist,uploader)s - %(title)s.%(ext)s" \
       "URL"

%(artist,uploader)s takes artist when YouTube provides it — it does on official music uploads — and falls back to the channel name otherwise.

The -x version, and its one trap

yt-dlp -x --audio-format m4a "URL"

-x downloads the best audio and hands it to FFmpeg. With --audio-format m4a against an AAC source, FFmpeg remuxes rather than re-encodes: I checked on 2026-07-31 and the output codec and bitrate were identical to the source.

The trap is that -x picks best audio, which may be Opus in WebM. Then --audio-format m4a has to genuinely re-encode Opus to AAC, and you lose quality without being told. Asking for bestaudio[ext=m4a] avoids the question entirely.

Convert to MP3 — when you actually need to

yt-dlp -x --audio-format mp3 --audio-quality 0 "URL"

--audio-quality 0 is the best VBR setting. Use it; the default is lower and there is no reason to accept that on a re-encode you have already decided to take.

Do this only for a real constraint: a car stereo from 2009, a DJ controller, an old device that lists MP3 and nothing else. Every current phone, computer, TV and speaker plays AAC.

Understand the cost. YouTube’s audio has already been compressed once, lossily. Converting to MP3 compresses the result of that again — generational loss. The artefacts of the first pass become material the second pass must encode, and it spends bits on them. You end up with a bigger file that sounds slightly worse, and a minute of your time per track.

What about Opus?

Opus at 130 kbps is, by most listening tests, better than AAC at the same bitrate. If quality is the only concern and your player handles it:

yt-dlp -f bestaudio[ext=webm] "URL"

The catch is compatibility. Apple Music does not import Opus in WebM, and neither do plenty of car systems and older devices. AAC in M4A plays everywhere on a Mac and on every iPhone, which is why it is the sane default even though it is not the technically best one.

You want Take
Something that just works, everywhere bestaudio[ext=m4a]
Best quality, modern players only bestaudio[ext=webm] (Opus)
A device that only lists MP3 -x --audio-format mp3 --audio-quality 0
To put it in Music bestaudio[ext=m4a] --embed-thumbnail --embed-metadata

A whole album or playlist

yt-dlp -f bestaudio[ext=m4a] \
       --download-archive done.txt \
       -o "%(playlist_index)02d - %(title)s.%(ext)s" \
       --embed-thumbnail --embed-metadata \
       "PLAYLIST_URL"

The archive file is what lets you re-run it later without re-downloading — covered properly in downloading a whole playlist.

Just a section

For a single track inside a two-hour mix, do not download two hours:

yt-dlp -f bestaudio[ext=m4a] --download-sections "*3:40-7:15" "URL"

That fetches roughly the bytes it needs and nothing else. There is a piece on that — it is the single most useful yt-dlp flag most people have never heard of.

Why the app defaults to M4A

The app I build extracts to M4A and offers MP3 as a choice rather than a default, for exactly the reason above: the default should be the operation that does not degrade anything. MP3 is one setting away when a device demands it.

The general rule is worth keeping even without the app: keep the file YouTube gave you, convert a copy if something forces you to. Re-encoding for convenience throws away quality you cannot get back, and it is almost always being done to satisfy a requirement that no longer exists.