Pixiv - KiraraShss
695 字
3 分钟
YouTube 视频 → 音频 → 文字 → AI Skill:一套 2026 年仍可用的完整工程流程
背景
YouTube 是当前互联网上质量最高的公开视频知识库之一,但要把它真正变成可用的 AI 能力,往往会遇到以下问题:
- YouTube 反爬升级,匿名下载不稳定
- Linux 下浏览器 Cookie 解密复杂
- 音频 / 字幕需要标准化
- 希望最终形成 可复用的 AI Skill / 知识模块
本文记录一套在 2025–2026 年仍然可用、稳定、工程化 的完整方案。
总体流程
YouTube URL ↓yt-dlp(带登录态) ↓MP3 音频 ↓Whisper ASR ↓文本 / 字幕 ↓Chunk / Embedding ↓AI Skill / RAG一、核心工具
1. yt-dlp(YouTube 下载)
- youtube-dl 的增强版
- 支持最新 YouTube 反爬策略
- 支持 Cookie / JS runtime
安装:
pip install -U yt-dlp2. ffmpeg(必备)
yt-dlp 抽取音频、修复封装都依赖 ffmpeg。
sudo apt updatesudo apt install -y ffmpeg验证:
ffmpeg -versionffprobe -version3. Whisper(音频转文字)
本地 ASR,支持中英文,适合私有知识库。
pip install -U openai-whispersudo apt install -y ffmpeg二、YouTube 下载的关键:登录态
常见错误
Sign in to confirm you’re not a bot这是 YouTube 强制要求登录态的表现,不是 yt-dlp 的问题。
三、推荐下载方案
方案 A:从浏览器直接读取 Cookie(桌面环境)
前提:
- 本机有 GUI
- Chrome / Chromium 已登录 YouTube
- 不要使用 sudo
yt-dlp --cookies-from-browser chrome -f ba -x --audio-format mp3 https://www.youtube.com/watch?v=VIDEO_IDLinux 必要依赖(否则 Cookie 无法解密)
python3 -m pip install -U secretstorage keyring cryptographysudo apt install -y dbus-x11 gnome-keyring libsecret-1-0方案 B(最稳):cookies.txt(服务器 / 自动化推荐)
- 浏览器安装 Get cookies.txt 扩展
- 登录 YouTube,导出
cookies.txt
使用:
yt-dlp --cookies cookies.txt -f ba -x --audio-format mp3 https://www.youtube.com/watch?v=VIDEO_ID四、JS Runtime(可选但推荐)
解决以下 warning:
No supported JavaScript runtime could be foundn challenge solving failed安装 deno:
curl -fsSL https://deno.land/install.sh | shexport PATH="$HOME/.deno/bin:$PATH"五、最佳实践:只下载音频
yt-dlp --cookies cookies.txt -f ba -x --audio-format mp3 https://www.youtube.com/watch?v=VIDEO_ID六、Whisper 转文字
中文 / 中英混合:
whisper *.mp3 --model medium --language zh输出文件:
video.mp3video.txtvideo.srtvideo.vtt推荐模型:
| 模型 | 用途 |
|---|---|
| base | 快速测试 |
| medium | 准确率 / 性能平衡(推荐) |
| large | 高准确率(慢) |
七、构建 AI Skill(示例)
推荐目录结构
skills/youtube_astock/ ├── source.mp3 ├── transcript.txt ├── chunks.json ├── embedding.vec └── skill.yaml文本切块示例
def chunk_text(text, max_len=500): chunks = [] cur = "" for line in text.split("\n"): if len(cur) + len(line) > max_len: chunks.append(cur) cur = line else: cur += line chunks.append(cur) return chunksSkill 描述示例
name: youtube_astock_skilldescription: > Knowledge extracted from YouTube videos about A-share trading.input: question: stringoutput: answer: string八、一键流水线
yt-dlp --cookies cookies.txt -f ba -x --audio-format mp3 $URLwhisper *.mp3 --model medium --language zhpython build_skill.py总结
- 2025+ 年 YouTube 匿名下载不稳定
- Cookie 登录态是关键
- ffmpeg 是必备组件
- Whisper 非常适合私有知识库
- 该流程适用于:
- AI Agent
- MCP Tool
- RAG 知识库
- 投资 / 技术 / 课程 Skill
延伸方向
- 多视频 → 单主题 Skill
- 自动同步 YouTube Playlist
- Skill + 向量检索 + Tool Calling
- LangChain / LangGraph / MCP 集成
赞助支持
如果这篇文章对你有帮助,欢迎赞助支持!
YouTube 视频 → 音频 → 文字 → AI Skill:一套 2026 年仍可用的完整工程流程
https://jkwei.com/posts/knowledge/youtube视频文字提取/ 最后更新于 2026-01-14,距今已过 1 天
部分内容可能已过时