Extract Audio with yt-dlp: MP3, M4A and Lossless Copies
Quick answer
Ripping to MP3 re-encodes audio that was already compressed once, so it is bigger and slightly worse than the original. Unless a specific device demands MP3, keep what YouTube already has:
yt-dlp -x --audio-format m4a --embed-thumbnail --embed-metadata "URL"
yt-dlp -x --audio-format mp3 --audio-quality 0 --embed-thumbnail --embed-metadata "URL"
Why m4a beats mp3 here
YouTube stores audio as AAC (in m4a) or Opus, both around 128 kbps. Those are already lossy. Converting to MP3 means decoding lossy audio and re-encoding it lossily — a second generation of loss, for a file two to three times the size.
Asking for 320 kbps does not recover anything. There is no additional detail in the source to capture; the bitrate just describes how much space is spent storing the same audio. The number is bigger, the file is bigger, the sound is not better.
| Format | Re-encodes? | Use when |
|---|---|---|
| m4a | No | Default. Plays on Apple devices, Android, everything modern |
| opus | No | Smallest; not read by older hardware |
| best | No | Whatever the source is — fastest, least lossy |
| mp3 | Yes | Car stereos, DJ software, legacy hardware |
| flac | Yes | Never, for this source — see below |
| wav | Yes | Feeding another tool that wants uncompressed input |
Keeping whatever is best
--audio-format best tells yt-dlp not to convert at all. Fastest, and lossless in
the only sense available here:
yt-dlp -x --audio-format best --embed-thumbnail --embed-metadata "URL"
You get .opus or .m4a depending on what the site served. If mixed
extensions in one folder bother you, ask for m4a specifically — YouTube's AAC is m4a already, so
nothing is re-encoded.
Metadata and cover art
Without these, you get a file called Some Track (Official Video) with no tags, which no music player will organise:
yt-dlp -x --audio-format m4a \
--embed-thumbnail \
--embed-metadata \
--convert-thumbnails jpg \
-o "%(artist,uploader)s/%(track,title)s.%(ext)s" \
"URL"
--convert-thumbnails jpg is there because YouTube serves WebP, and neither mp3 nor
m4a will embed it — the symptom is
ffmpeg exited with code 1 during
postprocessing, which reads as a much bigger problem than it is.
Turning a title into real tags
Music uploads usually put the artist in the title: Artist - Track (Official Video).
--parse-metadata splits that into fields a player understands:
yt-dlp -x --audio-format m4a \
--parse-metadata "%(title)s:%(artist)s - %(title)s" \
--embed-metadata --embed-thumbnail \
-o "%(artist)s/%(title)s.%(ext)s" \
"URL"
For a YouTube Music album, the fields are usually already correct and this is unnecessary — check
with --dump-json before adding rules that fight good metadata.
Albums and podcasts
yt-dlp -x --audio-format m4a \
--embed-thumbnail --embed-metadata \
-o "%(playlist)s/%(playlist_index)02d - %(title)s.%(ext)s" \
"ALBUM_PLAYLIST_URL"
yt-dlp -x --audio-format m4a \
--download-archive podcast.txt \
--embed-metadata --embed-chapters \
-o "%(uploader)s/%(upload_date>%Y-%m-%d)s - %(title)s.%(ext)s" \
"CHANNEL_URL"
--embed-chapters is worth having on podcasts specifically: it turns YouTube's
chapter markers into seekable positions in the audio file.
Keeping the video too
By default -x deletes the source once extraction succeeds:
yt-dlp -x --audio-format m4a --keep-video "URL"
Also useful as insurance while testing a postprocessing chain — if it fails, you still have the download and can retry without fetching it again.
A config for music
Worth keeping separate from your main config, and selecting per job:
-x
--audio-format m4a
--audio-quality 0
--embed-thumbnail
--embed-metadata
--convert-thumbnails jpg
--no-playlist
-o %(artist,uploader)s/%(album,playlist)s/%(track,title)s.%(ext)s
-P ~/Music/yt-dlp
yt-dlp --config-location ~/.config/yt-dlp/music.conf "URL"
If it fails
- ffmpeg not found. Extraction is entirely ffmpeg's work — install it.
-
"Unknown encoder libmp3lame" on Linux. A minimal ffmpeg build.
sudo apt install libavcodec-extra. -
No cover art in the file. Add
--convert-thumbnails jpg. -
Tags missing in one player, present in another. Some players read only
ID3v2.3.
--postprocessor-args "-id3v2_version 3"writes the older revision.
Frequently asked
Is 320 kbps MP3 better than the original?
Then why would I ever use MP3?
What does --audio-quality 0 mean?
Why is there no cover art in my file?
Related
- Install ffmpeg for yt-dlp on Windows, macOS and Linux Without ffmpeg yt-dlp is capped at whatever single file a site offers — usually 360p. How to install it on eac...
- Fix "Postprocessing: ffmpeg exited with code 1" in yt-dlp The download finished and the conversion failed — so the fix is never in yt-dlp's flags. How to read the ffmpe...
- yt-dlp Output Templates: Name and Sort Files Automatically The -o template turns a folder of random filenames into a library. Every field worth using, the numeric and da...