yt-dlp Audio Only: Download YouTube Audio for Speech Datasets

Written by

in

For ASR, TTS and speech-LLM training you rarely need the video, yet many pipelines still download it, or download audio and then re-encode it to MP3 "for compatibility". This guide covers the yt-dlp audio-only path: how to select the right stream, keep it bit-for-bit, pick the original-language track on videos with dubbed audio, filter before downloading, and do the 16 kHz conversion once, at training time. Flags were checked against the yt-dlp README and source at release 2026.10.26.

TL;DR

  • Use -f ba (bestaudio). It selects audio-only formats. Don't use ba*, which can return a muxed video file.
  • -x with the default --audio-format best doesn't re-encode. YouTube's Opus-in-WebM gets stream-copied to .opus, and M4A stays as it is. Only an explicit target like mp3 triggers a lossy re-encode.
  • On videos with several audio tracks, add -S lang. yt-dlp marks the original track with the highest language preference, but YouTube's default sort only uses it as a tiebreaker after quality and codec.
  • Store the native Opus/M4A. Convert to 16 kHz mono with ffmpeg -ac 1 -ar 16000 when you build training shards, not when you download.
  • Audio is cheap on bandwidth: 100k hours at 160 kbps is 7.2 TB. At that size, request rate limits cost you more time than the link does.

Select the audio stream, not the video

YouTube serves audio and video as separate DASH streams, so you can download just the audio. The yt-dlp format selection docs define ba/bestaudio as "the best quality audio-only format", equivalent to best*[vcodec=none]. ba* means "best format that contains audio" and may include video. The README marks it "Do not use!".

Before you script anything, look at what a video actually offers:

yt-dlp -F 'https://www.youtube.com/watch?v=VIDEO_ID'

The audio-only rows show the codec, bitrate, sample rate (asr) and, on videos that have it, a language in brackets plus track notes such as (original) or (default).

YouTube's audio-only formats

There are two families: Opus in a WebM container and AAC in an M4A (MP4) container. yt-dlp no longer ships a hardcoded itag table. It now reads codec, bitrate and sample rate from YouTube's player response. The last version that had the table (2024.12.23) listed these nominal values:

itag Container Codec Nominal bitrate (old yt-dlp table)
249 webm Opus 50 kbps
250 webm Opus 70 kbps
251 webm Opus 160 kbps
139 m4a AAC 48 kbps
140 m4a AAC 128 kbps

Treat these as labels, not measurements. Opus here is variable-bitrate, so the real average depends on the content and is often below the nominal figure. Which itags exist also varies by video and player client. The current extractor's own test suite marks itag 141 (256 kbps AAC) as "not served anymore". Check -F for real numbers.

Some videos also offer DRC (dynamic range compression) variants, which show up as format IDs like 251-drc with "DRC" in the note. The YouTube extractor ranks them slightly below the regular stream. If you want uncompressed dynamics, exclude them explicitly with -f 'ba[format_id!*=drc]/ba'.

Format sorting for audio (-S)

-S changes what counts as "best". The sorting docs list these audio-relevant fields:

  • acodec: flac/alac > wav/aiff > opus > vorbis > aac > mp4a > mp3 > …
  • abr (average audio bitrate, kbps), asr (sample rate, Hz), channels
  • size (exact or approximate file size)
  • lang: "the language preference as determined by the extractor (e.g. original language preferred over audio description)"

Fields sort descending; a + prefix reverses that. Your -S fields are placed ahead of the extractor's order. That matters on YouTube, whose extractor sets its own order (quality, res, fps, hdr:12, source, vcodec, channels, acodec, lang, proto), so lang normally comes near the end. Useful combinations:

  • -f ba -S lang: original track first, then the usual quality order.
  • -f 'ba[asr>=16000]' -S lang,+size: the smallest audio-only file that still has at least a 16 kHz sample rate. This makes sense if you're storage-bound and only train at 16 kHz. Measure WER on a sample before committing to it.
  • -f 'ba[ext=m4a]/ba': prefer AAC/M4A, for example if your decoder stack handles MP4 more easily than WebM/Ogg.

Dubbed and multi-language audio tracks

YouTube can attach several audio tracks to one video: the original, AI or human dubs, and audio description. For a speech dataset, a dub labeled with the original video's metadata is a data-quality bug. From the extractor source, this is how yt-dlp exposes them:

  • Each audio format's language is the part of YouTube's audio track ID before the dot.
  • A track whose display name contains "original" gets language_preference 10 and an (original) note. The default track gets 5, audio-description tracks get −10 with a language like en-desc, and all others get −1.
  • On single-track videos, yt-dlp fills language on audio formats from the original-language auto-caption track when one exists. Without one, language can be empty.

So -S lang picks the original track whenever YouTube labels it. To require a specific language, use a format filter. String filters support ^=, $=, *=, ~= and negation with !:

# English audio, but never the audio-description track
yt-dlp -f 'ba[language^=en][language!$=desc]' -S lang URL

If no format matches, that video fails with "Requested format is not available". yt-dlp then moves on to the next URL, because --no-abort-on-error is the default. Append /ba only if you'd rather get some audio than none. A format filter also excludes formats whose language is unknown, unless you write it as language^=?en.

-x, --audio-format and why not MP3

-x/--extract-audio needs ffmpeg and ffprobe. --audio-format accepts best (default), aac, alac, flac, m4a, mp3, opus, vorbis and wav. Here is what the FFmpegExtractAudioPP source actually does:

  • best + .m4a: does nothing ("already in a common audio format").
  • best + .webm: ffprobe reports Opus, so ffmpeg runs with -acodec copy into a .opus file. It's lossless and quick.
  • A different target (e.g. mp3): a full decode and re-encode with libmp3lame.

Re-encoding Opus or AAC to MP3 stacks one lossy codec on top of another. Quality can only go down, and you pay CPU for every hour of audio. --audio-quality (0 best to 10 worst for VBR, or a bitrate like 128K; default 5) only matters when a re-encode happens. The built-in preset -t mp3 expands to -f 'ba[acodec^=mp3]/ba/b' -x --audio-format mp3. That suits a music player, not a corpus.

Convert to 16 kHz mono at training time

Many ASR models, including Whisper and wav2vec 2.0, take 16 kHz mono input. Do the conversion when you build shards, not at download:

# 16 kHz, mono, 16-bit PCM WAV
ffmpeg -nostdin -i abc123.opus -vn -ac 1 -ar 16000 -c:a pcm_s16le abc123.wav

# Same, as FLAC (lossless, smaller than WAV)
ffmpeg -nostdin -i abc123.opus -vn -ac 1 -ar 16000 -sample_fmt s16 -c:a flac abc123.flac

-ac sets the channel count and -ar the sample rate (ffmpeg docs). Keeping the native file means you can later produce 24 kHz for TTS, keep stereo, or try another resampler without downloading again.

If you really only want WAV on disk, you can do the conversion inside yt-dlp with --postprocessor-args (alias --ppa). The ExtractAudio+ffmpeg_o key passes the arguments to ffmpeg just before the output file, and only when the ExtractAudio step runs it:

yt-dlp -f ba -S lang -x --audio-format wav \
  --ppa 'ExtractAudio+ffmpeg_o:-ac 1 -ar 16000' \
  -o '%(id)s.%(ext)s' URL

Cut segments with --download-sections

--download-sections takes a chapter-title regex or, with a * prefix, a time range. Negative timestamps count from the end, *from-url uses the URL's start/end time, and the flag can be repeated. It needs ffmpeg.

# Minutes 10–20 only, plus any chapter whose title matches "interview"
yt-dlp -f ba -S lang -x \
  --download-sections '*10:00-20:00' --download-sections 'interview' \
  -o '%(id)s_%(section_start)s.%(ext)s' URL

Use this when you already have timestamps, for example from a dataset manifest. Treat the cut edges as approximate, and trim to exact sample boundaries in your own preprocessing if your labels need it.

Filter before you download

--match-filters accepts any output-template field, compared with the same operators as format filtering. & joins conditions, !field means "field absent or false", and repeating the flag ORs the filters:

yt-dlp -f ba -S lang -x \
  --match-filters '!is_live & duration>=60 & duration<=7200 & language^=en' \
  URL_OR_PLAYLIST

A detail that matters for language: YouTube doesn't set a video-level language, but language is a format field. yt-dlp evaluates match filters once before format selection, where missing format fields pass, and again in process_info after selection, before any media is downloaded. In practice language^=en tests the audio track you're about to download. Together with -S lang, that means "the original audio is English". Videos with no language info are rejected unless you write language^=?en.

Filters on duration and is_live can drop playlist entries early, before a full extraction, when the playlist listing already includes those fields. For license filtering (Creative Commons), see our Creative Commons guide.

Provenance: info.json, embedded metadata, archive

  • --write-info-json writes the full metadata next to the file, including the selected format_id, language, asr, abr, the license and the channel. That's your per-sample lineage.
  • --embed-metadata writes title, uploader, date and similar fields into the audio file's tags, so they stay with the file if it gets separated from its JSON. (The infojson attachment only applies to mkv/mka.)
  • --download-archive archive.txt records IDs so reruns skip completed videos.
  • Name files by %(id)s, not by title.

Transcripts are a separate topic: our guide to yt-dlp subtitles and auto captions covers manual vs ASR tracks, the -orig track and VTT cleanup.

Throttling: audio is request-bound

An audio file is a small fraction of the size of its video, so per-video request overhead and YouTube's rate limits set your throughput, not bandwidth. The built-in -t sleep preset expands to --sleep-subtitles 5 --sleep-requests 0.75 --sleep-interval 10 --max-sleep-interval 20. For "Sign in to confirm you're not a bot", PO tokens, cookies and spreading load across IPs, see the troubleshooting guide.

Storage math for 100k hours

Formula: bytes = bitrate (bits/s) ÷ 8 × seconds. 100,000 h × 3,600 s = 360,000,000 s. The bitrates below are assumptions; your real Opus/AAC averages will differ.

Storage format (assumed bitrate) Per hour 100k hours
Native AAC/Opus at 128 kbps 57.6 MB 5.76 TB
Native Opus at 160 kbps 72 MB 7.2 TB
16 kHz × 16-bit × mono WAV = 256 kbps 115.2 MB 11.52 TB
48 kHz × 16-bit × stereo WAV = 1,536 kbps 691.2 MB 69.12 TB

For example, 160,000 ÷ 8 × 360,000,000 = 7,200,000,000,000 bytes = 7.2 TB. FLAC at 16 kHz mono comes in below the WAV figure, but the ratio depends on the content, so measure it on a sample. Transfer time: 7.2 TB is 57.6 Tbit, or 57,600 s ≈ 16 h at a sustained 1 Gbps.

The request side looks different. Assume an average video length of 10 minutes: 100k hours is then 600,000 videos. With -t sleep the per-video sleep averages 15 s, so one worker starts at most 240 videos/hour. That's 2,500 worker-hours, about 104 hours of wall-clock time with 24 workers. For link and egress sizing, see bandwidth for large-scale video downloads.

Goal → command

Goal Command (add URL)
Best native audio, original track, no re-encode yt-dlp -f ba -S lang -x
Same, excluding DRC variants yt-dlp -f 'ba[format_id!*=drc]/ba' -S lang -x
AAC/M4A only yt-dlp -f 'ba[ext=m4a]' -S lang
Smallest file, still ≥16 kHz yt-dlp -f 'ba[asr>=16000]' -S lang,+size -x
English original audio only yt-dlp -f ba -S lang -x --match-filters 'language^=en'
16 kHz mono WAV straight away yt-dlp -f ba -S lang -x --audio-format wav --ppa 'ExtractAudio+ffmpeg_o:-ac 1 -ar 16000'
Only a time range yt-dlp -f ba -S lang -x --download-sections '*10:00-20:00'
Corpus run with provenance and pacing yt-dlp -f ba -S lang -x --embed-metadata --write-info-json --download-archive archive.txt -o '%(id)s.%(ext)s' -t sleep

Python API

The same setup through yt_dlp.YoutubeDL. The repo's devscripts/cli_to_api.py translates any CLI flags into these parameters.

import yt_dlp
from yt_dlp.utils import match_filter_func

URLS = ['https://www.youtube.com/watch?v=VIDEO_ID']

ydl_opts = {
    'format': 'ba[format_id!*=drc]/ba',
    'format_sort': ['lang'],                      # original audio track first
    'match_filter': match_filter_func('!is_live & duration>=60 & duration<=7200'),
    'paths': {'home': 'audio_raw'},
    'outtmpl': {'default': '%(id)s.%(ext)s'},
    'writeinfojson': True,
    'download_archive': 'archive.txt',
    'sleep_interval_requests': 0.75,
    'sleep_interval': 10,
    'max_sleep_interval': 20,
    'postprocessors': [
        # 'best' = stream-copy WebM/Opus to .opus, leave .m4a untouched
        {'key': 'FFmpegExtractAudio', 'preferredcodec': 'best'},
        {'key': 'FFmpegMetadata', 'add_metadata': True},
    ],
    # For 16 kHz mono WAV instead: set preferredcodec to 'wav' and add
    # 'postprocessor_args': {'extractaudio+ffmpeg_o': ['-ac', '1', '-ar', '16000']},
}

with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    retcode = ydl.download(URLS)

Postprocessors run in list order, so audio extraction happens before metadata embedding. Keys in postprocessor_args are lowercase.

Compliance

YouTube's Terms of Service restrict automated access and downloading. Copyright and licensing apply to audio just as to video; some teams collect only Creative Commons material and record the license per sample. Voices are personal data under regimes like GDPR, and a voice can identify a speaker even without a name attached. That matters especially for TTS and voice-cloning use. Honor takedown and opt-out requests, and keep the lineage (video ID, channel, info.json) you need to act on them. Get legal review for your jurisdiction and use case.

If you'd rather not run this yourself

Corpora offers dedicated 1–40 Gbps unmetered proxy capacity (HTTP(S) and SOCKS5, compatible with yt-dlp) for teams running their own stack. There is also a fully managed option that delivers audio, subtitles and metadata as JSONL/Parquet with sha256 checksums and manifests to S3, GCS or Azure Blob, starting with a free sample batch. Contact us to scope it.

FAQ

How do I download only the audio from YouTube with yt-dlp?

yt-dlp -f ba -x URL. -f ba selects the best audio-only stream. -x with the default best format turns the WebM into .opus by stream copy and leaves M4A untouched, with no re-encoding. Add -S lang to prefer the original track on dubbed videos.

Is --audio-format mp3 lower quality?

Yes. YouTube's audio-only streams are Opus or AAC, so yt-dlp has to decode the Opus or AAC and re-encode it, adding a second lossy generation. Keep the native format and convert to WAV/FLAC when you need PCM.

Why did yt-dlp download a dubbed audio track?

On YouTube, the extractor's default sort puts quality and codec ahead of lang, so the original-track preference only breaks ties. Pass -S lang to make it the first criterion, and check -F for the (original) note.

What sample rate should I store for ASR training?

Store whatever YouTube served (check asr in -F). Resample to the model's rate, typically 16 kHz mono for ASR, with ffmpeg -ac 1 -ar 16000 when building training shards.

Does --download-sections still download the whole file?

No. yt-dlp passes each range to ffmpeg as input-side -ss/-t, so ffmpeg seeks into the stream instead of reading it from the start. You can pull labeled spans from long videos without storing the rest.