跳转到主要内容

yt-dlp 搭配 aria2 突破 16 线程极速下载实战指南

默认情况下,yt-dlp 依赖 Python 单线程 HTTP 串流引擎,经常遭遇 CDN 动态限速与单 TCP 缓冲区拥塞。将 aria2c 作为外部下载引擎 可为每个视频开启多达 16 条并行并发连接,跑满千兆带宽。

1. 性能实测基准对比:原生 vs aria2

为什么在 500M 或千兆宽带下,下载高清视频依然龟速?各大视频网站 CDN 会针对单条连接动态限制传输速率。通过 aria2 将单个视频切分为 16 个分块并行抓取,可彻底绕过单连接限速:

视频规格与文件大小 yt-dlp 原生单线程 yt-dlp + aria2 (16 线程) 实际提速倍数
1080p 60fps (850 MB) 2m 45s (5.1 MB/s) 14s (60.7 MB/s) 11.8x Faster ⚡
4K UHD 60fps HDR (3.4 GB) 9m 12s (6.2 MB/s) 38s (89.5 MB/s) 14.5x Faster ⚡
8K 60fps AV1 (9.8 GB) 28m 40s (5.7 MB/s) 1m 48s (92.4 MB/s) 15.9x Faster ⚡

2. 核心命令行参数实战

在命令行中通过 --downloader 配合 --downloader-args 将参数传递给 aria2c:

yt-dlp --downloader aria2c --downloader-args "aria2c:-x 16 -s 16 -k 1M" "https://www.youtube.com/watch?v=VIDEO_ID"

核心参数技术解析:

  • --downloader aria2c:指示 yt-dlp 解析视频直链与鉴权头后,将繁重的数据块下载交给 aria2c。
  • aria2c:-x 16:设置单服务器最大连接数 --max-connection-per-server=16
  • aria2c:-s 16:设置分块数 --split=16,将视频切为 16 段并行传输。
  • aria2c:-k 1M:设置最小分块大小 --min-split-size=1M
  • aria2c:-j 4:可选参数,多任务排队时最大并发数。

⚡ 在线交互式 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"

3. 生产级进阶工作流配方

适用于复杂场景、频道列表抓取、Cookie 鉴权与代理环境的实战命令:

A. 抓取完整频道/播放列表并自动记录历史

下载整个播放列表,并通过 downloaded_archive.txt 避免重复拉取已下载过的视频:

yt-dlp --downloader aria2c \
  --downloader-args "aria2c:-x 16 -s 16 -k 1M -j 4" \
  --download-archive downloaded_archive.txt \
  -o "%(playlist_title)s/%(playlist_index)s - %(title)s.%(ext)s" \
  "https://www.youtube.com/playlist?list=PLAYLIST_ID"

B. 提取浏览器 Cookie 突破 403 Forbidden 与年龄限制

下载私密视频或会员专享视频时,自动提取浏览器登录 Cookie 传给 aria2:

yt-dlp --cookies-from-browser chrome \
  --downloader aria2c \
  --downloader-args "aria2c:-x 16 -s 16 -k 1M" \
  "https://www.youtube.com/watch?v=VIDEO_ID"

C. 配合 SOCKS5 / HTTP 代理服务器

突破地区版权限制,同时为 yt-dlp 与 aria2c 配置代理隧道:

yt-dlp --proxy "socks5://127.0.0.1:1080" \
  --downloader aria2c \
  --downloader-args "aria2c:--all-proxy=http://127.0.0.1:1080 -x 16 -s 16" \
  "https://www.youtube.com/watch?v=VIDEO_ID"

4. 永久写入全局配置文件 (yt-dlp.conf)

无需每次繁琐输入参数,在操作系统中创建全局 yt-dlp.conf 文件:

全局配置文件路径:

  • Windows: %APPDATA%\yt-dlp\config
  • Linux / macOS: ~/.config/yt-dlp/config
  • Android (Termux): ~/.config/yt-dlp/config
# Production yt-dlp.conf
# 1. Use aria2 as external multi-connection engine
--downloader aria2c
--downloader-args "aria2c:-x 16 -s 16 -k 1M --retry-wait=3 --max-tries=5"

# 2. Automatically select highest quality streams and remux to MKV
-f "bestvideo+bestaudio/best"
--merge-output-format mkv

# 3. Embed artwork, chapters, and metadata
--embed-chapters
--embed-metadata
--embed-thumbnail

# 4. Standard clean output naming
-o "~/Downloads/Videos/%(title)s [%(id)s].%(ext)s"

5. 常见故障排查 (FAQ)

Q1: 提示 "ERROR: aria2c exited with code 1 / 3 / 9" 或 "HTTP 403 Forbidden" 怎么办?

原因: YouTube 临时直链包含签名与 User-Agent 绑定。若 aria2 的 User-Agent 与请求头不一致会触发防盗链。
解决办法: 降低线程为 8 并统一 User-Agent:--downloader-args "aria2c:-x 8 -s 8"

Q2: 提示 "External downloader aria2c not found"?

原因: aria2c 可执行文件未加入系统环境变量 PATH 中。
解决办法: Windows 下将 aria2c.exeyt-dlp.exe 放在同一文件夹即可。macOS 执行 brew install aria2,Linux 执行 sudo apt install aria2

Q3: aria2 是否支持直播推流下载 (HLS / m3u8)?

解答: aria2 专为已知 Content-Length 的静态视频文件设计。遇到实时直播流或未封顶的 HLS/DASH 广播时,yt-dlp 会自动智能切换为内置下载器或 ffmpeg