Skip to main content

Overview

yt-dlp can extract audio from videos and convert it to your preferred format. This requires ffmpeg and ffprobe to be installed on your system.

Basic Audio Extraction

The simplest way to extract audio is using the -x flag:
yt-dlp -x "https://www.youtube.com/watch?v=BaW_jenozKc"
By default, audio is extracted in the best available format. yt-dlp will choose the optimal format automatically.

Specify Audio Format

1

Choose your format

Select from supported formats: mp3, aac, flac, m4a, opus, vorbis, wav, alac, or best.
2

Extract with format conversion

yt-dlp -x --audio-format mp3 URL
3

Set quality level

# Quality 0 (best) to 10 (worst) for VBR
yt-dlp -x --audio-format mp3 --audio-quality 0 URL

# Or specify bitrate directly
yt-dlp -x --audio-format mp3 --audio-quality 320K URL

Audio Format Examples

# High quality MP3
yt-dlp -x --audio-format mp3 --audio-quality 0 URL

# Standard quality MP3 (192K)
yt-dlp -x --audio-format mp3 --audio-quality 192K URL

# Using preset alias
yt-dlp -t mp3 URL

Advanced Audio Extraction

Extract without re-encoding

If the source already has the desired audio codec, avoid re-encoding to maintain quality:
# Download best audio-only format without conversion
yt-dlp -f 'ba' URL

# Prefer specific codec
yt-dlp -f 'ba[acodec^=opus]/ba[acodec^=mp4a]/ba' URL

Multiple audio quality rules

Convert based on source format:
# Similar to --remux-video syntax
yt-dlp -x --audio-format "opus>mp3/best" URL
This will:
  • Convert opus to mp3
  • Keep other formats in their best available quality

Audio-Only Downloads

Best audio quality

# Best quality from YouTube Music
yt-dlp -f 'ba' "https://music.youtube.com/watch?v=..."

Extract Audio from Playlists

Download and extract audio from entire playlists:
# Extract MP3 from all videos in playlist
yt-dlp -x --audio-format mp3 \
  -o "%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" \
  PLAYLIST_URL

# Skip already downloaded
yt-dlp -x --audio-format mp3 \
  --download-archive downloaded.txt \
  PLAYLIST_URL

Embed Metadata and Artwork

Metadata embedding requires either mutagen (Python package) or ffmpeg to be installed.
1

Basic metadata embedding

yt-dlp -x --audio-format mp3 \
  --embed-metadata \
  --embed-thumbnail \
  URL
2

Custom metadata

# Parse artist from title
yt-dlp -x --audio-format mp3 \
  --parse-metadata "title:%(artist)s - %(title)s" \
  --embed-metadata \
  URL
3

Complete music file

yt-dlp -x --audio-format mp3 --audio-quality 0 \
  --embed-metadata \
  --embed-thumbnail \
  --parse-metadata "%(uploader|)s:%(meta_artist)s" \
  -o "%(artist,uploader)s - %(title)s.%(ext)s" \
  URL

Audio Processing Options

Normalize audio

Use ffmpeg postprocessor arguments:
yt-dlp -x --audio-format mp3 \
  --ppa "ffmpeg:-af loudnorm" \
  URL

Split by chapters

Extract each chapter as separate audio file:
yt-dlp -x --audio-format mp3 \
  --split-chapters \
  -o "chapter:%(title)s - %(section_number)s %(section_title)s.%(ext)s" \
  URL

Remove sponsor segments

Combine with SponsorBlock to remove ads/sponsors:
yt-dlp -x --audio-format mp3 \
  --sponsorblock-remove sponsor,selfpromo \
  URL

Preset Aliases for Audio

yt-dlp includes convenient presets:
# Equivalent to: -f 'ba[acodec^=mp3]/ba/b' -x --audio-format mp3
yt-dlp -t mp3 URL

Organizing Audio Downloads

Music library structure

yt-dlp -x --audio-format mp3 \
  -o "%(uploader)s/%(album,playlist)s/%(track_number)s - %(title)s.%(ext)s" \
  --embed-metadata \
  --embed-thumbnail \
  PLAYLIST_URL

By date

yt-dlp -x --audio-format mp3 \
  -o "%(upload_date>%Y)s/%(upload_date>%m)s/%(title)s.%(ext)s" \
  URL

Python API Example

Extract audio programmatically:
import yt_dlp

URLs = ['https://www.youtube.com/watch?v=BaW_jenozKc']

ydl_opts = {
    'format': 'm4a/bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'm4a',
    }]
}

with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    ydl.download(URLs)

Troubleshooting

ffmpeg not found

Audio extraction requires ffmpeg. Install it from ffmpeg.org or use your package manager.
# Check if ffmpeg is installed
ffmpeg -version

# Specify ffmpeg location if needed
yt-dlp -x --ffmpeg-location /path/to/ffmpeg URL

Quality loss during conversion

# Download best audio without re-encoding
yt-dlp -f 'ba' URL

# If conversion needed, use highest quality
yt-dlp -x --audio-format mp3 --audio-quality 0 URL

Thumbnail not embedding

# Install mutagen for better thumbnail support
pip install mutagen

# Or use AtomicParsley for MP4/M4A
yt-dlp -x --audio-format m4a --embed-thumbnail URL

Next Steps

Post-Processing

Advanced post-processing options

Metadata Modification

Customize metadata in audio files

Playlists

Extract audio from entire playlists

Format Selection

Advanced audio format selection

Build docs developers (and LLMs) love