# YouTube 吉他谱解析器

- 来源：Hacker News 热门（buzzing.cc 中文翻译）
- 作者：neogenix
- 发布时间：2026-07-14 16:10
- AIHOT 分数：67
- AIHOT 链接：https://aihot.virxact.com/items/cmrkdylqq00vzbizsn6bmona0
- 原文链接：https://github.com/marcelpanse/youtube-guitar-tab-parser

## AI 摘要

一款开源 CLI 工具，可将 YouTube 吉他教学视频自动转换为 PDF 格式的吉他谱。工具下载视频后采样帧画面，使用 Claude 视觉模型定位乐谱区域，裁剪每帧并基于每行乐谱上的小节编号去重，最终将不同小节垂直拼接为 PDF。PDF 包含视频标题作为首页标题和文档元数据。无需配置即可使用，依赖 Node.js ≥ 20、yt-dlp、ffmpeg 和 Anthropic API key。支持自定义截图间隔、采样帧数、去重阈值等参数。

## 正文

Youtube Guitar Tab Parser

CLI that turns a YouTube guitar-lesson video into a PDF of the guitar tab.

It downloads the video, samples frames, uses Claude vision to locate the tab region, crops every frame to that region, de-duplicates the crops by the bar number printed on each line of the score, and stitches the distinct tab lines vertically into a PDF. It works out of the box with no configuration — the PDF is written to out/<video-title>.pdf, with the video title as a heading on the first page and in the document metadata.

Example

Generated from the YouTube lesson Game of Thrones - Guitar Lesson + TAB:

🎬 Source video: https://youtu.be/WgU5tDGC-Vc

📄 Output PDF: examples/Game of Thrones.pdf

Requirements

Node.js ≥ 20

yt-dlp and ffmpeg on your PATH (brew install yt-dlp ffmpeg)

An Anthropic API key

Setup

npm install npm run build cp .env.example .env # then put your ANTHROPIC_API_KEY in it

Usage

# with a .env file node --env-file=.env dist/cli.js "https://www.youtube.com/watch?v=WgU5tDGC-Vc"

# or with the key already exported export ANTHROPIC_API_KEY=sk-ant-... node dist/cli.js "https://www.youtube.com/watch?v=WgU5tDGC-Vc"

During development you can skip the build step:

node --env-file=.env --import tsx src/cli.ts "<url>"

The result is written to out/<video-title>.pdf (its path is also printed to stdout); progress goes to stderr.

Options

Everything has a sensible default; you normally only need the URL.

-i, --interval <seconds> screenshot interval (default 2) --model <id> Claude vision model (default claude-sonnet-5) --sample <n> frames sampled for tab-region detection (default 6) --dedup-threshold <n> pre-dedup Hamming distance, cost control (default 12) --max-height <px> cap download resolution (default 720) --keep-temp keep intermediate frames/crops

How it works

Download — yt-dlp fetches the video (≤ --max-height).

Frames — ffmpeg extracts one frame every --interval seconds.

Detect — two stages, since vision models are reliable at picking labeled regions but not at precise pixel coordinates:

A labeled row/column grid is drawn on --sample frames and Claude vision reports which rows and columns the sheet music overlaps. The per-edge median across samples gives a coarse box (works whether the tab is a full-width bottom strip or a corner overlay).

That box is then snapped to the actual paper edges with an image mask (sheet music is dark content on a light, unsaturated background, unlike the colourful performer/backdrop), so the crop hugs the tab tightly. If no clear paper region is found (e.g. a dark-themed tab viewer), the vision box is used.

Crop — sharp crops every frame to that box.

Pre-dedup — a dHash perceptual hash drops near-identical consecutive crops. This is only a cost control to reduce the number of vision calls in the next step.

Bar-number dedup — Claude reads the measure/bar number printed at the start of each line and whether the crop is real sheet music. The tool keeps exactly one crop per distinct bar number (first appearance wins) and drops non-tab crops (title cards, intros/outros). Because the bar number is constant while the playback cursor sweeps a line and only changes when the score advances, this collapses all the near-identical cursor frames of a line into a single page.

PDF — pdf-lib stacks the distinct tab lines vertically down A4 pages, in the order they appear in the video. The video title (read from yt-dlp) becomes the file name, a heading on the first page, and the document metadata title. Output: out/<video-title>.pdf.
