11
This commit is contained in:
63
src/config/subtitleTemplates.js
Normal file
63
src/config/subtitleTemplates.js
Normal file
@@ -0,0 +1,63 @@
|
||||
/** 字幕样式预设(对齐 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}`;
|
||||
}
|
||||
Reference in New Issue
Block a user