TechEarl

How to Download YouTube Audio (M4A, MP3, or Opus) with yt-dlp

Download YouTube audio free with yt-dlp: extract to M4A or Opus with no quality-losing re-encode, tag it with cover art, or convert YouTube to MP3 for older players. The free, maintained youtube-dl successor.

Ishan Karunaratne⏱️ 9 min readUpdated
Share thisCopied
Download YouTube audio free with yt-dlp: extract to M4A or Opus with no re-encode, embed cover art and metadata, or convert YouTube to MP3 for legacy players.

The fast, free way to download YouTube audio in 2026 is yt-dlp, a free, open-source command-line downloader. Paste a URL below, leave the type on Audio, pick a format, and copy the command:

Build your yt-dlp command

Paste a YouTube URL, choose what to grab, and copy the command. It updates as you change the options.

Profile / bulk options
Your command
bash
yt-dlp -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format m4a --audio-quality 0 --embed-thumbnail --embed-metadata "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
AI CLI prompt

Paste this into your terminal AI and it runs the command for you, installing the tool first if you do not have it. Works with Claude Code, OpenAI Codex CLI, Gemini CLI, GitHub Copilot CLI, Aider, Cursor Agent, Warp, OpenCode, Cline and any other CLI coding agent.

prompt
Goal: download the audio from this YouTube link.

Run this command in my shell:

    yt-dlp -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format m4a --audio-quality 0 --embed-thumbnail --embed-metadata "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

First check whether `yt-dlp` is installed (run `command -v yt-dlp`). If it is not, install it with my system's package manager before running anything: macOS `brew install yt-dlp ffmpeg`, Debian/Ubuntu `sudo apt install yt-dlp ffmpeg`, Fedora `sudo dnf install yt-dlp ffmpeg`, Windows `winget install yt-dlp ffmpeg`. Then run the command above.

Show me any command that needs sudo before you run it, tell me where the output file landed when you are done, and do not run anything else.

You run this at your own risk. An AI agent can execute commands on your machine; review what it does before approving. TechEarl is not liable for the outcome, see the Terms of Service.

The one decision that matters: what format. The modern default is M4A (the AAC track YouTube serves) or Opus (the other native stream), because each can be saved with no re-encode as long as you ask for the format YouTube actually sent, so you keep the original quality exactly. MP3 is here too, because "youtube to mp3" is still what a lot of people search for, but it forces a lossy re-encode and should be reserved for a device that genuinely cannot play anything else. The rest of this page is the detail: what -x does, the one selector that decides whether you copy or re-encode, why ffmpeg is the part that trips people up, and how to tag the file properly.

If you have used youtube-dl before, yt-dlp is its actively maintained successor. youtube-dl (originally written by Ricardo García, "rg3") still exists but is effectively unmaintained and breaks whenever YouTube changes its player; yt-dlp is the community fork that keeps up. Every youtube-dl audio command below works as yt-dlp with better results.

Download only audio you have the right to. Saving your own uploads, Creative Commons tracks, podcasts, or material the rights holder permits is fine; ripping copyrighted music to redistribute is not, and bulk downloading can violate YouTube's Terms of Service. This guide is for the legitimate cases. What you do with the file is on you.

Install yt-dlp (and ffmpeg, the part that actually matters here)

For audio, ffmpeg is not optional: yt-dlp shells out to it for every extraction and every format conversion. The single most common "audio download failed" report is a missing ffmpeg, not a yt-dlp bug.

Try it with your own values

Pick your OS for the install command.

bash· Linux (GNU)
# Cross-platform and always current:
pipx install yt-dlp
sudo apt install ffmpeg   # or your distro's package manager

YouTube changes often enough that a stale yt-dlp simply stops working, so keep it current: yt-dlp -U for the standalone binary, pipx upgrade yt-dlp for the pipx install, brew upgrade yt-dlp on macOS. When an extraction suddenly fails, updating is the first thing to try.

-x (short for --extract-audio) tells yt-dlp to pull only the audio track and throw the video away. Here is what to actually run, best option first.

bash
# Recommended: M4A/AAC, no re-encode, best quality
yt-dlp -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format m4a "URL"

This is the one to reach for. The detail that almost every tutorial skips: --audio-format only sets the conversion target, it does not pick which stream gets downloaded. Left to itself, yt-dlp's bestaudio usually grabs YouTube's Opus stream (it ranks Opus above AAC), and then ffmpeg has to re-encode Opus into AAC to satisfy m4a, which is a lossy conversion you did not want. The -f "bestaudio[ext=m4a]/bestaudio" selector fixes that: it asks for the AAC-in-M4A stream first, so yt-dlp copies it verbatim (acodec copy, no transcode), and only falls back to whatever audio exists if a particular video has no m4a track. When the source already is M4A, yt-dlp logs "Not converting audio ... already is in target format" and nothing is degraded.

bash
# Tagged file with cover art + metadata
yt-dlp -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format m4a --embed-thumbnail --embed-metadata "URL"

For a music library, this is the version you want: --embed-thumbnail writes the video thumbnail in as cover art and --embed-metadata fills in title, artist, and the rest of the tags from YouTube's data, so the file shows up correctly in your player. One thing tags will not fix is wildly different playback levels between tracks pulled from different sources, so if your library plays back uneven, normalizing the audio volume from the command line with ffmpeg's loudnorm filter evens it out.

bash
# Opus (smallest for the quality)
yt-dlp -f "bestaudio[ext=webm]/bestaudio" -x --audio-format opus "URL"

Opus is the other native YouTube format and gives you the smallest file at a given quality. YouTube ships Opus inside a WebM container, so selecting bestaudio[ext=webm] hands yt-dlp the Opus stream it can copy without re-encoding. Use it when storage or bandwidth matters and every device you care about supports it (modern phones, browsers, and most desktop players do).

bash
# MP3 only if a device demands it (this re-encodes, losing a little quality)
yt-dlp -x --audio-format mp3 --audio-quality 0 "URL"

This is the legacy path. YouTube does not serve MP3, so yt-dlp has to re-encode from the already-lossy AAC or Opus source, which means a second round of lossy compression. The drop is small at --audio-quality 0, but it is real, so only do this for an old car stereo, a basic MP3 player, or some other device that truly cannot handle M4A or Opus. For everything else, M4A is the better "youtube to mp3" answer.

A whole playlist, or a long mix split by track

Point the same command at a playlist URL and yt-dlp walks every entry:

bash
# A whole playlist to audio
yt-dlp -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format m4a "PLAYLIST_URL"

For a long DJ set, podcast, or compilation that has YouTube chapters, --split-chapters cuts it into one file per chapter instead of a single giant file:

bash
# Long DJ mix / podcast split by chapters
yt-dlp -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format m4a --split-chapters "URL"

For the full bulk workflow (an archive file so re-runs skip what you already grabbed, output templates, rate limiting), see download a YouTube playlist or channel.

Convert YouTube to Opus

To get Opus from YouTube with no quality loss, remux the native stream instead of converting it: yt-dlp -f "bestaudio[ext=webm]/bestaudio" --remux-video opus "URL". Opus is already YouTube's native audio codec, served inside a WebM container, so bestaudio[ext=webm] grabs that exact stream and --remux-video opus just drops it into an Opus container. Remuxing changes the container, not the audio, so the result is bit-for-bit the audio YouTube sent at the smallest size for its quality.

bash
# YouTube to Opus, native stream copied into an .opus container (no re-encode)
yt-dlp -f "bestaudio[ext=webm]/bestaudio" --remux-video opus "URL"

The command you will see most often is -x --audio-format opus, and it also produces an .opus file:

bash
# Also works, but --audio-format is a conversion step
yt-dlp -f "bestaudio[ext=webm]/bestaudio" -x --audio-format opus "URL"

The difference is that --audio-format runs ffmpeg's audio-conversion postprocessor, so it can re-encode rather than copy, which is a lossy step you do not need when the source is already Opus. That is why I reach for --remux-video opus when the stream is native Opus, and keep --audio-format for the case where a video has no Opus stream (some older or audio-restricted uploads ship only AAC) and you genuinely want to transcode. Add --embed-thumbnail --embed-metadata to either command for cover art and tags in the .opus file.

Why M4A/Opus beats MP3 here

The short version: you cannot add quality back, so do not throw any away. YouTube's source audio is already lossy AAC or Opus. When you ask for the format that matches the stream (the bestaudio[ext=m4a] / bestaudio[ext=webm] selectors above), yt-dlp copies that stream verbatim, so the output is bit-for-bit the audio YouTube sent. Converting to MP3 decodes that lossy audio and re-encodes it with a different lossy codec, stacking a second generation of loss on top of the first. The difference is usually subtle, but it is never an improvement, and the MP3 file is typically larger than the Opus one at comparable quality. MP3's only remaining advantage is universal playback on very old hardware. That is the whole case for it, and it is why this article is audio-first, not mp3-first.

FAQ

Yes. yt-dlp is free and open source (released into the public domain under the Unlicense), with no ads, no paywall, no watermark, and no limits. Unlike the "free YouTube to MP3" websites that wrap a tool like this in ads and trackers, yt-dlp runs entirely on your own machine and costs nothing.

Run yt-dlp -x --audio-format mp3 --audio-quality 0 "URL". Note that YouTube does not serve MP3, so this re-encodes from a lossy source and loses a little quality. For the best result, extract to m4a or opus instead and only fall back to MP3 for a device that cannot play those.

M4A. YouTube serves AAC audio in an M4A container, so selecting that stream with -f "bestaudio[ext=m4a]/bestaudio" and extracting to m4a copies it with no re-encode and keeps the original quality. (Plain --audio-format m4a can still re-encode, because yt-dlp's default often downloads the Opus stream and converts it.) MP3 forces a second lossy conversion no matter what. Choose MP3 only when a specific old device demands it.

Yes. yt-dlp uses ffmpeg to extract the audio track and to convert formats. Without ffmpeg installed, -x and every --audio-format conversion fail. A missing ffmpeg is the number one cause of "audio download not working."

Add --embed-thumbnail --embed-metadata: yt-dlp -x --audio-format m4a --embed-thumbnail --embed-metadata "URL". That writes the thumbnail in as cover art and fills the title/artist/date tags from YouTube's metadata, so the track displays correctly in your player.

yt-dlp. It is the maintained fork of youtube-dl (originally by Ricardo García) and keeps working when YouTube changes its player. The audio flags are identical, so any youtube-dl -x command runs as yt-dlp.

See also

Sources

Authoritative references this article was fact-checked against.

Tagsyt-dlpYouTubeyoutube-dlyoutube to mp3m4aopusCLIffmpeg

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Software Systems Architect · Senior Software Engineer · Engineering Leadership

Software systems architect and senior software engineer with more than two decades designing, building, and running production software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Now a CTO, though what I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts

Download a Facebook video from the command line with yt-dlp: public watch and fb.watch links work without cookies, private and group videos use Firefox cookies, and you choose the resolution.

How to Download a Facebook Video with yt-dlp

Download a Facebook video free from the command line with yt-dlp: public watch links and fb.watch shorts need no cookies, private and group videos use --cookies-from-browser firefox, and you pick the resolution yourself.

Download an Instagram Reel or video from the command line with yt-dlp using browser cookies, covering reels, feed videos, IGTV, and audio-only.

How to Download an Instagram Reel or Video with yt-dlp

Download an Instagram Reel or video free from the command line with yt-dlp. Instagram needs you logged in, so cookies are mandatory: how to pass them, keep them fresh, and grab reels, feed videos, IGTV, or just the audio.