Files
yaoayanui/src/config/subtitleTemplates.js
fengchuanhn@gmail.com 3b0a8d777c 11
2026-05-21 00:19:08 +08:00

64 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 字幕样式预设(对齐 Electron 常用底部白字黑边,供 ffmpeg force_style */
export const SUBTITLE_TEMPLATES = [
{
id: "default",
label: "默认白字黑边",
fontName: "Microsoft YaHei",
fontSize: 24,
primaryColor: "#FFFFFF",
outlineColor: "#000000",
outline: 2,
marginV: 40,
},
{
id: "large",
label: "大号字幕",
fontName: "Microsoft YaHei",
fontSize: 32,
primaryColor: "#FFFFFF",
outlineColor: "#000000",
outline: 3,
marginV: 48,
},
{
id: "yellow",
label: "黄色强调",
fontName: "Microsoft YaHei",
fontSize: 26,
primaryColor: "#FFD700",
outlineColor: "#000000",
outline: 2,
marginV: 42,
},
];
/**
* @param {string} templateId
*/
export function getSubtitleTemplate(templateId) {
return (
SUBTITLE_TEMPLATES.find((t) => t.id === templateId) ||
SUBTITLE_TEMPLATES[0]
);
}
/**
* @param {{ fontName?: string, fontSize?: number, primaryColor?: string, outlineColor?: string, outline?: number, marginV?: number }} tpl
*/
export function buildFfmpegForceStyle(tpl) {
const hexToAss = (hex) => {
const h = hex.replace("#", "");
const r = h.substring(0, 2);
const g = h.substring(2, 4);
const b = h.substring(4, 6);
return `&H00${b}${g}${r}`.toUpperCase();
};
const fontName = tpl.fontName || "Microsoft YaHei";
const fontSize = tpl.fontSize || 24;
const primary = hexToAss(tpl.primaryColor || "#FFFFFF");
const outline = hexToAss(tpl.outlineColor || "#000000");
const outlineW = tpl.outline ?? 2;
const marginV = tpl.marginV ?? 40;
return `FontName=${fontName},FontSize=${fontSize},PrimaryColour=${primary},OutlineColour=${outline},Outline=${outlineW},Alignment=2,MarginV=${marginV}`;
}