feat(ai): 分析结果按素材指纹缓存,跨项目复用无需重新分析

- 视觉/技术分析结果持久化到 cache/analysis/<指纹>.json,
  导入同一素材时自动加载缓存分析,新项目无需重复分析
- 技术分析抽帧跳过已存在的帧文件,重复分析只做场景检测
- 分析完成(技术或视觉)后自动写入缓存
This commit is contained in:
xhgit committed 2026-11-14 13:33:36 +08:00
1 parent 3fdddf638f
commit 28904bffea
3 files changed
+30 -3

No files matched your search

+13 -1
View File
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import path from 'node:path';
import {newProject,commit,undo,saveProject,loadProject,applyOperations,validateProject,projectDuration,splitClip,sanitizeOperations} from '../desktop/core/project.mjs';
import {run,ffmpeg,probe,importMedia,analyzeTechnical,exportVideo,makeProxy} from '../desktop/core/media.mjs';
import {run,ffmpeg,probe,importMedia,analyzeTechnical,exportVideo,makeProxy,loadCachedAnalysis,saveCachedAnalysis} from '../desktop/core/media.mjs';
import {Tasks} from '../desktop/core/tasks.mjs';
import {assemble} from '../desktop/core/styles.mjs';
const out=path.resolve('.test-output','中文 空格素材');await fs.mkdir(out,{recursive:true});
@@ -27,6 +27,18 @@ test('真实 FFmpeg:导入、场景时间戳、编辑、SQLite 恢复、代理
await assert.rejects(importMedia(path.join(out,'不存在.mp4'),cache));
});
test('任务队列限流、错误和取消',async()=>{let latest;const queue=new Tasks(x=>latest=x);let release;const block=new Promise(r=>release=r);queue.add('第一任务',async()=>{await block;return {ok:true};});const id=queue.add('取消任务',async()=>{throw Error('不得执行');});queue.cancel(id);queue.add('失败任务',async()=>{throw Error('真实失败');});release();for(let i=0;i<100&&queue.running;i++)await new Promise(r=>setTimeout(r,10));assert.equal(latest.find(i=>i.id===id).status,'cancelled');assert.equal(latest.find(i=>i.label==='失败任务').status,'error');});
test('分析结果按素材指纹缓存,跨项目复用无需重新分析',async()=>{
const cache=path.join(out,'analysis-cache');
const m={fingerprint:'fp-'+Date.now(),name:'复用素材.mp4'};
assert.equal(await loadCachedAnalysis(cache,m),null);
const analysis={method:'测试分析',segments:[{start:0,end:5,description:'海滩日落',tags:['海边'],score:90}]};
await saveCachedAnalysis(cache,m,analysis);
const loaded=await loadCachedAnalysis(cache,m);
assert.equal(loaded.segments[0].description,'海滩日落');
assert.equal(loaded.segments[0].score,90);
const other={fingerprint:'other-fp',name:'其他.mp4'};
assert.equal(await loadCachedAnalysis(cache,other),null);
});
test('AI 操作净化:越界数值截断、无效引用忽略、视频轨重叠自动平移',()=>{
const p=newProject('净化测试');p.media=[
{id:'v',type:'video',duration:30,name:'v',tags:[],path:'x'},