JimLiu/baocut / skills/baocut
baocut
Flagged用 BaoCut 处理视频与音频:转录、字幕、翻译、配音、剪口播、切短视频、分章、总结写稿、从链接下载、压缩转码、导出成片,或从零做一条成片。有媒体文件、视频链接、字幕文件或 BaoCut 视频时用;只翻译纯文本、与视频无关的写作或作图、别的剪辑器与 FFmpeg 的用法、BaoCut 源码开发不用。
references/craft/virtual-host/scripts/puppet-mask.mjs
View on GitHub#!/usr/bin/env node
// i18n-ignore-file: 给智能体拷走用的独立脚本,日志与报错写英文
// The mask for the bald repaint: the portrait's hair (as puppet-build.mjs finds it, or as the part map paints it),
// grown 4 px, as strokes for the retouch tool's repaint (`mask: { strokes }`). Plain Node >= 22.
//
// node puppet-mask.mjs <character.json> [out.json]
//
// Reads "portrait" and "partmap" (or, without a part map, "skin" / "line" / "hair" when set) from character.json. Writes out.json (default: hair-mask.json next
// to character.json) and out.png, the mask to look at: white is what gets repainted.
import fs from 'node:fs';
import path from 'node:path';
import { readImage, writeGray } from './puppet/png.mjs';
import { segment } from './puppet/segment.mjs';
import { maskStrokes, keyOut } from './puppet/seg.mjs';
import { dilate, count, bbox, or } from './puppet/ops.mjs';
import { readLabels, part } from './puppet/partmap.mjs';
// what the retouch tool takes
const MAX_STROKES = 500, MAX_SHARE = 0.6;
const [cfgArg, outArg] = process.argv.slice(2);
if (!cfgArg) {
console.error('usage: node puppet-mask.mjs <character.json> [out.json]');
process.exit(2);
}
const cfgPath = path.resolve(cfgArg);
const cfg = JSON.parse(fs.readFileSync(cfgPath, 'utf8'));
if (!cfg.portrait) {
console.error('FIX config: "portrait" is required');
process.exit(1);
}
const out = path.resolve(outArg ?? path.join(path.dirname(cfgPath), 'hair-mask.json'));
const im = readImage(path.resolve(path.dirname(cfgPath), cfg.portrait)), { w, h } = im;
let hair;
if (cfg.partmap) {
const pm = readImage(path.resolve(path.dirname(cfgPath), cfg.partmap));
if (pm.w !== w || pm.h !== h) {
console.error(`FIX part map: ${pm.w}x${pm.h}, the portrait is ${w}x${h}; ask for the same size`);
process.exit(1);
}
const { lab } = readLabels(im, pm, keyOut(im));
hair = or(or(part(lab, 'front'), part(lab, 'side')), part(lab, 'back'));
} else {
try {
hair = segment(im, { skin: cfg.skin, line: cfg.line, hair: cfg.hair, glasses: cfg.glasses }).hair;
} catch (e) {
console.error(`FIX portrait: ${e.message}`);
process.exit(1);
}
}
const m = dilate(hair, w, h, 4);
const share = count(m) / (w * h);
if (share > MAX_SHARE) {
console.error(`FIX the hair mask covers ${(100 * share).toFixed(1)}% of the image (the repaint takes at most 60%): make the character smaller in the frame`);
process.exit(1);
}
// one stroke per run of each row band; coarser bands until the count fits (a stroke's radius covers its band)
let step = 4, strokes = maskStrokes(m, w, h, step, 3);
while (strokes.length > MAX_STROKES) {
step += 2;
strokes = maskStrokes(m, w, h, step, Math.ceil(step / 2) + 1);
}
fs.writeFileSync(out, JSON.stringify({ strokes }) + '\n');
writeGray(out.replace(/\.json$/, '') + '.png', w, h, m.map((v) => v * 255));
console.log(`ok hair mask: ${count(hair)} px of hair in ${bbox(hair, w, h)}, ${(100 * share).toFixed(1)}% of the image, ${strokes.length} strokes -> ${out}`);
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 |