JimLiu/baocut / skills/baocut
baocut
Flagged用 BaoCut 处理视频与音频:转录、字幕、翻译、配音、剪口播、切短视频、分章、总结写稿、从链接下载、压缩转码、导出成片,或从零做一条成片。有媒体文件、视频链接、字幕文件或 BaoCut 视频时用;只翻译纯文本、与视频无关的写作或作图、别的剪辑器与 FFmpeg 的用法、BaoCut 源码开发不用。
references/craft/production-scripts/scripts/envelope.mjs
View on GitHub#!/usr/bin/env node
// i18n-ignore-file: 给智能体拷走用的独立脚本,日志与报错写英文
// 把一段录音量成一排条(RMS 包络),写成场景能直接读的 JS,给 scene-kit 的 K.bars() 画:
// node tools/envelope.mjs <录音> --out shared/speech-wave.js [--var SPEECH_WAVE] [--bars 240] [--from 秒] [--to 秒]
// 输出:window.<var> = { off, dur, bars: [0..1, …] }。off 是这排条从录音的第几秒起(--from,缺省 0),dur 是量的这段的秒数,
// bars 按 95 分位归一(最响的几条夹到 1),
// 开头的爆音不会把其余的压扁。视频里的录音剪掉了开头(报幕、空白)时带 --from 剪掉的秒数,声波才和视频里放的那段对得上;
// 场景拿录音的秒数(例如原声片段的 from / to)标位置时先减去 off。不读配置、不连 Runtime,只要本机有 ffmpeg。
import fs from 'node:fs';
import path from 'node:path';
import { execFileSync } from 'node:child_process';
import { audioWindow, parseArgs } from './lib.mjs';
const { ids, flags } = parseArgs(process.argv, ['out', 'var', 'bars', 'from', 'to']);
const [file] = ids;
if (!file || !flags.out) throw new Error('usage: envelope.mjs <audio> --out <file.js> [--var NAME] [--bars 240] [--from s] [--to s]');
const n = Math.round(+(flags.bars ?? 240));
if (!(n >= 8)) throw new Error(`--bars must be a number of bars (8 or more), got ${flags.bars}`);
const name = flags.var || 'SPEECH_WAVE';
if (!/^[A-Za-z_$][\w$]*$/.test(name)) throw new Error(`--var must be a JavaScript identifier, got ${name}`);
const RATE = 8000;
const from = flags.from != null ? +flags.from : 0;
const { input, filters } = audioWindow(from, flags.to != null ? +flags.to - from : null);
const pcm = execFileSync('ffmpeg', ['-v', 'error', ...input, '-i', file, '-vn', ...(filters.length ? ['-af', filters.join(',')] : []), '-ac', '1', '-ar', String(RATE), '-f', 's16le', '-'], { maxBuffer: 1 << 30 });
const total = pcm.length >> 1;
if (!total) throw new Error(`no audio decoded from ${file}`);
const rms = [];
for (let b = 0; b < n; b++) {
const s = Math.floor((b * total) / n), e = Math.max(s + 1, Math.floor(((b + 1) * total) / n));
let acc = 0;
for (let j = s; j < e; j++) { const v = pcm.readInt16LE(j * 2) / 32768; acc += v * v; }
rms.push(Math.sqrt(acc / (e - s)));
}
const top = [...rms].sort((a, b) => a - b)[Math.min(n - 1, Math.floor(n * 0.95))] || 1;
const bars = rms.map(v => +Math.min(1, v / top).toFixed(3));
const dur = +(total / RATE).toFixed(2), off = flags.from != null ? +flags.from : 0;
fs.mkdirSync(path.dirname(path.resolve(flags.out)), { recursive: true });
fs.writeFileSync(flags.out, `// envelope of ${path.basename(file)} from ${off} s (${dur} s), ${n} RMS bars; drawn with K.bars(), which takes recording seconds and subtracts off itself\nwindow.${name} = ${JSON.stringify({ off, dur, bars })};\n`);
console.log(`${flags.out}: window.${name}, ${n} bars over ${dur} s from ${off} s`);
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |