Author SHA1 Message Date
xhgit 286beb8ee5 fix(ai): 净化层去重同源片段,禁止重复使用相同 in/out 范围
实测混剪成片:模型把同一集同一个镜头(相同 mediaId+in+out)用了 3 次。
净化层现在按 mediaId+in+out(0.1s 粒度)去重,重复的 add 直接忽略并记录
备注;提示词同步增加「禁止重复使用同一个源片段」规则。
新增净化测试用例(同源同范围 add 去重)。
2026-11-14 17:54:21 +08:00
xhgit e473bc90a3 Merge pull request 'fix(ai): 规划数据排除片头片尾卡并按描述去重,裁剪保底每素材 3 段' (#14) from fix/planner-segment-filter into main 2026-11-14 07:10:04 +00:00
xhgit d96ef11fe2 fix(ai): 规划数据排除片头片尾卡并按描述去重,裁剪保底每素材 3 段
实测《无职转生》4 集分析后规划返回空方案,原因:
1. 片头标题画面/演职员表评分最高,占据了每素材有限的段数名额
2. 静态画面重复帧产生大量相同描述,挤掉有效镜头
3. 预算裁剪最低压到每素材 2 段,模型实际只看到 8 个片段

修改:标题/演职员类片段从数据中排除;同素材内相同描述去重;
裁剪保底每素材 3 段;提示词补充「含蓄镜头同样可以表达人物关系」。
新增测试断言标题卡排除。
2026-11-14 15:09:05 +08:00
xhgit ad2a2ba704 Merge pull request 'fix(ai): 规划提示词补回用户要求——指令此前从未发送给模型' (#13) from fix/planner-missing-instruction into main 2026-11-14 07:06:20 +00:00
4 changed files with 13 additions and 4 deletions

No files matched your search

+3
View File
@@ -73,6 +73,8 @@ function cleanColor(v){return /^#[0-9a-fA-F]{6}$/.test(String(v))?String(v):unde
export function sanitizeOperations(p,operations){
if(!Array.isArray(operations)||operations.length>1000)throw Error('模型没有返回有效的操作数组');
const ops=[],notes=[],addBySim=new Map(),updById=new Map();
const seenRange=new Set();
for(const c of p.clips)if(c.mediaId&&c.track!=='subtitle')seenRange.add(c.mediaId+'|'+Math.round(c.in*10)+'|'+Math.round(c.out*10));
const note=n=>{if(notes.length<40)notes.push(n);};
const handle=op=>{
if(!op||typeof op!=='object')return note('忽略无效操作');
@@ -91,6 +93,7 @@ export function sanitizeOperations(p,operations){
else if(m.type==='image'){clip.in=0;clip.out=Math.min(clampValue(raw.out,'out')??Math.min(5,60),60);}
else{clip.in=Math.min(clampValue(raw.in,'in')??0,Math.max(0,m.duration-.1));clip.out=Math.min(clampValue(raw.out,'out')??m.duration,m.duration);}
if(!(clip.out>clip.in+.05))return note('忽略 add:出点必须大于入点');
if(track!=='subtitle'){const key=clip.mediaId+'|'+Math.round(clip.in*10)+'|'+Math.round(clip.out*10);if(seenRange.has(key))return note('忽略 add:与现有片段重复使用同一源片段');seenRange.add(key);}
if(raw.text!==undefined)clip.text=cleanText(raw.text);
for(const k of ['fade','brightness','contrast','saturation','fontSize']){const v=clampValue(raw[k],k);if(v!==undefined)clip[k]=v;}
if(raw.color!==undefined){const col=cleanColor(raw.color);if(col)clip.color=col;}
+6 -4
View File
@@ -85,11 +85,13 @@ export async function visionAnalyze(c,media,analysis,signal,progress){
// 规划提示词:只发送经过筛选的高价值片段(按评分排序),并严格控制数据体量,
// 避免超出本地模型上下文导致报错;明确选材规则,减少"乱选素材"。
const PLACEHOLDER=/尚未|等待|采样窗口|时间采样|语义或动作/;
const TITLE_CARD=/标题画面|演职员|职员表|片头|片尾|字幕卡|制作人员/;
const SEG_CAP=60,PER_MEDIA_CAP=8,DESC_MAX=90;
const round2=n=>Math.round(n*100)/100;
function buildProjectData(p,budget){
const media=p.media.map(m=>{
const all=(m.analysis?.segments||[]).filter(s=>s&&Number.isFinite(s.score)&&s.score!==null&&typeof s.description==='string'&&s.description&&!PLACEHOLDER.test(s.description))
const seen=new Set();
const all=(m.analysis?.segments||[]).filter(s=>s&&Number.isFinite(s.score)&&s.score!==null&&typeof s.description==='string'&&s.description&&!PLACEHOLDER.test(s.description)&&!TITLE_CARD.test(s.description)&&!seen.has(s.description)&&(seen.add(s.description),true))
.map(s=>({start:round2(s.start),end:round2(s.end),score:round2(s.score),description:String(s.description).slice(0,DESC_MAX),...(s.reason?{reason:String(s.reason).slice(0,50)}:{})}))
.sort((a,b)=>b.score-a.score);
return {id:m.id,name:String(m.name||'').slice(0,60),type:m.type,duration:round2(m.duration),...(m.tags&&m.tags.length?{tags:m.tags.slice(0,6)}:{}),segments:all,hint:all.length?'':'未分析,必要时可从全片取用'};
@@ -102,11 +104,11 @@ function buildProjectData(p,budget){
...(c.brightness!==undefined?{brightness:c.brightness}:{}),...(c.contrast!==undefined?{contrast:c.contrast}:{}),...(c.saturation!==undefined?{saturation:c.saturation}:{}),...(c.fit?{fit:c.fit}:{})}));
const data={settings:p.settings,timelineDuration:round2(Math.max(0,...p.clips.map(c=>c.start+(c.out-c.in)/(c.speed||1)))),media,clips};
const steps=[
d=>{for(const m of d.media)m.segments=m.segments.slice(0,4);},
d=>{for(const m of d.media)m.segments=m.segments.slice(0,6);},
d=>{for(const m of d.media)for(const s of m.segments)s.description=s.description.slice(0,60);},
d=>{for(const m of d.media)for(const s of m.segments)delete s.reason;},
d=>{for(const m of d.media)for(const s of m.segments)s.description=s.description.slice(0,30);},
d=>{for(const m of d.media)if(m.segments.length)m.segments=m.segments.slice(0,2);},
d=>{for(const m of d.media)if(m.segments.length)m.segments=m.segments.slice(0,3);},
d=>{for(const c of d.clips)for(const k of ['brightness','contrast','saturation','fit','color','fontSize','fade','volume','speed'])delete c[k];},
d=>{d.clips=d.clips.slice(0,120).map(c=>({id:c.id,mediaId:c.mediaId,track:c.track,start:c.start}));},
d=>{for(const m of d.media)delete m.tags;},
@@ -154,7 +156,7 @@ remove {"type":"remove","id":"已有片段 ID"}。
1. 只能引用素材列表中的素材 ID,禁止编造;视频/图片放入 video 轨,音频放入 audio 轨,音频素材不能放入 video 轨。
2. 视频/音频的 in≥0 且 out≤素材 duration,且 out>in;图片素材 in=0,out 最长 60 秒。
3. 视频轨片段不允许重叠;新片段一般接在时间轴末尾(start 等于 timelineDuration),除非用户要求插入特定位置。片段在时间轴上的时长=(out-in)/speed。
4. 素材选择:优先使用 score 高的片段;根据用户主题、关键词与片段的 description、reason、tags 匹配内容;尽量使用多个不同素材,避免同一素材连续堆砌;不要使用与主题明显无关的素材;未分析的素材只作补充。
4. 素材选择:优先使用 score 高的片段;根据用户主题、关键词与片段的 description、reason、tags 匹配内容;尽量使用多个不同素材,避免同一素材连续堆砌;不要使用与主题明显无关的素材;未分析的素材只作补充。含蓄镜头(背影、牵手、表情特写、物品特写)同样可以表达人物关系,不必要求两人同框或正脸。禁止重复使用同一个源片段(相同素材的相同 in/out 范围只能出现一次)。
5. ${mode}
6. 不要声称添加了不存在的音乐;音频素材列表为空时不要添加 audio 轨。若素材列表中有音频素材且用户要求配乐 / 配音,应添加 audio 轨并按需要调整 volume。
7. 数值范围:speed 0.25–4,volume 0–4,fade 0–10,brightness -1–1,contrast 0–2,saturation 0–3,fontSize 12–160,color 为 #rrggbb。
+1
View File
@@ -50,6 +50,7 @@ test('AI 操作净化:越界数值截断、无效引用忽略、视频轨重
{type:'update',id:'c1',changes:{out:25}}, // 延长到 25s
{type:'add',clip:{mediaId:'v',track:'video',start:0,in:0,out:999,speed:99,volume:-5,color:'red',fontSize:1,brightness:9}}, // 越界全部截断
{type:'add',clip:{mediaId:'v',track:'video',start:1,in:5,out:10}}, // 与 c1 重叠,应后移
{type:'add',clip:{mediaId:'v',track:'video',start:9,in:5,out:10}}, // 与上一条同源同范围,应去重忽略
{type:'add',clip:{mediaId:'nope',track:'video',start:0,in:0,out:1}}, // 素材不存在,忽略
{type:'add',clip:{mediaId:'v',track:'audio',start:0,in:0,out:5}}, // 视频素材进音频轨,忽略
{type:'update',id:'ghost',changes:{start:0}}, // 片段不存在,忽略
+3
View File
@@ -34,6 +34,8 @@ test('JSON 解析失败自动重试:第二次不再强制 format 并追加严
test('规划提示词:按评分筛选片段、丢弃占位描述、区分新建/修改模式、控制数据体量',()=>{
const mk=(id,score)=>({id,name:id,type:'video',duration:120,tags:['海边'],analysis:{segments:[
{start:0,end:5,description:'海滩日落,人物走过画面,光线柔和,构图开阔',score,reason:'构图好'},
{start:2,end:6,description:'海滩日落,人物走过画面,光线柔和,构图开阔',score:score+2}, // 重复描述应去重
{start:8,end:12,description:'动画标题画面,显示作品名称',score:99}, // 片头标题卡应排除
{start:10,end:15,description:'尚未进行语义或动作识别',score:null},
{start:20,end:25,description:'城市夜景,车流灯光',score:score-10,reason:'节奏感强'},
]}});
@@ -44,6 +46,7 @@ test('规划提示词:按评分筛选片段、丢弃占位描述、区分新
assert.ok(fresh.includes('海滩日落'));
assert.ok(fresh.includes('城市夜景'));
assert.ok(!fresh.includes('尚未进行语义或动作识别'));
assert.ok(!fresh.includes('动画标题画面'),'片头标题卡必须排除');
assert.ok(!fresh.includes('motion'));
assert.ok(fresh.includes('先 remove 现有全部片段'));
assert.ok(fresh.includes('45'));