diff --git a/desktop/core/providers.mjs b/desktop/core/providers.mjs index 1262ee3..36c7cf3 100644 --- a/desktop/core/providers.mjs +++ b/desktop/core/providers.mjs @@ -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 匹配内容;尽量使用多个不同素材,避免同一素材连续堆砌;不要使用与主题明显无关的素材;未分析的素材只作补充。含蓄镜头(背影、牵手、表情特写、物品特写)同样可以表达人物关系,不必要求两人同框或正脸。 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。 diff --git a/tests/providers.test.mjs b/tests/providers.test.mjs index 8b94592..0e02ce2 100644 --- a/tests/providers.test.mjs +++ b/tests/providers.test.mjs @@ -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'));