qiaomu-cut
Verified把一句话需求转成可复现、可验收视频工程的乔木智能剪辑导演。Use when the user asks to create, plan, edit, remix, explain, narrate, subtitle, animate, composite, or render a video—including one-line requests such as “制作一个科普视频:介绍 LLM 中的 RL”. Builds English-learning movie mixes, person profiles, explainers, code-drawn motion graphics (UI morph loops, showreels, kinetic-type promos, line-art/pixel/Three.js animation, lyric MVs), product launch videos, cinematic shorts, social clips, course/PPT videos, AI image/video/TTS/music-assisted stories, stock-footage stories, or multi-source montage. Routes across 33台词, ClipSeek/open media, local files, ListenHub, image generation, HTML/SVG/Canvas motion graphics with beat-grid storyboards and determinism probes, Manim, ffmpeg-full, captions, sound design, frame-0 video covers with YouTube thumbnails, and release checks.
scripts/renderers/bilingual_ass.js
View on GitHub#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const STYLE_ORDER = [
'English',
'Chinese',
'Note',
'Source',
'Card',
'CardChinese',
'BigWord',
'BigChinese'
];
function number(value, fallback) {
const parsed = Number(value);
return Number.isFinite(parsed) ? parsed : fallback;
}
function assColor(value, fallback) {
const text = String(value || '').trim();
return /^&H[0-9A-Fa-f]{6,8}&?$/.test(text) ? text.replace(/&$/, '') : fallback;
}
function fontFamily(value) {
const text = String(value || 'Noto Sans CJK SC').replace(/[,\r\n{}\\]/g, '').trim();
return text || 'Noto Sans CJK SC';
}
function assTime(seconds) {
const centiseconds = Math.max(0, Math.round(number(seconds, 0) * 100));
const hours = Math.floor(centiseconds / 360000);
const minutes = Math.floor(centiseconds / 6000) % 60;
const secs = Math.floor(centiseconds / 100) % 60;
const cs = centiseconds % 100;
return `${hours}:${String(minutes).padStart(2, '0')}:${String(secs).padStart(2, '0')}.${String(cs).padStart(2, '0')}`;
}
function escapePlain(text) {
return String(text == null ? '' : text)
.replace(/\\/g, '\\\\')
.replace(/[{}]/g, '')
.replace(/\r?\n/g, '\\N');
}
function renderText(text, style, highlightColor) {
const pieces = String(text == null ? '' : text).split(/(\[\[.*?\]\])/gs);
return pieces.map((piece) => {
if (piece.startsWith('[[') && piece.endsWith(']]')) {
const content = escapePlain(piece.slice(2, -2));
return `{\\c${highlightColor}\\b1}${content}{\\r${style}}`;
}
return escapePlain(piece);
}).join('');
}
function animationType(event) {
if (!event || !event.animation) return 'fade';
if (typeof event.animation === 'string') return event.animation;
return event.animation.type || 'fade';
}
function inferredSegments(text) {
const value = String(text == null ? '' : text);
if (/\s/.test(value)) {
return value.split(/(\s+)/).filter(Boolean).map((part) => ({ text: part }));
}
return Array.from(value).map((part) => ({ text: part }));
}
function karaokeText(event, theme = {}) {
const segments = Array.isArray(event.segments) && event.segments.length
? event.segments
: inferredSegments(event.text);
const totalCentiseconds = Math.max(1, Math.round((number(event.end, 0) - number(event.start, 0)) * 100));
const weights = segments.map((segment) => Math.max(0.01,
number(segment.durationMs, number(segment.duration, 1) * (segment.durationMs == null ? 1 : 0.001))
));
const weightTotal = weights.reduce((sum, value) => sum + value, 0);
let remaining = totalCentiseconds;
const highlight = `${assColor(theme.highlight, '&H0042B9F4')}&`;
const pending = `${assColor(theme.karaokePending, '&H00D3D6DC')}&`;
const text = segments.map((segment, index) => {
const duration = index === segments.length - 1
? Math.max(1, remaining)
: Math.max(1, Math.round(totalCentiseconds * weights[index] / weightTotal));
remaining -= duration;
return `{\\kf${duration}}${escapePlain(segment.text)}`;
}).join('');
return `{\\1c${highlight}\\2c${pending}}${text}`;
}
function expandCues(cues, options = {}) {
const events = [];
for (const cue of cues || []) {
const common = {
start: cue.start,
end: cue.end,
pos: cue.pos
};
if (cue.english) events.push({ ...common, layer: 2, style: cue.englishStyle || 'English', text: cue.english });
if (cue.chinese) events.push({ ...common, layer: 1, style: cue.chineseStyle || 'Chinese', text: cue.chinese });
if (cue.note) events.push({ ...common, layer: 0, style: cue.noteStyle || 'Note', text: cue.note });
if (cue.source && options.showSource === true) events.push({ ...common, layer: 3, style: 'Source', text: cue.source });
}
return events;
}
function styleValues(document, options) {
const width = Math.max(320, Math.round(number(options.width, 1080)));
const height = Math.max(240, Math.round(number(options.height, 1920)));
const scale = height / 1920;
const horizontalScale = Math.min(1.2, Math.max(0.72, width / 1080));
const typeScale = Math.min(scale, horizontalScale);
const size = (base, minimum = 20) => Math.max(minimum, Math.round(base * typeScale));
const margin = (ratio, minimum = 20) => Math.max(minimum, Math.round(height * ratio));
// TikTok's official 720x1280 in-feed LTR template marks 80 px left,
// 120 px right, 160 px top, and 440 px bottom as UI risk areas.
// Scale those asymmetric horizontal bounds to the active canvas.
const safeLeft = Math.max(48, Math.round(width * (80 / 720)));
const safeRight = Math.max(48, Math.round(width * (120 / 720)));
const fonts = document.fonts || {};
const font = fontFamily(document.font || options.font || 'Noto Sans CJK SC');
const englishFont = fontFamily(fonts.english || font);
const chineseFont = fontFamily(fonts.chinese || font);
const titleFont = fontFamily(fonts.title || chineseFont);
const theme = document.theme || {};
const primary = assColor(theme.primary, '&H00FFFFFF');
const secondary = assColor(theme.secondary, '&H00E8E2D8');
const outline = assColor(theme.outline, '&HCC101010');
const back = assColor(theme.back, '&H70000000');
return {
English: [englishFont, size(88, 38), primary, outline, back, 1, 0.4, 5, 1, 2, safeLeft, safeRight, margin(500 / 1920)],
Chinese: [chineseFont, size(72, 34), secondary, outline, back, 1, 0.2, 4, 0, 2, safeLeft, safeRight, margin(360 / 1920)],
Note: [titleFont, size(76, 34), assColor(theme.note, '&H00FFFFFF'), '&H99101010', '&H60000000', 1, 1.2, 4, 1, 8, safeLeft, safeRight, margin(560 / 1920)],
Source: [font, size(46, 24), assColor(theme.source, '&H00C1C7C9'), '&HAA101010', '&H60000000', 0, 0.3, 3, 0, 7, safeLeft, safeRight, margin(280 / 1920)],
Card: [font, size(76, 32), primary, outline, '&H80000000', 1, 1, 4, 1, 5, safeLeft, safeRight, 0],
CardChinese: [font, size(46, 24), secondary, outline, '&H80000000', 0, 0.3, 3, 0, 5, safeLeft, safeRight, 0],
BigWord: [font, size(106, 42), primary, outline, '&H85000000', 1, 1.4, 5, 1, 5, safeLeft, safeRight, 0],
BigChinese: [font, size(50, 26), secondary, outline, '&H85000000', 0, 0.3, 3, 0, 5, safeLeft, safeRight, 0]
};
}
function styleLine(name, values) {
const [font, fontSize, primary, outline, back, bold, spacing, outlineWidth, shadow, alignment, marginL, marginR, marginV] = values;
return `Style: ${name},${font},${fontSize},${primary},&H000000FF,${outline},${back},${bold},0,0,0,100,100,${spacing},0,1,${outlineWidth},${shadow},${alignment},${marginL},${marginR},${marginV},1`;
}
function header(document, options = {}) {
const width = Math.max(320, Math.round(number(options.width, 1080)));
const height = Math.max(240, Math.round(number(options.height, 1920)));
const styles = styleValues(document, { ...options, width, height });
const styleLines = STYLE_ORDER.map((name) => styleLine(name, styles[name]));
return `[Script Info]
Title: ${escapePlain(document.title || 'QiaoCut bilingual captions')}
ScriptType: v4.00+
PlayResX: ${width}
PlayResY: ${height}
WrapStyle: 0
ScaledBorderAndShadow: yes
YCbCr Matrix: TV.709
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
${styleLines.join('\n')}
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
`;
}
function eventLine(event, document = {}) {
const style = STYLE_ORDER.includes(event.style) ? event.style : 'English';
const theme = document.theme || {};
const animation = animationType(event);
const tags = [];
if (animation !== 'none') {
tags.push(`\\fad(${Math.max(0, Math.round(number(event.fadeInMs, 120)))},${Math.max(0, Math.round(number(event.fadeOutMs, 140)))})`);
}
const width = Math.max(320, Math.round(number(document.width, 1080)));
const height = Math.max(240, Math.round(number(document.height, 1920)));
const coordinateWidth = Math.max(1, number(document.coordinateWidth, width));
const coordinateHeight = Math.max(1, number(document.coordinateHeight, height));
const coordinateScaleX = width / coordinateWidth;
const coordinateScaleY = height / coordinateHeight;
if (style === 'BigWord') tags.push(`\\pos(${Math.round(width / 2)},${Math.round(height * 0.469)})`);
if (style === 'BigChinese') tags.push(`\\pos(${Math.round(width / 2)},${Math.round(height * 0.547)})`);
if (style === 'Card') tags.push(`\\pos(${Math.round(width / 2)},${Math.round(height * 0.453)})`);
if (style === 'CardChinese') tags.push(`\\pos(${Math.round(width / 2)},${Math.round(height * 0.526)})`);
if (Array.isArray(event.pos) && event.pos.length === 2) {
const x = Math.round(number(event.pos[0], coordinateWidth / 2) * coordinateScaleX);
const y = Math.round(number(event.pos[1], coordinateHeight / 2) * coordinateScaleY);
const slideOffset = Math.max(1, Math.round(42 * coordinateScaleY));
if (animation === 'slide-up') tags.push(`\\move(${x},${y + slideOffset},${x},${y},0,220)`);
else tags.push(`\\pos(${x},${y})`);
}
if (animation === 'pop') {
tags.push('\\fscx72\\fscy72\\t(0,180,\\fscx100\\fscy100)');
}
const body = animation === 'karaoke' || animation === 'word-follow' || animation === 'typewriter'
? karaokeText(event, theme)
: renderText(event.text, style, `${assColor(theme.highlight, '&H0042B9F4')}&`);
const text = `{${tags.join('')}}${body}`;
return `Dialogue: ${Math.round(number(event.layer, 0))},${assTime(event.start)},${assTime(event.end)},${style},,0,0,0,,${text}`;
}
function validateEvents(events) {
const animations = new Set(['fade', 'none', 'pop', 'slide-up', 'karaoke', 'word-follow', 'typewriter']);
for (const [index, event] of events.entries()) {
const start = number(event.start, NaN);
const end = number(event.end, NaN);
if (!Number.isFinite(start) || !Number.isFinite(end) || start < 0 || end <= start) {
throw new Error(`Caption event ${index + 1} must have finite start/end with 0 <= start < end.`);
}
if (typeof event.text !== 'string' || !event.text.trim()) {
throw new Error(`Caption event ${index + 1} has no text.`);
}
const animation = animationType(event);
if (!animations.has(animation)) throw new Error(`Caption event ${index + 1} has unsupported animation: ${animation}.`);
if (event.segments != null) {
if (!Array.isArray(event.segments) || event.segments.length === 0) {
throw new Error(`Caption event ${index + 1} segments must be a non-empty array.`);
}
for (const segment of event.segments) {
if (!segment || typeof segment.text !== 'string' || !segment.text) {
throw new Error(`Caption event ${index + 1} contains an invalid segment.`);
}
}
}
}
}
function generateBilingualAss(document, options = {}) {
if (!document || typeof document !== 'object' || Array.isArray(document)) {
throw new Error('Caption JSON must be an object with events or cues.');
}
const events = [
...(Array.isArray(document.events) ? document.events : []),
...expandCues(Array.isArray(document.cues) ? document.cues : [], document)
];
validateEvents(events);
const renderingDocument = {
...document,
font: options.font || document.font,
width: number(options.width, document.width || 1080),
height: number(options.height, document.height || 1920),
coordinateWidth: number(options.coordinateWidth, document.coordinateWidth || document.width || options.width || 1080),
coordinateHeight: number(options.coordinateHeight, document.coordinateHeight || document.height || options.height || 1920)
};
return header(renderingDocument, renderingDocument) + events.map((event) => eventLine(event, renderingDocument)).join('\n') + '\n';
}
function readCaptionDocument(file) {
return JSON.parse(fs.readFileSync(file, 'utf8'));
}
function main(argv = process.argv.slice(2)) {
const [input, output, width, height] = argv;
if (!input || !output) {
process.stderr.write('Usage: bilingual_ass.js captions.json subtitles.ass [width] [height]\n');
process.exitCode = 2;
return;
}
const document = readCaptionDocument(path.resolve(input));
const ass = generateBilingualAss(document, { width, height });
const absoluteOutput = path.resolve(output);
fs.mkdirSync(path.dirname(absoluteOutput), { recursive: true });
fs.writeFileSync(absoluteOutput, ass, 'utf8');
process.stdout.write(`${absoluteOutput}\n`);
}
module.exports = {
STYLE_ORDER,
assTime,
escapePlain,
expandCues,
generateBilingualAss,
karaokeText,
readCaptionDocument,
renderText
};
if (require.main === module) {
try {
main();
} catch (error) {
process.stderr.write(`${error.message}\n`);
process.exitCode = 1;
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |