Show HN:YouTube 吉他谱解析器
Show HN: YouTube Guitar Tab Parser

原始链接: https://github.com/marcelpanse/youtube-guitar-tab-parser

这是一个将 YouTube 吉他教学视频自动转换为结构化 PDF 吉他谱的命令行工具。它需要 Node.js (≥20)、`yt-dlp`、`ffmpeg` 以及 Anthropic API 密钥。 **工作流程:** 1. **下载与提取:** 使用 `yt-dlp` 和 `ffmpeg` 获取视频并按设定的时间间隔提取帧。 2. **检测:** 使用 Claude Vision 识别包含吉他谱的特定屏幕区域。 3. **优化:** 将帧裁剪至检测到的区域并进行多阶段去重。它利用感知哈希(perceptual hashing)移除近乎相同的帧,并通过 Claude 读取小节编号,确保每个乐句只被包含一次。 4. **合成:** 将提取出的乐谱行拼接成 A4 PDF 文档,并根据视频元数据自动生成标题和页眉。 **使用方法:** 在安装依赖并配置 API 密钥后,只需通过以下命令运行工具并传入 YouTube 链接即可: `node dist/cli.js ""` 该工具提供合理的默认设置,用户无需手动配置即可生成专业的吉他谱,同时也提供可选参数用于调整采样间隔、模型选择和分辨率控制。生成的最终 PDF 将保存至 `/out` 目录。

一位开发者在 GitHub 上发布了一款新的命令行工具,可以将 YouTube 上的吉他教学视频转换为 PDF 格式的吉他谱。由于对现有的 AI 转录服务感到不满,该开发者采用了一种独特的方法:该工具会先下载视频,利用 Claude 的视觉能力识别并裁剪每一帧中的谱表区域,通过打印的的小节编号进行去重,最后将图像拼接成一份完整的文档。 该项目在 Hacker News 社区获得了积极反馈,用户对这款作为付费转录服务免费替代品的新工具表示非常期待。不过,目前也出现了一些关于技术层面的质疑,例如该工具在处理“滚动谱表”类视频(即播放头静止但乐谱滚动)时的有效性;此外,还有建议提出应探索比基于大语言模型(LLM)的处理方式更廉价的传统计算机视觉方案。该开发者表示,目前工具尚处于早期阶段,欢迎社区参与测试和贡献。
相关文章

原文

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.

  • Node.js ≥ 20
  • yt-dlp and ffmpeg on your PATH (brew install yt-dlp ffmpeg)
  • An Anthropic API key
npm install
npm run build
cp .env.example .env   # then put your ANTHROPIC_API_KEY in it
# 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.

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
  1. Downloadyt-dlp fetches the video (≤ --max-height).
  2. Framesffmpeg extracts one frame every --interval seconds.
  3. Detect — a labeled horizontal-band grid is drawn on --sample frames and Claude vision reports which bands contain sheet music. The median first/last music band (robust to an outlier) gives the vertical extent; width is kept full. (Coarse labeled bands are far more reliable than asking a vision model for precise pixel coordinates.)
  4. Cropsharp crops every frame to that region.
  5. 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.
  6. 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.
  7. PDFpdf-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.
联系我们 contact @ memedata.com