feat: AI生图提示词翻译成英文后再发往上流(img2img 全链路 + 视频/设置改动)
This commit is contained in:
1 parent
76d9d45770
commit
b6e0c475d3
9 files changed
+1169
-34
No files matched your search
@@ -30,6 +30,16 @@ const DEFAULTS = {
|
||||
apiKey: '',
|
||||
model: ''
|
||||
}
|
||||
},
|
||||
// AI 视频:一句话/文本/网页/文档 → 带字幕配音的成片
|
||||
// provider='inherit' 复用上面的 AI 生图配置;'custom' 用下面自定义的文本模型
|
||||
videoai: {
|
||||
provider: 'inherit',
|
||||
custom: {
|
||||
url: '',
|
||||
model: '',
|
||||
apiKey: ''
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -64,6 +74,14 @@ function getSettings() {
|
||||
apiKey: (data.imagegen && data.imagegen.custom && data.imagegen.custom.apiKey) || '',
|
||||
model: (data.imagegen && data.imagegen.custom && data.imagegen.custom.model) || ''
|
||||
}
|
||||
},
|
||||
videoai: {
|
||||
provider: (data.videoai && data.videoai.provider) === 'custom' ? 'custom' : 'inherit',
|
||||
custom: {
|
||||
url: (data.videoai && data.videoai.custom && data.videoai.custom.url) || '',
|
||||
model: (data.videoai && data.videoai.custom && data.videoai.custom.model) || '',
|
||||
apiKey: (data.videoai && data.videoai.custom && data.videoai.custom.apiKey) || ''
|
||||
}
|
||||
}
|
||||
};
|
||||
} catch (e) {
|
||||
@@ -108,6 +126,19 @@ function saveSettings(settings) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (settings.videoai) {
|
||||
const va = settings.videoai;
|
||||
if (va.provider === 'custom' || va.provider === 'inherit') merged.videoai.provider = va.provider;
|
||||
if (va.custom) {
|
||||
if (typeof va.custom.url === 'string') merged.videoai.custom.url = va.custom.url.trim();
|
||||
if (typeof va.custom.model === 'string') merged.videoai.custom.model = va.custom.model.trim();
|
||||
const vk = va.custom.apiKey;
|
||||
// 空串/掩码 = 保持原密钥
|
||||
if (typeof vk === 'string' && vk.trim() && !vk.includes('***')) {
|
||||
merged.videoai.custom.apiKey = vk.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(p, JSON.stringify(merged, null, 2));
|
||||
return merged;
|
||||
}
|
||||
@@ -119,4 +150,36 @@ function maskKey(key) {
|
||||
return `${key.slice(0, 4)}***${key.slice(-4)}`;
|
||||
}
|
||||
|
||||
module.exports = { getSettings, saveSettings, maskKey, settingsPath };
|
||||
/**
|
||||
* 解析 AI 视频使用的文本大模型配置
|
||||
* - 设置-AI 视频里选了「自定义」且填了地址 → 用自定义
|
||||
* - 否则复用 AI 生图配置(内置 NewAPI / 自定义提供商)
|
||||
* 普通文本模型(chat/completions)即可,全流程由后端写分镜、TTS 配音、合成字幕。
|
||||
*/
|
||||
function resolveVideoGen(settings) {
|
||||
const s = settings || getSettings();
|
||||
const va = (s && s.videoai) || {};
|
||||
const ig = (s && s.imagegen) || {};
|
||||
const defModel = process.env.NEWAPI_TEXT_MODEL || 'mimo-v2.6-flash';
|
||||
if (va.provider === 'custom' && va.custom && va.custom.url) {
|
||||
return {
|
||||
url: String(va.custom.url).replace(/\/+$/, ''),
|
||||
model: va.custom.model || defModel,
|
||||
apiKey: va.custom.apiKey || process.env.NEWAPI_KEY || ''
|
||||
};
|
||||
}
|
||||
if (ig.provider === 'custom' && ig.custom) {
|
||||
return {
|
||||
url: String(ig.custom.url || '').replace(/\/+$/, ''),
|
||||
model: ig.custom.model || defModel,
|
||||
apiKey: ig.custom.apiKey || process.env.NEWAPI_KEY || ''
|
||||
};
|
||||
}
|
||||
return {
|
||||
url: String((ig.newapi && ig.newapi.url) || 'http://192.168.68.19:3099/v1').replace(/\/+$/, ''),
|
||||
model: defModel,
|
||||
apiKey: ((ig.newapi && ig.newapi.apiKey) || process.env.NEWAPI_KEY || '')
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { getSettings, saveSettings, maskKey, settingsPath, resolveVideoGen };
|
||||
@@ -365,17 +365,21 @@ async function stripSubtitleAudio(input, output, { removeAudio = true, removeSub
|
||||
* AI 生成视频素材装配(分段:图 + 该段字幕 + 该段配音)
|
||||
* @param {object} seg { imagePath, subtitle, ttsFile, duration } duration=该段秒数
|
||||
*/
|
||||
async function buildSegment(seg, outPath, { width = 1920, height = 1080, fontSizePct = 5 } = {}) {
|
||||
async function buildSegment(seg, outPath, { width = 1920, height = 1080, fontSizePct = 5, subtitleStyle = {} } = {}) {
|
||||
const dir = tmpDir();
|
||||
try {
|
||||
const tFile = path.join(dir, 'sub.txt');
|
||||
fs.writeFileSync(tFile, seg.subtitle || '', 'utf8');
|
||||
const textFile = tFile;
|
||||
const fontSize = Math.max(12, Math.round((height * fontSizePct) / 100));
|
||||
const fontSize = Math.max(12, Math.round((height * (subtitleStyle.fontSizePct || fontSizePct)) / 100));
|
||||
const color = subtitleStyle.color || 'white';
|
||||
const pos = subtitleStyle.position || 'bottom-center';
|
||||
const yExpr = pos.startsWith('top') ? 'h*0.07' : pos === 'center' ? '(h-text_h)/2' : 'h-text_h-h*0.07';
|
||||
const xExpr = pos.endsWith('left') ? 'w*0.05' : pos.endsWith('right') ? 'w-text_w-w*0.05' : '(w-text_w)/2';
|
||||
const vf = [
|
||||
`scale=${width}:${height}:force_original_aspect_ratio=decrease`,
|
||||
`pad=${width}:${height}:(ow-iw)/2:(oh-ih)/2:color=black`,
|
||||
`drawtext=fontfile=/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc:textfile=${textFile}:fontsize=${fontSize}:fontcolor=white@0.95:borderw=2:bordercolor=black@0.6:x=(w-text_w)/2:y=h-text_h-h*0.07:line_spacing=8`
|
||||
`drawtext=fontfile=/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc:textfile=${textFile}:fontsize=${fontSize}:fontcolor=${color}@0.95:borderw=2:bordercolor=black@0.6:x=${xExpr}:y=${yExpr}:line_spacing=8`
|
||||
].join(',');
|
||||
|
||||
const args = [
|
||||
|
||||
Reference in new issue
Block a user