跳转到主要内容

用 aria2 为 yt-dlp 提速

yt-dlp 负责解析流地址、Cookie 与请求头,aria2c 则以每个文件最多 16 条并行连接拉取数据,把被 CDN 限速的单条连接变成跑满带宽的管道。本指南是完整的实用参考:安装、调优、自动化、验证与故障排查。

最后核对 2026-09 · aria2 v1.37.0 · 需要 yt-dlp 2024+ 与 ffmpeg

开始之前

仅下载你有权获取的内容。 请遵守各站点的服务条款与当地版权法律。

工作原理与适用范围

yt-dlp 是解析器:它与站点协商、选择流格式并生成精确的请求(URL、Cookie、请求头、字节范围)。aria2c 是传输引擎:它对同一主机开启多条套接字并行拉取分片。两者结合,兼得 yt-dlp 的准确与 aria2 的吞吐。

aria2 帮助很大的场景

  • 直接的 HTTP(S) 媒体文件(大视频/音频以单个文件下载)
  • YouTube 式 DASH:视频与音频是各自完整的文件
  • 高速线路(500 Mbps 以上)上的数 GB 4K/8K 下载
  • 限制单条 TCP 连接、却允许多个字节范围请求的服务器

aria2 帮助有限的场景

  • 直播(长度不固定)
  • 分片式 HLS/DASH(成千上万个小分片)– 用 yt-dlp 原生/ffmpeg 下载器,并以 -N 调优
  • 明确拒绝并行范围的服务器(出现 403/429 – 降低 -x)

经验法则:若 yt-dlp 显示一个大小已知的单一 Destination 文件,aria2 会加速它;若显示成百上千个小分片,请改用 -N 8,该任务不要用外部下载器。

安装与更新

yt-dlp 更新非常频繁,以跟进站点变化。使用过旧的版本是突然失败的最常见原因。

# aria2
sudo apt install aria2          # Debian/Ubuntu
brew install aria2              # macOS
winget install aria2.aria2      # Windows(或 scoop install aria2)

# ffmpeg(合并视频与音频所需)
sudo apt install ffmpeg
brew install ffmpeg
winget install Gyan.FFmpeg

# yt-dlp - 独立二进制(推荐),随后自更新
yt-dlp -U

# yt-dlp - 通过 Python/pip(之后用 pip 更新,而非 -U)
python -m pip install -U yt-dlp

确认它们都在 PATH 中:

aria2c --version && yt-dlp --version && ffmpeg -version

快速开始(一条命令)

用 --downloader 把下载交给 aria2,并通过 --downloader-args 以 aria2c: 前缀传入 aria2 参数:

yt-dlp --downloader aria2c --downloader-args "aria2c:-x 16 -s 16 -k 1M" "URL"

参数解析

  • --downloader aria2c – 对 HTTP(S) 下载使用外部下载器 aria2c(旧版 youtube-dl 用 --external-downloader;yt-dlp 的正式名称是 --downloader)。
  • --downloader-args "aria2c:…" – aria2c: 之后的内容原样传给 aria2c 进程。
  • -x 16 = --max-connection-per-server=16(每个主机的套接字数)
  • -s 16 = --split=16(将文件分为 16 个分片)
  • -k 1M = --min-split-size=1M(避免小文件频繁重建连接)

yt-dlp 会自动把 Cookie、User-Agent 与所需请求头转发给 aria2c,因此签名 URL 仍然有效。

验证生效: 加上 --verbose,观察 aria2c 的调用与进度行(见验证与监控)。

yt-dlp + aria2 命令生成器

选择选项,即可生成可直接运行的命令。

yt-dlp --downloader aria2c --downloader-args "aria2c:-x 16 -s 16 -k 1M" -f "bestvideo+bestaudio/best" --merge-output-format mkv --embed-subs --embed-chapters "URL"

连接与分片调优

对单个文件,aria2 最多开启 min(split, max-connection-per-server) 条连接。从 16 开始,若站点拒绝再下调。

按场景推荐的 aria2 设置
场景-x-s-k说明
高速家庭线路 / VPS(500 Mbps+)16161M最大吞吐
常见宽带881M均衡,封禁更少
严格 CDN / 频繁 403 或 429442M不像爬虫
播放列表项目很多16161M谨慎提高 aria2 -j(并发数)
# 面向播放列表:限制并行文件为 4,并增加重试
yt-dlp --downloader aria2c \
  --downloader-args "aria2c:-x 16 -s 16 -k 1M -j 4 --retry-wait=3 --max-tries=5" \
  "PLAYLIST_URL"

分片流(HLS/DASH)是另一条路径:不要用 aria2,改用 yt-dlp 自身提高并行分片数:-N 8(例如 yt-dlp -N 8 URL)。

格式选择与合并

yt-dlp 分别下载视频与音频轨,再由 ffmpeg 合并。这与 aria2 无关(若每条轨道是单个文件,aria2 会分别加速)。

# 最佳质量,转换为 MKV
-f "bestvideo+bestaudio/best" --merge-output-format mkv

# 限制分辨率同时保留最佳音频
-S "res:1080" -f "bv*+ba/b"

# 仅音频(经 ffmpeg 转为 MP3)
-x --audio-format mp3 --audio-quality 0

# 先列出所有可用格式
-F URL

-S(排序)通常比硬编码 -f 过滤更清晰。--merge-output-format 需要 ffmpeg。

永久配置

与其每次重复输入参数,不如写入 yt-dlp 配置文件。

yt-dlp 配置(每行一个参数)
--downloader aria2c
--downloader-args "aria2c:-x 16 -s 16 -k 1M --file-allocation=falloc --retry-wait=3 --max-tries=5"
-f "bestvideo+bestaudio/best"
--merge-output-format mkv
--embed-metadata
--embed-chapters
--embed-thumbnail
-o "%(title)s [%(id)s].%(ext)s"

Windows 引号: aria2c: 值两侧的双引号必须保留。PowerShell 中按原样即可;配置文件中使用如上所示的字面双引号。

实战配方

可直接复制、覆盖常见任务的起点。

下载整个播放列表/频道,避免重复下载

yt-dlp --downloader aria2c \
  --downloader-args "aria2c:-x 16 -s 16 -k 1M -j 3" \
  --download-archive archive.txt \
  -o "%(playlist_title)s/%(playlist_index)s - %(title)s.%(ext)s" \
  "PLAYLIST_URL"

私密 / 年龄限制视频(Cookie)

yt-dlp --cookies-from-browser firefox \
  --downloader aria2c --downloader-args "aria2c:-x 16 -s 16 -k 1M" "URL"

# 或使用先前导出的 Netscape 格式 cookies.txt
yt-dlp --cookies cookies.txt ... "URL"

通过代理连接

yt-dlp --proxy "http://127.0.0.1:8080" \
  --downloader aria2c \
  --downloader-args "aria2c:--all-proxy=http://127.0.0.1:8080 -x 8 -s 8" "URL"

为 yt-dlp(元数据)与 aria2(数据本体)都设置代理。aria2 只接受 HTTP 代理:如果你的是 SOCKS5 代理,可直接给 yt-dlp 使用,再为 aria2 配一个本地 HTTP 转 SOCKS 桥接(privoxy、gost)。

限制带宽,避免跑满线路

yt-dlp --downloader aria2c \
  --downloader-args "aria2c:-x 8 -s 8 --max-download-limit=5M" "URL"

# 或对 yt-dlp/aria2 整体限速
yt-dlp -r 5M --downloader aria2c --downloader-args "aria2c:-x 8 -s 8" "URL"

只取片段、字幕、封面、元数据、SponsorBlock

# 5 分钟片段
yt-dlp --download-sections "*10:15-15:00" ... "URL"

# 字幕 + 封面 + 元数据,嵌入
yt-dlp --write-subs --sub-langs "en.*" --embed-subs \
  --embed-thumbnail --embed-metadata --embed-chapters ... "URL"

# 移除赞助片段(需要 ffmpeg)
yt-dlp --sponsorblock-remove sponsor ... "URL"

批量处理 URL 列表

yt-dlp --downloader aria2c --downloader-args "aria2c:-x 16 -s 16 -k 1M -j 3" \
  --batch-file urls.txt

验证与监控

确认确实由 aria2 执行下载:

yt-dlp --verbose --downloader aria2c \
  --downloader-args "aria2c:-x 16 -s 16 -k 1M --summary-interval=5" "URL"

故障排查

HTTP 403 Forbidden / aria2 以代码 1、3 或 9 退出

原因: CDN 的 URL 是短时效签名链接,或站点不喜欢大量并行连接 / 非浏览器 User-Agent。
解决: 更新 yt-dlp(yt-dlp -U),降到 -x 8 -s 8,并用 --cookies-from-browser 传入 Cookie。yt-dlp 会自动转发请求头,除非站点要求,不要覆盖 User-Agent。

“external downloader ... not installed” / 找不到 aria2c

原因: aria2c 不在 PATH 中(或 yt-dlp 找不到它)。
解决: 安装 aria2(见安装);Windows 上将 aria2c.exe 放到 yt-dlp.exe 旁边或把文件夹加入 Path;重开终端。

下载成了一大堆小分片 / 非常慢

原因: 源是分片式 HLS/DASH 流,aria2 无法加速。
解决: 该任务不要用外部下载器,改用 yt-dlp 原生分片:yt-dlp -N 8 URL。

HTTP 429 Too Many Requests

原因: 短时间内连接/请求过多。
解决: 降低 -j 与 -x,加上 --sleep-requests 1,并减缓并行项目。

合并/转换失败,或输出没有声音

原因: 缺少 ffmpeg,或所选容器与编码不兼容。
解决: 安装 ffmpeg 并用 ffmpeg -version 验证;使用最兼容的 --merge-output-format mkv 而非 mp4。

直播永远不会结束

原因: 直播没有固定大小,aria2 等待永远不会出现的 Content-Length。
解决: 直播不要用 aria2 下载器,改用 yt-dlp 默认(在支持时用 --live-from-start 从头录制)。

Windows:“aria2c:-x is not recognized” / 参数被忽略

原因: shell 的引号处理把 aria2c: 的值拆开了。
解决: 将整个值用双引号包裹:--downloader-args "aria2c:-x 16 -s 16 -k 1M";在 PowerShell 中不要混用单双引号。

常见问题

16 连接总是更好吗?

不是。超出线路容量后,额外连接只会带来开销并可能触发限速。8 是更稳妥的默认;严格服务器降到 4。

对 YouTube 播放列表和频道也有效吗?

有效。aria2 并行下载每条轨道;用 --download-archive 避免重复下载,并把 -j 保持在适中水平以避免限速。

可以配合 yt-dlp --newline 记录日志吗?

可以 – --newline 只改变 yt-dlp 的进度格式,不影响外部下载器。

下载文件保存在哪里?

在当前目录,或 -P/-o 指定的位置。例如 -P ~/Downloads。

请仅用于你有权下载的内容。