v1.4.19: AI视频两步生成文案 + 模型默认值/免费注册引导
This commit is contained in:
1 parent
9c7b695081
commit
71c5d25862
7 files changed
+160
-22
No files matched your search
@@ -1,5 +1,11 @@
|
||||
# 更新日志
|
||||
|
||||
## 2026-11-23 → v1.4.19
|
||||
|
||||
- ✨ **AI 视频「模型提供商」默认值**:设置 → AI 视频 选「单独配置提供商 / 模型 / Key」时,接口地址默认填 `https://ai.88531.cn/v1`、模型默认填 `mimo-v2.6-flash`(后端 DEFAULTS 与前端兜底同步,新装/未配置即开箱可用)
|
||||
- ✨ **免费注册额度引导**:该面板新增蓝色引导卡——没有 API Key 可前往 ai.88531.cn 免费注册(注册送体验金、每天签到再领 ¥0.5),登录后在「令牌」页创建 Key 粘贴即可
|
||||
- ✨ **AI 生成文案两步流程**:生成弹窗标题行新增「AI 生成文案」按钮,一键出分镜文案到可编辑文本框;点「开始生成」按**你编辑后的文案**原样出片(后端新增 `/api/video/gen-script`,`script` 字段直通分镜,不再被 LLM 改写、不循环朗读、不虚增段数)
|
||||
|
||||
## 2026-11-19 → v1.4.14
|
||||
|
||||
- ✨ **灯箱只显示图片**:双击图片打开灯箱后,底部缩略图条只列出当前文件夹(含筛选)下的图片,mp4/md 等打不开的文件不再混入(此前显示出来也点不开,纯属干扰)
|
||||
|
||||
@@ -430,6 +430,84 @@ router.post(
|
||||
})
|
||||
);
|
||||
|
||||
// ---------- 按标题快速生成文案(可编辑,生成视频时严格按此文案分镜) ----------
|
||||
/** 把整段文案切成逐句分镜:按行优先,长行再按句读符号切 */
|
||||
function splitCopyToScenes(text) {
|
||||
const raw = String(text || '').replace(/\r/g, '').split('\n').map((s) => s.trim()).filter(Boolean);
|
||||
const out = [];
|
||||
for (let line of raw) {
|
||||
line = line.replace(/^\d+\s*[.、))]\s*/, ''); // 去掉序号
|
||||
if (!line) continue;
|
||||
if (line.length <= 45) { out.push(line); continue; }
|
||||
const parts = line.split(/(?<=[。!?!?;;])/).map((s) => s.trim()).filter(Boolean);
|
||||
if (parts.length > 1) out.push(...parts);
|
||||
else out.push(line);
|
||||
}
|
||||
return out.slice(0, 40).map((s) => ({
|
||||
subtitle: s.slice(0, 40),
|
||||
tts: s.slice(0, 120)
|
||||
}));
|
||||
}
|
||||
|
||||
router.post(
|
||||
'/gen-script',
|
||||
asyncHandler(async (req, res) => {
|
||||
const { title, duration = 0, count = 0 } = req.body || {};
|
||||
const t = String(title || '').trim();
|
||||
if (!t) throw new ValidationError('请填写视频标题');
|
||||
|
||||
const settings = getSettings();
|
||||
const gen = resolveVideoGen(settings);
|
||||
const url = String(gen.url || '').replace(/\/+$/, '');
|
||||
const key = gen.apiKey || process.env.NEWAPI_KEY || '';
|
||||
const model = gen.model || 'mimo-v2.6-flash';
|
||||
if (!url) throw new ValidationError('AI 视频未配置:请在右上角「设置 → AI 视频」里填写 Base URL');
|
||||
if (!key) throw new ValidationError('AI 视频未配置 API Key:请在右上角「设置 → AI 视频」里填写');
|
||||
|
||||
const targetSec = Math.min(600, Math.max(0, Number(duration) || 0));
|
||||
const lineCount = Number(count) > 0
|
||||
? Math.min(30, Number(count))
|
||||
: (targetSec ? Math.min(30, Math.max(2, Math.ceil(targetSec / 5))) : 6);
|
||||
|
||||
const sys = '你是短视频编导。根据标题写出可直接朗读的短视频旁白文案。要求口语化、有画面感、避免空话。';
|
||||
const user = [
|
||||
`标题:${t}`,
|
||||
`共 ${lineCount} 个画面,每行对应一个画面的旁白。`,
|
||||
targetSec ? `视频总时长约 ${targetSec} 秒,文案总字数控制在 ${Math.round(targetSec * 3.5)} 字左右。` : '',
|
||||
'严格只输出文案本身:每行一句,不要编号、不要引号、不要小标题、不要代码块标记;每行不超过 40 个字。'
|
||||
].filter(Boolean).join('\n');
|
||||
|
||||
const resp = await fetch(`${url}/chat/completions`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer' + ' ' + key },
|
||||
body: JSON.stringify({
|
||||
model,
|
||||
messages: [
|
||||
{ role: 'system', content: sys },
|
||||
{ role: 'user', content: user }
|
||||
],
|
||||
temperature: 0.7,
|
||||
max_tokens: 2000
|
||||
}),
|
||||
signal: AbortSignal.timeout(60 * 1000)
|
||||
});
|
||||
if (!resp.ok) {
|
||||
let msg = `模型接口错误 (${resp.status})`;
|
||||
try { const j = await resp.json(); msg = (j.error && j.error.message) || j.message || msg; } catch (_) { /* 非 JSON */ }
|
||||
throw new Error(msg);
|
||||
}
|
||||
const data = await resp.json();
|
||||
const raw = data.choices && data.choices[0] && data.choices[0].message && data.choices[0].message.content;
|
||||
if (!raw) throw new Error('模型未返回内容');
|
||||
const script = String(raw)
|
||||
.replace(/^```[a-z]*\s*/i, '').replace(/```\s*$/, '')
|
||||
.split('\n').map((s) => s.trim().replace(/^\d+\s*[.、))]\s*/, '')).filter(Boolean)
|
||||
.slice(0, 40).join('\n');
|
||||
if (!script) throw new Error('模型未返回文案');
|
||||
res.json({ success: true, script });
|
||||
})
|
||||
);
|
||||
|
||||
// ---------- 文本源 AI 生成视频(提示词/URL/文档) ----------
|
||||
const textTasks = new Map();
|
||||
let textTaskSeq = 0;
|
||||
@@ -477,7 +555,8 @@ router.post(
|
||||
setTimeout(() => textTasks.delete(id), 30 * 60 * 1000);
|
||||
|
||||
const durSec = Math.min(600, Math.max(0, Number(duration) || 0)); // 目标时长(秒),0=自动
|
||||
runTextVideo({ task, library, title: String(title).trim(), content: text, images, url, key, model: mdl, voice, width: Number.isFinite(w)?w:1920, height: Number.isFinite(h)?h:1080, extraPrompt: String(extraPrompt||''), saveDir: String(saveDir||''), transition: trans, duration: durSec, subtitleStyle: subtitleStyle||{}, req }).catch((err) => {
|
||||
const userScript = String(req.body.script || '').trim().slice(0, 8000); // 用户已编辑的文案:原样分镜,不改写
|
||||
runTextVideo({ task, library, title: String(title).trim(), content: text, script: userScript, images, url, key, model: mdl, voice, width: Number.isFinite(w)?w:1920, height: Number.isFinite(h)?h:1080, extraPrompt: String(extraPrompt||''), saveDir: String(saveDir||''), transition: trans, duration: durSec, subtitleStyle: subtitleStyle||{}, req }).catch((err) => {
|
||||
task.status = 'error'; task.error = err.message || String(err);
|
||||
});
|
||||
res.json({ success: true, taskId: id });
|
||||
@@ -520,7 +599,12 @@ async function runTextVideo(ctx) {
|
||||
task.step = 'script'; task.stepLabel = '正在生成脚本'; task.progress = 5;
|
||||
let script = [];
|
||||
const targetDur0 = Number(ctx.duration) > 0 ? Number(ctx.duration) : 0;
|
||||
if (content) {
|
||||
const userScript = String(ctx.script || '').trim();
|
||||
if (userScript) {
|
||||
// 用户已编辑的文案:原样按行切分成镜,绝不改写
|
||||
script = splitCopyToScenes(userScript);
|
||||
logger.info(`📝 使用用户文案直通分镜 ${script.length} 段(不改写)`);
|
||||
} else if (content) {
|
||||
// 让模型按内容生成 N 段(N = min(8, 句子数))
|
||||
const sentences = content.split(/[。!?.!?]/).map(s=>s.trim()).filter(Boolean);
|
||||
const baseN = Math.min(8, Math.max(2, sentences.length));
|
||||
@@ -535,10 +619,10 @@ async function runTextVideo(ctx) {
|
||||
// TTS + segments:每段轮换使用选中图片,保证所有图片都出现
|
||||
const segments = [];
|
||||
let segCount = Math.max(script.length, imagePaths.length);
|
||||
if (targetDur0 > 0) segCount = Math.max(segCount, Math.min(30, Math.ceil(targetDur0 / 5))); // 按目标时长补齐段数
|
||||
if (targetDur0 > 0 && !userScript) segCount = Math.max(segCount, Math.min(30, Math.ceil(targetDur0 / 5))); // 时长越长分镜越多(仅自动文案时)
|
||||
for (let i = 0; i < segCount; i++) {
|
||||
task.step = 'tts'; task.stepLabel = `正在朗读 ${i+1}/${segCount}`; task.progress = 10 + Math.round((i/segCount)*40);
|
||||
const seg = script[i % script.length] || {};
|
||||
const seg = userScript ? (script[i] || {}) : (script[i % script.length] || {}); // 用户文案不循环重复朗读
|
||||
let ttsFile = ''; let dur = 0;
|
||||
if (seg.tts) {
|
||||
try {
|
||||
@@ -546,7 +630,7 @@ async function runTextVideo(ctx) {
|
||||
ttsFile = t.file; dur = t.seconds;
|
||||
} catch (e) { logger.warn('TTS fail: ' + e.message); }
|
||||
}
|
||||
segments.push({ imagePath: imagePaths[i % imagePaths.length], subtitle: seg.subtitle || seg.tts || title, ttsFile, ttsSeconds: dur, duration: Math.max(2.5, Math.min(12, dur || 4)) });
|
||||
segments.push({ imagePath: imagePaths[i % imagePaths.length], subtitle: seg.subtitle || seg.tts || (userScript ? '' : title), ttsFile, ttsSeconds: dur, duration: Math.max(2.5, Math.min(12, dur || 4)) });
|
||||
}
|
||||
|
||||
// 目标时长:画面段总长 = 目标 + 转场重叠(xfade 每次吃掉 0.6s),
|
||||
|
||||
@@ -33,12 +33,13 @@ const DEFAULTS = {
|
||||
}
|
||||
},
|
||||
// AI 视频:一句话/文本/网页/文档 → 带字幕配音的成片
|
||||
// provider='inherit' 复用上面的 AI 生图配置;'custom' 用下面自定义的文本模型
|
||||
// provider='custom' 用下面的文本模型(默认指向 ai.88531.cn,免费注册领额度);
|
||||
// 'inherit' 复用上面的 AI 生图配置
|
||||
videoai: {
|
||||
provider: 'inherit',
|
||||
provider: 'custom',
|
||||
custom: {
|
||||
url: '',
|
||||
model: '',
|
||||
url: 'https://ai.88531.cn/v1',
|
||||
model: 'mimo-v2.6-flash',
|
||||
apiKey: ''
|
||||
}
|
||||
}
|
||||
@@ -78,10 +79,12 @@ function getSettings() {
|
||||
}
|
||||
},
|
||||
videoai: {
|
||||
provider: (data.videoai && data.videoai.provider) === 'custom' ? 'custom' : 'inherit',
|
||||
provider: data.videoai
|
||||
? (data.videoai.provider === 'inherit' ? 'inherit' : 'custom')
|
||||
: DEFAULTS.videoai.provider,
|
||||
custom: {
|
||||
url: (data.videoai && data.videoai.custom && data.videoai.custom.url) || '',
|
||||
model: (data.videoai && data.videoai.custom && data.videoai.custom.model) || '',
|
||||
url: (data.videoai && data.videoai.custom && data.videoai.custom.url) || DEFAULTS.videoai.custom.url,
|
||||
model: (data.videoai && data.videoai.custom && data.videoai.custom.model) || DEFAULTS.videoai.custom.model,
|
||||
apiKey: (data.videoai && data.videoai.custom && data.videoai.custom.apiKey) || ''
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ services:
|
||||
- HUB_API_KEY=${HUB_API_KEY:-}
|
||||
- NEWAPI_KEY=${NEWAPI_KEY:-}
|
||||
# 当前站点版本(与 frontend/package.json、CHANGELOG 保持一致,界面版本徽标来源)
|
||||
- SITE_VERSION=1.4.18
|
||||
- SITE_VERSION=1.4.19
|
||||
# 让容器经 host.docker.internal 访问宿主机的 AI 侧车
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flypic-frontend",
|
||||
"version": "1.4.18",
|
||||
"version": "1.4.19",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -64,6 +64,8 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) {
|
||||
const [saveDir, setSaveDir] = useState('');
|
||||
const [transition, setTransition] = useState('fade');
|
||||
const [duration, setDuration] = useState(0); // 目标时长(秒),0=自动按配音
|
||||
const [script, setScript] = useState(''); // 视频文案(可编辑,逐句朗读)
|
||||
const [genScript, setGenScript] = useState(false);
|
||||
const [task, setTask] = useState(null);
|
||||
const [error, setError] = useState('');
|
||||
const [starting, setStarting] = useState(false);
|
||||
@@ -167,6 +169,23 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) {
|
||||
finally { setExtracting(false); }
|
||||
};
|
||||
|
||||
const handleGenScript = async () => {
|
||||
if (!title.trim()) { setError('请填写视频标题'); return; }
|
||||
setError(''); setGenScript(true);
|
||||
try {
|
||||
const r = await fetch('/api/video/gen-script', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer' + ' ' + getToken() },
|
||||
body: JSON.stringify({ title: title.trim(), duration: Number(duration) || 0, count: picked.length || 0 })
|
||||
});
|
||||
const d = await r.json().catch(() => ({}));
|
||||
if (!r.ok || d.error) throw new Error(errText(d.error, `文案生成失败 (${r.status})`));
|
||||
if (!d.script) throw new Error('模型未返回文案');
|
||||
setScript(d.script);
|
||||
} catch (e) { setError(e.message || '文案生成失败'); }
|
||||
finally { setGenScript(false); }
|
||||
};
|
||||
|
||||
const handleStart = async () => {
|
||||
setError('');
|
||||
if (!title.trim()) { setError('请填写视频标题'); return; }
|
||||
@@ -179,6 +198,7 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) {
|
||||
const body = {
|
||||
libraryId, title: title.trim(),
|
||||
content: content.trim(),
|
||||
script: script.trim(), // 用户已编辑的文案:非空时原样分镜(不改写)
|
||||
images: imgs,
|
||||
voice, resolution, extraPrompt: '', saveDir, transition, duration: Number(duration) || 0,
|
||||
subtitleStyle: { position: subtitlePos, color: subtitleColor, fontSizePct: subtitleSize }
|
||||
@@ -337,7 +357,23 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) {
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">视频标题</label>
|
||||
<input className={input} value={title} onChange={(e) => setTitle(e.target.value)} placeholder="例如:产品速览 / 探店 vlog" maxLength={60} disabled={running||done} />
|
||||
<div className="flex gap-2">
|
||||
<input className={input + ' flex-1'} value={title} onChange={(e) => setTitle(e.target.value)} placeholder="输入标题后点右侧按钮快速生成文案" maxLength={60} disabled={running||done} />
|
||||
<button onClick={handleGenScript} disabled={genScript || running || done || !title.trim()}
|
||||
title="按标题快速生成文案,生成后可修改,视频严格按此文案朗读"
|
||||
className="shrink-0 px-3 py-1.5 text-xs rounded bg-indigo-600 text-white hover:bg-indigo-700 disabled:opacity-50 whitespace-nowrap">
|
||||
{genScript ? '文案生成中…' : 'AI 生成文案'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">视频文案(可修改,逐句朗读)</label>
|
||||
<textarea className={input + ' font-mono'} rows={6} value={script} onChange={(e) => setScript(e.target.value)} disabled={running||done}
|
||||
placeholder={'点上方「AI 生成文案」按标题生成;也可直接粘贴已有文案。\n每行一句 = 一个画面,视频严格按此文案配音。\n留空则由 AI 按下方提示词/内容自动生成。'} />
|
||||
<div className="text-[11px] text-gray-500 dark:text-gray-400 mt-1">
|
||||
{script.trim() ? `已填 ${script.trim().split(/\n+/).length} 句 · 按你的文案生成(不改写)` : '留空 = AI 自动分镜'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
|
||||
@@ -57,10 +57,10 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
}
|
||||
});
|
||||
setVa({
|
||||
provider: d?.videoai?.provider === 'custom' ? 'custom' : 'inherit',
|
||||
provider: d?.videoai?.provider === 'inherit' ? 'inherit' : 'custom',
|
||||
custom: {
|
||||
url: d?.videoai?.custom?.url || '',
|
||||
model: d?.videoai?.custom?.model || '',
|
||||
url: d?.videoai?.custom?.url || 'https://ai.88531.cn/v1',
|
||||
model: d?.videoai?.custom?.model || 'mimo-v2.6-flash',
|
||||
apiKeyMasked: d?.videoai?.custom?.apiKeyMasked || '',
|
||||
configured: !!d?.videoai?.custom?.configured
|
||||
}
|
||||
@@ -135,10 +135,10 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
setApiKeyInput('');
|
||||
if (data?.videoai) {
|
||||
setVa({
|
||||
provider: data.videoai.provider === 'custom' ? 'custom' : 'inherit',
|
||||
provider: data.videoai.provider === 'inherit' ? 'inherit' : 'custom',
|
||||
custom: {
|
||||
url: data.videoai.custom?.url || '',
|
||||
model: data.videoai.custom?.model || '',
|
||||
url: data.videoai.custom?.url || 'https://ai.88531.cn/v1',
|
||||
model: data.videoai.custom?.model || 'mimo-v2.6-flash',
|
||||
apiKeyMasked: data.videoai.custom?.apiKeyMasked || '',
|
||||
configured: !!data.videoai.custom?.configured
|
||||
}
|
||||
@@ -532,7 +532,7 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
type="text"
|
||||
value={va.custom.url}
|
||||
onChange={(e) => setVa((v) => ({ ...v, custom: { ...v.custom, url: e.target.value } }))}
|
||||
placeholder="https://api.openai.com/v1 或 http://192.168.68.19:3099/v1"
|
||||
placeholder="https://ai.88531.cn/v1"
|
||||
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
@@ -556,6 +556,15 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
<div className="p-3 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg">
|
||||
<div className="text-xs font-semibold text-blue-700 dark:text-blue-300 mb-1">免费注册领额度</div>
|
||||
<div className="text-xs text-blue-700/90 dark:text-blue-300/90 leading-relaxed">
|
||||
没有 API Key?前往{' '}
|
||||
<a href="https://ai.88531.cn/register" target="_blank" rel="noreferrer" className="font-medium underline hover:text-blue-800 dark:hover:text-blue-200">ai.88531.cn 免费注册</a>
|
||||
,注册即送体验金、每天签到再领 ¥0.5;登录后在「令牌」页创建一个 Key 粘贴到上方即可。
|
||||
默认已填好接口地址 https://ai.88531.cn/v1 与模型 mimo-v2.6-flash。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
Reference in new issue
Block a user