JimLiu/baocut / skills/baocut
baocut
Flagged用 BaoCut 处理视频与音频:转录、字幕、翻译、配音、剪口播、切短视频、分章、总结写稿、从链接下载、压缩转码、导出成片,或从零做一条成片。有媒体文件、视频链接、字幕文件或 BaoCut 视频时用;只翻译纯文本、与视频无关的写作或作图、别的剪辑器与 FFmpeg 的用法、BaoCut 源码开发不用。
references/craft/production-scripts/scripts/preview.mjs
View on GitHub#!/usr/bin/env node
// i18n-ignore-file: 给智能体拷走用的独立脚本,日志与报错写英文
// 写 preview.json,给 video-production 的 examples/bundle-preview.html 用(页面拷到工程根目录,在根目录起静态服务打开)。
// node tools/preview.mjs [--config <配置>]
// 每段:代码包、旁白音频(audio/<id>.<格式>;gaps.mjs 留过白的用 timing 里的 gapAudio)、对齐好的句子(timing/<id>.json),稿子里这一段的备注行当 note。
// 有 clips.json 时,落在这一段的实拍片段换算成 clips: [{ src, at, dur, label, audio }](at 是相对段首的秒数,
// 取所在句的开头,给了 cue 取 cue 被说到的时刻,gap 片段取旁白里留出的空白;同一段里后一个开始时截断)。src 是 overlay.mjs --preview 剪出的小片段。
// 片段的 pip(画中画框:x、y 中心,w 宽,画布百分比)照抄。片段带 subs 时换算成相对片段开头的 [{ start, end, text, tr, who }],页面画在字幕带上;audio 为数字时是原声音量。
// 最后一个片段超出段尾(旁白时长 + hold)时截到段尾并提示。片段的 in / out 转场照抄成 { kind, dur, easing }(长度不超过片段一半),和后一个片段首尾相接的那一侧去掉,与 overlay.mjs 放上时间线的一致。
// 字幕带的样式取配置的 preview.caption(与字幕样式同一套键),没有时取旁白字幕的 captions.style,都不给就不画。footage.layer 为 under 时写 clipsLayer: "under",页面把实拍铺在透明的代码画面下面。
import fs from 'node:fs';
import path from 'node:path';
import { loadConfig, readJson, writeJson, scriptNotes, clipTimes } from './lib.mjs';
const cfg = loadConfig();
const cl = readJson(cfg.abs(cfg.footage?.clips || 'clips.json'), { clips: [] });
const notes = scriptNotes(cfg);
const rel = p => path.relative(cfg.root, cfg.abs(p)).split(path.sep).join('/');
const missing = [];
const segments = cfg.order.map(id => {
const tf = cfg.abs(cfg.dirs.timing, `${id}.json`);
const tm = readJson(tf);
if (!tm) missing.push(id);
const mine = cl.clips.filter(c => c.seg === id), t0 = tm && mine.length ? clipTimes(tm, mine) : {};
const clips = !tm ? [] : mine.map(c => ({
src: rel(path.join(cfg.dirs.work, 'clips', `${c.id}.mp4`)),
at: +t0[c.id].toFixed(3),
dur: +(c.to - c.from).toFixed(3),
label: c.label ?? cl.label ?? '',
...(c.audio ? { audio: true } : {}),
...(typeof c.audio === 'number' ? { volume: c.audio } : {}),
...(c.pip ? { pip: { x: c.pip.x, y: c.pip.y, w: c.pip.w } } : {}),
...(c.in ? { in: { kind: c.in.kind, dur: c.in.dur ?? 0.5, easing: c.in.easing || 'ease-in-out' } } : {}),
...(c.out ? { out: { kind: c.out.kind, dur: c.out.dur ?? 0.5, easing: c.out.easing || 'ease-in-out' } } : {}),
...(c.subs ? { subs: c.subs.map(x => ({ start: +(x.from - c.from).toFixed(3), end: +(x.to - c.from).toFixed(3), text: x.text, tr: x.tr, ...(x.who ? { who: x.who } : {}) })) } : {}),
}));
clips.sort((x, y) => x.at - y.at);
const end = tm ? tm.dur + (cfg.hold[id] || 0) : Infinity;
clips.forEach((c, i) => {
if (clips[i + 1]) c.dur = +Math.min(c.dur, clips[i + 1].at - c.at).toFixed(3);
else if (c.at + c.dur > end + 0.02) { console.log(`${id}: clip ${path.basename(c.src, '.mp4')} runs ${(c.at + c.dur - end).toFixed(2)}s past the segment end; cut there`); c.dur = +(end - c.at).toFixed(3); }
});
clips.forEach((c, i) => {
const n = clips[i + 1];
if (n && c.at + c.dur >= n.at - 1e-3) { delete c.out; delete n.in; }
for (const k of ['in', 'out']) if (c[k]) c[k].dur = +Math.min(c[k].dur, c.dur / 2).toFixed(3);
});
for (const c of clips) if (!fs.existsSync(cfg.abs(c.src))) console.log(`${id}: ${c.src} missing; run overlay.mjs --preview`);
const audio = tm?.gapAudio || path.join(cfg.dirs.audio, `${id}.${cfg.voice.format || 'wav'}`);
return {
id,
bundle: rel(path.join(cfg.dirs.bundles, id)),
...(fs.existsSync(cfg.abs(audio)) ? { audio: rel(audio) } : {}),
...(tm ? { lines: rel(path.join(cfg.dirs.timing, `${id}.json`)) } : {}),
note: notes[id] || '',
...(clips.length ? { clips } : {}),
};
});
// footage.layer 为 under 时页面把实拍画在代码画面下面(包要透明:bundle.alpha)
const caption = cfg.preview?.caption ?? cfg.captions?.style;
writeJson(cfg.abs('preview.json'), { ...(caption ? { caption } : {}), ...(cfg.footage?.layer === 'under' ? { clipsLayer: 'under' } : {}), segments });
if (missing.length) console.log(`no timing yet for ${missing.join(', ')}; those play on the page clock`);
console.log(segments.map(s => `${s.id}${s.clips ? ` clips:${s.clips.length}` : ''}`).join(' '));
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 |