feat: 开源轻映 AI 桌面剪辑工作台及抽帧复核功能
This commit is contained in:
1 parent
9af7c2fe86
commit
b51ef85dbd
46 files changed
+6916
-2
No files matched your search
@@ -0,0 +1,5 @@
|
||||
// Real-model integration: no fixture server or synthetic AI responses.
|
||||
import {spawn} from 'node:child_process';
|
||||
const env={...process.env,QY_AI_TEST:'1',QY_TEST_MODEL:process.env.QY_TEST_MODEL||'gemma3:4b'};
|
||||
const child=spawn(process.execPath,['scripts/desktop-e2e.mjs'],{stdio:'inherit',env,windowsHide:true});
|
||||
child.on('exit',code=>process.exitCode=code||0);
|
||||
@@ -0,0 +1,19 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {run,ffmpeg} from '../desktop/core/media.mjs';
|
||||
const root=path.resolve('output/无职转生_30秒燃向卡点');
|
||||
const dest=path.resolve('.test-output/frame-audit-v1');await fs.mkdir(dest,{recursive:true});
|
||||
const sources=JSON.parse(await fs.readFile('.test-output/user-cut/sources.json','utf8'));
|
||||
const edl=JSON.parse(await fs.readFile(path.join(root,'剪辑清单.json'),'utf8'));
|
||||
for(const s of edl.shots){
|
||||
const m=sources.find(x=>x.episode===s.episode);
|
||||
for(const [kind,file,start,len] of [['source',m.path,s.sourceIn,s.sourceOut-s.sourceIn],['output',path.join(root,'无职转生_超燃卡点_30秒_RTX5080.mp4'),s.timelineStart,s.duration]]){
|
||||
await run(ffmpeg,['-y','-v','error','-hwaccel','cuda','-ss',String(start),'-i',file,'-vf',`select='eq(n,0)+gte(t,${len*.5})*lt(prev_selected_t,${len*.5})+gte(t,${len-.07})*lt(prev_selected_t,${len-.07})',scale=320:180,tile=3x1`,'-frames:v','1',path.join(dest,`${s.index}-${kind}.jpg`)]);
|
||||
}
|
||||
console.log('Compared frames',s.index);
|
||||
}
|
||||
await fs.writeFile(path.join(dest,'shots.json'),JSON.stringify(edl.shots,null,2));
|
||||
const src=sources.find(s=>s.episode===21);
|
||||
for(const [start,len] of [[540,60],[660,40],[700,45]]){
|
||||
await run(ffmpeg,['-y','-v','error','-hwaccel','cuda','-ss',String(start),'-t',String(len),'-i',src.path,'-vf',`fps=1,scale=320:180,setpts=PTS+${start}/TB,drawtext=fontfile='C\\:/Windows/Fonts/consola.ttf':text='%{pts\\:hms}':fontsize=22:fontcolor=white:box=1:boxcolor=black@0.8:x=5:y=5,tile=5x${Math.ceil(len/5)}`,'-frames:v','1',path.join(dest,`source21-${start}.jpg`)]);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import {run,ffmpeg,importMedia,exportVideo,probe} from '../desktop/core/media.mjs';
|
||||
import {newProject,applyOperations,saveProject,loadProject} from '../desktop/core/project.mjs';
|
||||
import {assemble,getStyle,styleOperations} from '../desktop/core/styles.mjs';
|
||||
const dir=path.resolve('.test-output','30段 批量素材');await fs.mkdir(dir,{recursive:true});
|
||||
const p=newProject('30 段素材 45 秒真实渲染');p.settings={width:320,height:180,fps:30};
|
||||
const report={mediaCount:30,analysis:'此测试验证批量媒体与渲染,不声称完成30个真实场景的语义理解',checks:[]};
|
||||
for(let i=0;i<30;i++){
|
||||
const file=path.join(dir,`素材 ${String(i+1).padStart(2,'0')}.mp4`);
|
||||
await run(ffmpeg,['-y','-v','error','-f','lavfi','-i','testsrc2=s=320x180:r=30','-vf',`hue=h=${i*12}`,'-t','1.6','-c:v','libx264','-pix_fmt','yuv420p',file]);
|
||||
p.media.push(await importMedia(file,path.join(dir,'cache')));
|
||||
}
|
||||
assert.equal(new Set(p.media.map(m=>m.fingerprint)).size,30);report.checks.push('30个独立媒体真实探测和缩略图');
|
||||
const duplicate=path.join(dir,'重复副本.mp4');await fs.copyFile(p.media[0].path,duplicate);const d=await importMedia(duplicate,path.join(dir,'cache'));assert.equal(d.fingerprint,p.media[0].fingerprint);report.checks.push('不同文件名的同内容 SHA256 去重');
|
||||
const proposal=assemble(p,{style:'cinematic',target:45});const next=applyOperations(p,proposal.operations,'规则组接');assert.ok(Math.abs(Math.max(...next.clips.map(c=>c.start+(c.out-c.in)/c.speed))-45)<.01);
|
||||
const file=path.join(dir,'45秒 成品.mp4');let encoder;await exportVideo(next,file,{acceleration:'auto',onEncoder:e=>encoder=e});const meta=await probe(file);assert.ok(Math.abs(Number(meta.format.duration)-45)<.15);report.checks.push('真实45秒MP4导出');report.encoder=encoder;
|
||||
await saveProject(path.join(dir,'批量工程.qycut'),next);assert.equal((await loadProject(path.join(dir,'批量工程.qycut'))).media.length,30);report.checks.push('30素材SQLite保存恢复');
|
||||
const sport=getStyle('sport'),movie=getStyle('cinematic');assert.ok(sport.shotMax<movie.shotMin);assert.notEqual(styleOperations([{type:'add',clip:{}}],sport)[0].clip.saturation,styleOperations([{type:'add',clip:{}}],movie)[0].clip.saturation);report.checks.push('风格影响镜头长度与实际渲染参数');
|
||||
await fs.writeFile('.test-output/batch-e2e-report.json',JSON.stringify(report,null,2));console.log(JSON.stringify(report,null,2));
|
||||
@@ -0,0 +1,18 @@
|
||||
import {_electron as electron} from 'playwright-core';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
const exe=path.resolve('.test-output/installed app/轻映 AI.exe'),project=path.resolve('output/无职转生_30秒_修订版/无职转生_修订版.qycut');
|
||||
const app=await electron.launch({executablePath:exe,args:[project],env:{...process.env,QY_TEST_USERDATA:path.resolve('.test-output/final-project-profile')}});
|
||||
try{
|
||||
const page=await app.firstWindow();await page.waitForFunction(()=>!!window.studio&&document.querySelector('.project-title'));
|
||||
const state=await page.evaluate(()=>window.studio.bootstrap());assert.equal(state.project.clips.filter(c=>c.track==='video').length,23);assert.equal(state.config.processingMode,'gpu');
|
||||
assert.ok(state.project.media.every(m=>!m.missing));
|
||||
await page.getByRole('button',{name:'导出视频',exact:true}).click();
|
||||
const select=page.getByLabel('编码加速');assert.equal(await select.inputValue(),'gpu');
|
||||
assert.deepEqual(await select.locator('option').evaluateAll(options=>options.map(o=>o.value)),['cpu','gpu','hybrid']);
|
||||
for(const value of ['cpu','hybrid','gpu']){await select.selectOption(value);assert.equal(await select.inputValue(),value);}
|
||||
await page.screenshot({path:'.test-output/installed-gpu-modes.png'});await page.locator('.modal .icon-button').click();
|
||||
await page.getByRole('button',{name:'剪辑',exact:true}).click();await page.screenshot({path:'.test-output/installed-real-project.png'});
|
||||
await fs.writeFile('.test-output/final-project-report.json',JSON.stringify({installedExe:exe,project,videoClips:23,mediaMissing:false,defaultMode:'gpu',modes:['cpu','gpu','hybrid'],passed:true},null,2));console.log('PASS installed project and all three engine selectors');
|
||||
}finally{await app.close();}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Original instrumental soundtrack, synthesized locally. No external music assets.
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {run,ffmpeg,probe} from '../desktop/core/media.mjs';
|
||||
const out=path.resolve('output','无职转生_30秒燃向卡点');await fs.mkdir(out,{recursive:true});
|
||||
const sr=48000,seconds=30,bpm=144,beat=60/bpm,N=sr*seconds,L=new Float32Array(N),R=new Float32Array(N);
|
||||
let seed=837472;const noise=()=>{seed=(Math.imul(seed,1664525)+1013904223)>>>0;return seed/2147483648-1;};
|
||||
function add(start,dur,fn,gain=1,pan=0){const begin=Math.round(start*sr),count=Math.min(Math.round(dur*sr),N-begin);for(let j=0;j<count;j++){const [l,r]=fn(j/sr,j);L[begin+j]+=l*gain*(1-pan*.35);R[begin+j]+=r*gain*(1+pan*.35);}}
|
||||
const osc=(f,t)=>Math.sin(2*Math.PI*f*t);
|
||||
function saw(f,t){const x=f*t;return 2*(x-Math.floor(x+.5));}
|
||||
const roots=[73.4162,58.2705,65.4064,55];
|
||||
for(let b=0;b<72;b++){
|
||||
const t=b*beat,section=b<8?.48:b<16?.7:b<64?1:.85;
|
||||
// Tight, pitched kick with a short saturated transient.
|
||||
add(t,.36,(q)=>{const phase=2*Math.PI*(49*q+145*.022*(1-Math.exp(-q/.022)));const v=Math.sin(phase)*Math.exp(-q*12)+noise()*.12*Math.exp(-q*160);return [v,v];},.86*section);
|
||||
if(b%4===1||b%4===3)add(t,.22,(q)=>{const n=noise(),clap=n*Math.exp(-q*24)*(q<.009||q>.012&&q<.024||q>.03?1:.15);const v=clap*.55+osc(182,q)*Math.exp(-q*35)*.2;return [v,v*.95];},.62*section);
|
||||
for(let h=0;h<2;h++){const open=h===1&&b%4===3;add(t+h*beat/2,open?.18:.055,(q)=>{const v=noise()*Math.exp(-q*(open?28:90))*.22;return [v,-v*.6];},section,h%2?.35:-.3);}
|
||||
const root=roots[Math.floor(b/8)%4],bassPattern=[0,0,7,0,0,12,7,0];
|
||||
if(b>=8)for(let h=0;h<2;h++){const f=root/2*2**(bassPattern[(b*2+h)%8]/12);add(t+h*beat/2,beat*.45,(q)=>{const envelope=Math.min(1,q/.008)*Math.min(1,(beat*.45-q)/.025);const v=Math.tanh((osc(f,q)*.8+saw(f,q)*.22)*1.5)*envelope;return [v,v];},.25*section);}
|
||||
// Wide, side-chained power chord; harmonics retain weight below the lead.
|
||||
add(t,beat,(q)=>{const attack=Math.min(1,q/.018),release=Math.min(1,(beat-q)/.035),duck=.2+.8*Math.min(1,q/.13);let left=0,right=0;for(const ratio of [1,1.5,2]){const f=root*ratio;left+=(saw(f*.998,q)+osc(f,q)*.6)/3;right+=(saw(f*1.002,q)+osc(f,q)*.6)/3;}return [left*attack*release*duck,right*attack*release*duck];},.16*section);
|
||||
if(b>=16){const pattern=[12,19,24,19,15,19,22,19,12,19,24,26,22,19,15,19];for(let h=0;h<2;h++){const note=pattern[(b*2+h)%pattern.length],f=root*2**(note/12);add(t+h*beat/2,beat*.43,(q)=>{const env=Math.min(1,q/.006)*Math.exp(-q*9)*Math.min(1,(beat*.43-q)/.02);const l=(osc(f*.997,q)+osc(f,q)+.25*osc(f*2,q))*.3*env,r=(osc(f*1.003,q)+osc(f,q)+.25*osc(f*2,q))*.3*env;return [l,r];},.22*section);}}
|
||||
if([0,8,16,32,48,64,70].includes(b))add(t,1.1,(q)=>{const v=noise()*Math.exp(-q*5)*.3+osc(55,q)*Math.exp(-q*8)*.4;return [v,v*.9];},.65);
|
||||
}
|
||||
// Two controlled build-ups, followed by a sharp downbeat.
|
||||
for(const startBeat of [12,44,60])add(startBeat*beat,4*beat,(q)=>{const x=q/(4*beat),v=noise()*x*x*.14+osc(180+900*x,q)*x*.025;return [v,v*.8];},1);
|
||||
// Short ping-pong delay adds space without obscuring transient alignment.
|
||||
const delay=Math.round(beat*.75*sr);for(let i=N-1;i>=delay;i--){L[i]+=R[i-delay]*.12;R[i]+=L[i-delay]*.12;}
|
||||
const pcm=Buffer.alloc(N*4);for(let i=0;i<N;i++){const fade=Math.min(1,i/(sr*.02),(N-1-i)/(sr*.16));pcm.writeInt16LE(Math.round(Math.tanh(L[i]*1.1)*.85*fade*32767),i*4);pcm.writeInt16LE(Math.round(Math.tanh(R[i]*1.1)*.85*fade*32767),i*4+2);}
|
||||
const header=Buffer.alloc(44);header.write('RIFF',0);header.writeUInt32LE(pcm.length+36,4);header.write('WAVEfmt ',8);header.writeUInt32LE(16,16);header.writeUInt16LE(1,20);header.writeUInt16LE(2,22);header.writeUInt32LE(sr,24);header.writeUInt32LE(sr*4,28);header.writeUInt16LE(4,32);header.writeUInt16LE(16,34);header.write('data',36);header.writeUInt32LE(pcm.length,40);
|
||||
const raw=path.join(out,'原创配乐_144BPM_raw.wav'),dest=path.join(out,'原创配乐_144BPM.wav');await fs.writeFile(raw,Buffer.concat([header,pcm]));
|
||||
await run(ffmpeg,['-y','-v','error','-i',raw,'-af','highpass=f=30,lowpass=f=10500,loudnorm=I=-13:TP=-1.5:LRA=7','-ar','48000','-c:a','pcm_s16le',dest]);await fs.rm(raw);console.log(dest,await probe(dest).then(p=>p.format.duration));
|
||||
await fs.writeFile(path.join(out,'配乐说明.txt'),'原创电子器乐配乐:144 BPM,D 小调,72 拍,30 秒。由本项目本地合成;底鼓、军鼓、镲、低音、和弦、琶音及上升音效均为程序生成,无外部音乐采样。\n');
|
||||
@@ -0,0 +1,42 @@
|
||||
import {_electron as electron} from 'playwright-core';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
const dir=path.resolve('.test-output/desktop-profile');await fs.mkdir(dir,{recursive:true});
|
||||
const exe=process.env.QY_PACKAGED_EXE;
|
||||
const app=await electron.launch({...(exe?{executablePath:exe,args:[]}:{args:['.']}),env:{...process.env,QY_TEST_USERDATA:dir}});
|
||||
const page=await app.firstWindow();const errors=[];page.on('pageerror',e=>errors.push(e.message));page.on('console',m=>{if(m.type()==='error')console.log('Renderer:',m.text());});
|
||||
const report={packaged:!!exe,checks:[],errors};
|
||||
async function check(name,fn){await fn();report.checks.push(name);console.log('PASS',name);}
|
||||
const waitTask=async id=>{await page.waitForFunction(id=>{const t=window.__events.filter(e=>e.type==='tasks').flatMap(e=>e.data).filter(t=>t.id===id).at(-1);return t&&['done','error','cancelled'].includes(t.status);},id,{timeout:600000});const task=await page.evaluate(id=>window.__events.filter(e=>e.type==='tasks').flatMap(e=>e.data).filter(t=>t.id===id).at(-1),id);if(task.status!=='done')throw Error(task.detail);return task;};
|
||||
try{
|
||||
await page.waitForFunction(()=>!!window.studio&&document.body.innerText.includes('剪辑工作台'));
|
||||
await page.evaluate(()=>{window.__events=[];window.studio.onEvent(e=>window.__events.push(e));});
|
||||
await check('Electron IPC 与真实桌面界面启动',async()=>{assert.ok(await page.locator('.topbar').isVisible());});
|
||||
const source=path.resolve('.test-output/中文 空格素材/测试 三色.mp4');
|
||||
await page.evaluate(()=>window.studio.newProject('桌面端到端验收'));
|
||||
await app.evaluate(({dialog},source)=>{dialog.showOpenDialog=async()=>({canceled:false,filePaths:[source]});},source);
|
||||
await check('通过原生文件选择 API 导入真实视频',async()=>{const id=await page.evaluate(()=>window.studio.importFiles());await waitTask(id);assert.equal((await page.evaluate(()=>window.studio.bootstrap())).project.media.length,1);});
|
||||
let state=await page.evaluate(()=>window.studio.bootstrap());const m=state.project.media[0];
|
||||
await check('真实缩略图和媒体协议 Range 流',async()=>{const r=await page.evaluate(async url=>{const r=await fetch(url,{headers:{Range:'bytes=0-1023'}});return {status:r.status,size:(await r.arrayBuffer()).byteLength};},m.url);assert.equal(r.status,206);assert.equal(r.size,1024);await page.locator('.media-card').first().click();await page.waitForFunction(()=>document.querySelector('video')?.readyState>=2);});
|
||||
await check('技术分析生成镜头时间戳',async()=>{const id=await page.evaluate(id=>window.studio.analyze([id],false),m.id);await waitTask(id);});
|
||||
await check('时间轴编辑、撤销和重做',async()=>{await page.locator('.quick-add').first().click({force:true});await page.waitForFunction(()=>document.querySelectorAll('.timeline-clip').length===1);await page.getByTitle('撤销 Ctrl+Z').click();await page.waitForFunction(()=>document.querySelectorAll('.timeline-clip').length===0);await page.getByTitle('重做 Ctrl+Shift+Z').click();await page.waitForFunction(()=>document.querySelectorAll('.timeline-clip').length===1);});
|
||||
const saved=path.resolve('.test-output/桌面 保存项目.qycut');
|
||||
await app.evaluate(({dialog},saved)=>{dialog.showSaveDialog=async()=>({canceled:false,filePath:saved});},saved);
|
||||
await check('桌面项目 SQLite 保存',async()=>{await page.evaluate(()=>window.studio.saveProject(false));assert.ok((await fs.stat(saved)).size>0);});
|
||||
await check('合成预览渲染并加载',async()=>{const id=await page.evaluate(()=>window.studio.preview());await waitTask(id);await page.waitForFunction(()=>document.body.innerText.includes('已合成时间轴'));});
|
||||
const dest=path.resolve('.test-output/桌面 导出成品.mp4');
|
||||
await app.evaluate(({dialog},dest)=>{dialog.showSaveDialog=async()=>({canceled:false,filePath:dest});},dest);
|
||||
await check('桌面真实 MP4 导出',async()=>{const id=await page.evaluate(()=>window.studio.export({format:'mp4',codec:'h264',bitrate:1500}));const t=await waitTask(id);assert.ok((await fs.stat(dest)).size>1000);assert.equal(t.result.encoder,'h264_nvenc');assert.equal(t.result.audit.sampleCount,3);assert.equal(t.result.audit.pages.length,1);assert.ok((await fs.stat(t.result.audit.reportPath)).size>100);await page.getByRole('button',{name:'任务',exact:true}).click();await page.getByRole('button',{name:'查看抽帧 · 3 帧',exact:true}).click();await page.waitForFunction(()=>Array.from(document.querySelectorAll('.modal img')).some(i=>i.naturalWidth>0));await page.screenshot({path:'.test-output/audit-ui.png'});await page.locator('.modal .icon-button').click();});
|
||||
await page.screenshot({path:'.test-output/desktop-with-media.png'});
|
||||
if(process.env.QY_AI_TEST==='1'){
|
||||
const model=process.env.QY_TEST_MODEL||'gemma3:4b';state=await page.evaluate(()=>window.studio.bootstrap());const cfg=state.config;cfg.accounts[0].model=model;cfg.accounts[0].timeout=300;
|
||||
await page.evaluate(c=>window.studio.saveConfig(c),cfg);
|
||||
await check('真实 Ollama 文本能力测试',async()=>{const r=await page.evaluate(()=>window.studio.testModel('local',false));assert.equal(r.textVerified,true);});
|
||||
await check('真实 Ollama 视觉能力测试',async()=>{const r=await page.evaluate(()=>window.studio.testModel('local',true));assert.ok(/red|红/i.test(r.data.color));});
|
||||
await check('真实本地多帧分析,含三个镜头',async()=>{const id=await page.evaluate(id=>window.studio.analyze([id],true),m.id);await waitTask(id);const b=await page.evaluate(()=>window.studio.bootstrap());assert.equal(b.project.media[0].analysis.model,model);await fs.writeFile('.test-output/local-vision-result.json',JSON.stringify(b.project.media[0].analysis,null,2));});
|
||||
await check('真实 AI 修改现有时间轴并确认执行 / 撤销',async()=>{const id=await page.evaluate(()=>window.studio.plan('将当前唯一视频片段的出点 out 改为 4 秒,其他内容保持原样。只需要一个 update 操作。'));await waitTask(id);const plan=await page.evaluate(()=>window.__events.filter(e=>e.type==='plan').at(-1).data);await page.evaluate(id=>window.studio.applyPlan(id),plan.id);let b=await page.evaluate(()=>window.studio.bootstrap());assert.equal(b.project.clips[0].out,4);await page.evaluate(()=>window.studio.undo(false));b=await page.evaluate(()=>window.studio.bootstrap());assert.equal(b.project.clips[0].out,6);await fs.writeFile('.test-output/local-plan-result.json',JSON.stringify(plan,null,2));});
|
||||
}
|
||||
await check('关闭后重新打开项目内容一致',async()=>{const before=(await page.evaluate(()=>window.studio.bootstrap())).project;await app.evaluate(({dialog},saved)=>{dialog.showOpenDialog=async()=>({canceled:false,filePaths:[saved]});},saved);await page.evaluate(()=>window.studio.newProject('临时项目'));await page.evaluate(()=>window.studio.openProject());const after=(await page.evaluate(()=>window.studio.bootstrap())).project;assert.deepEqual(after.clips,before.clips);assert.equal(after.media.length,before.media.length);});
|
||||
assert.deepEqual(errors,[]);
|
||||
}finally{await fs.writeFile('.test-output/'+(process.env.QY_AI_TEST==='1'?'ai-e2e-report':exe?'packaged-e2e-report':'desktop-e2e-report')+'.json',JSON.stringify(report,null,2));await app.close();}
|
||||
@@ -0,0 +1,17 @@
|
||||
import {spawn} from 'node:child_process';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs/promises';
|
||||
import {ProxyAgent} from 'undici';
|
||||
const base='http://127.0.0.1:11434';
|
||||
let service;
|
||||
try{await fetch(base+'/api/tags');}catch{
|
||||
const exe=path.join(process.env.LOCALAPPDATA,'Programs','Ollama','ollama.exe');
|
||||
const log=await fs.open('.test-output/ollama.log','a');
|
||||
service=spawn(exe,['serve'],{windowsHide:true,detached:true,stdio:['ignore',log.fd,log.fd],env:{...process.env,OLLAMA_HOST:'127.0.0.1:11434',HTTPS_PROXY:process.env.QY_PROXY==='DIRECT'?'':process.env.QY_PROXY||'http://127.0.0.1:7890',NO_PROXY:'127.0.0.1,localhost,::1'}});service.unref();await fs.writeFile('.test-output/ollama.pid',String(service.pid));
|
||||
for(let i=0;i<40;i++){try{await fetch(base+'/api/tags');break;}catch{await new Promise(r=>setTimeout(r,500));}}
|
||||
}
|
||||
console.log('Ollama service available');
|
||||
const res=await fetch(base+'/api/pull',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({model:process.env.QY_TEST_MODEL||'gemma3:4b',stream:true})});
|
||||
if(!res.ok)throw Error(await res.text());let buffer='',lastPrint=0;
|
||||
for await(const data of res.body){buffer+=new TextDecoder().decode(data);const lines=buffer.split('\n');buffer=lines.pop();for(const line of lines.filter(Boolean)){const j=JSON.parse(line);if(j.error)throw Error(j.error);if(Date.now()-lastPrint>5000||j.status==='success'){console.log(j.status,j.total?`${(j.completed/1e9).toFixed(2)}/${(j.total/1e9).toFixed(2)} GB`:'');lastPrint=Date.now();}}}
|
||||
console.log('Model ready');
|
||||
@@ -0,0 +1,34 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {randomUUID} from 'node:crypto';
|
||||
import {newProject,commit,saveProject} from '../desktop/core/project.mjs';
|
||||
import {importMedia,exportVideo,probe,run,ffmpeg} from '../desktop/core/media.mjs';
|
||||
export const out=path.resolve('output/无职转生_30秒_修订版');
|
||||
await fs.mkdir(out,{recursive:true});
|
||||
const sources=JSON.parse(await fs.readFile('.test-output/user-cut/sources.json','utf8'));
|
||||
const source=sources.find(s=>s.episode===21);
|
||||
// Single encounter, chronological order. Descriptions are observable content, not invented plot outcomes.
|
||||
const choices=[
|
||||
[546.05,2,1,'少年眼睛特写'],[547.05,2,1,'白发男子冲近'],[549.05,4,1,'长枪挡住攻击'],
|
||||
[564.3,2,1.15,'挥枪与近身格挡'],[568.85,4,1.1,'连续刺击与格挡'],[575.2,2,1.1,'旋身交锋'],[576.4,4,1.1,'枪身与手臂碰撞火花'],[582.8,4,1.1,'近身反击,持枪者腾空'],
|
||||
[673.3,4,1,'红发少女伸手凝聚火焰'],[675.2,4,1,'火焰消散,少女抬眼'],
|
||||
[687.0,2,1.1,'带火尖锥掠过洞内'],[688.7,2,1.1,'白发男子抬手挡住'],[707.0,4,1.1,'掌前火焰被驱散'],
|
||||
[725.7,4,1,'少年伸出手臂'],[730.0,4,1.1,'掌中光球变色'],
|
||||
[732.1,4,1,'紫色光球变亮'],[735.6,4,1,'紫色能量向上扩展'],[744.1,2,1,'少年抬头看向前方'],[745.5,2,1,'手掌前能量释放'],
|
||||
[747.1,4,1,'紫色弹体向对面推进'],[750.6,2,1,'对面抬手形成圆形纹路'],[752.2,4,1.25,'紫色能量撞上圆形防御'],[768.4,2,1,'紫色余光环绕白发男子']
|
||||
];
|
||||
if(choices.reduce((n,s)=>n+s[1],0)!==72)throw Error('Expected 72 beats');
|
||||
const musicFile=path.join(out,'原创配乐_144BPM.wav');await fs.copyFile(path.resolve('output/无职转生_30秒燃向卡点/原创配乐_144BPM.wav'),musicFile);
|
||||
const p=newProject('无职转生 · 同场战斗 · 30秒修订版');p.settings={width:1920,height:1080,fps:60,processingMode:'gpu'};
|
||||
const m=await importMedia(source.path,path.join(out,'cache'),undefined,{acceleration:'gpu'}),music=await importMedia(musicFile,path.join(out,'cache'));p.media=[m,music];
|
||||
let beats=0;const edl=[];const clips=choices.map(([input,n,speed,description],i)=>{const start=beats*25/60,len=n*25/60;beats+=n;const c={id:randomUUID(),track:'video',mediaId:m.id,start,in:input,out:input+len*speed,speed,volume:(i<8?.38:i<13?.18:.28)*.8,fade:0,audioFade:.008,fit:'contain',crop:{x:0,y:0,width:1,height:.83},saturation:1.06,contrast:1.035,brightness:.006};edl.push({index:i+1,episode:21,sourceIn:input,sourceOut:c.out,timelineStart:start,duration:len,beats:n,speed,reason:description});return c;});
|
||||
clips.push({id:randomUUID(),track:'audio',mediaId:music.id,start:0,in:0,out:30,speed:1,volume:.68,audioFade:.08});
|
||||
const project=commit(p,clips,'同一场战斗按源时间顺序重剪;逐镜头抽帧复查');
|
||||
await saveProject(path.join(out,'无职转生_修订版.qycut'),project);await fs.writeFile(path.join(out,'剪辑清单.json'),JSON.stringify({bpm:144,beats:72,shots:edl},null,2));
|
||||
if(process.argv.includes('--prepare')){
|
||||
for(const s of edl){await run(ffmpeg,['-y','-v','error','-hwaccel','cuda','-ss',String(s.sourceIn),'-i',source.path,'-vf',`select='eq(n,0)+gte(t,${(s.sourceOut-s.sourceIn)/2})*lt(prev_selected_t,${(s.sourceOut-s.sourceIn)/2})+gte(t,${s.sourceOut-s.sourceIn-.06})*lt(prev_selected_t,${s.sourceOut-s.sourceIn-.06})',scale=384:216,tile=3x1`,'-frames:v','1',path.join(out,'cache',`source-${s.index}.jpg`)]);console.log('Source checked',s.index);}
|
||||
}else{
|
||||
const file=path.join(out,'无职转生_30秒_抽帧复核版_RTX5080.mp4'),engines=[];let last=-1;
|
||||
await exportVideo(project,file,{acceleration:'gpu',bitrate:18000,onEncoder:e=>engines.push(e)},undefined,(v,d)=>{const n=Math.floor(v*100);if(n!==last){console.log(n+'%',d);last=n;}});
|
||||
const meta=await probe(file);await fs.writeFile(path.join(out,'编码检查.json'),JSON.stringify({engines,meta},null,2));console.log('RENDERED',file);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {run,ffmpeg} from '../desktop/core/media.mjs';
|
||||
const items=JSON.parse(await fs.readFile('.test-output/user-cut/sources.json','utf8'));
|
||||
for(const [ep,start,seconds] of [[21,530,105],[21,635,105],[21,740,70],[11,600,108],[5,1010,108],[8,1280,90]]){
|
||||
const m=items.find(m=>m.episode===ep);const dest=path.resolve('.test-output/user-cut/contact',`detail-${ep}-${start}.jpg`);
|
||||
await run(ffmpeg,['-y','-v','error','-ss',String(start),'-t',String(seconds),'-i',m.path,'-vf',`fps=1/3,scale=260:-2,setpts=PTS+${start}/TB,drawtext=fontfile='C\\:/Windows/Fonts/consola.ttf':text='%{pts\\:hms}':fontsize=18:fontcolor=white:box=1:boxcolor=black@0.65:x=5:y=5,tile=6x6`,'-frames:v','1',dest]);console.log('Detailed',ep,start);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {randomUUID} from 'node:crypto';
|
||||
import {newProject,commit,saveProject} from '../desktop/core/project.mjs';
|
||||
import {importMedia,exportVideo,probe,run,ffmpeg} from '../desktop/core/media.mjs';
|
||||
const out=path.resolve('output','无职转生_30秒燃向卡点');await fs.mkdir(out,{recursive:true});
|
||||
const sources=JSON.parse(await fs.readFile('.test-output/user-cut/sources.json','utf8'));
|
||||
const p=newProject('无职转生 · 30秒超燃卡点 · RTX 5080');p.settings={width:1920,height:1080,fps:60,processingMode:'gpu'};
|
||||
const map=new Map();for(const ep of [5,8,11,21]){const source=sources.find(s=>s.episode===ep),m=await importMedia(source.path,path.join(out,'cache'));m.tags=['动画','动作','魔法',`第${ep}集`];p.media.push(m);map.set(ep,m);}
|
||||
const music=await importMedia(path.join(out,'原创配乐_144BPM.wav'),path.join(out,'cache'));p.media.push(music);
|
||||
// Source positions manually inspected using real extracted video frames, not invented model analysis.
|
||||
const shots=[
|
||||
[21,545.0,4,.9,0,'人物进入对峙'],[5,1037.5,2,.9,.15,'手中火焰蓄力'],[21,666.0,2,1.05,.12,'法术发动前的近景'],
|
||||
[21,548.8,2,1.15,.5,'刀刃冲突'],[21,568.7,2,1.15,.5,'长枪近身交锋'],[21,572.8,1,1.25,.45,'空中兵刃动作'],[21,576.2,1,1.3,.4,'快速斩击'],[21,581.0,2,1.15,.4,'攻击冲击'],
|
||||
[5,1051.6,1,1.05,.5,'火焰爆发'],[5,1059.0,1,.9,0,'人物反应特写'],[5,1075.0,2,1.3,.4,'剑士迎击'],[5,1100.8,2,1.2,.35,'跃起出剑'],
|
||||
[11,648.9,2,1.1,.5,'法杖光芒'],[11,655.1,2,1.15,.4,'巨蛇突袭'],[11,663.0,2,1.2,.35,'翻身近战'],[11,669.3,2,1.2,.4,'长枪攻击'],[11,681.7,2,1.15,.35,'魔术师准备攻击'],
|
||||
[21,674.7,2,.95,.4,'火球聚集'],[21,676.1,2,1.1,.45,'火球掷出'],[21,681.5,1,1.15,.35,'火光穿越画面'],[21,686.4,1,1.2,.35,'攻势衔接'],[21,694.5,2,1.15,.3,'迎击动作'],
|
||||
[21,708.0,2,.9,.4,'火焰环绕'],[21,718.8,2,1.05,.45,'能量球爆发'],[21,729.0,2,.9,.2,'掌中能量蓄力'],[21,731.0,2,1.05,.3,'紫色能量成形'],
|
||||
[21,734.4,2,1.05,.4,'紫色能量扩张'],[21,736.0,2,1.15,.4,'法术释放'],[8,1298.9,2,.95,.5,'巨大光柱出现'],[8,1301.9,2,.9,.5,'能量爆裂'],[8,1303.5,2,1.1,.5,'冲击波扩散'],[8,1305.3,2,1,.5,'光球席卷画面'],
|
||||
[21,573.0,1,1.2,.4,'兵刃衔接'],[5,1076.0,1,1.15,.4,'剑光衔接'],[5,1101.3,2,1.15,.4,'跃击回扣'],
|
||||
[8,1307.4,2,.8,.4,'冲击波延展'],[21,736.6,2,.9,.3,'能量释放收束'],[21,729.6,4,.75,.15,'掌中光球定格式收束']
|
||||
];
|
||||
const totalBeats=shots.reduce((s,x)=>s+x[2],0);if(totalBeats!==72)throw Error('节拍总数不等于72:'+totalBeats);
|
||||
let cursor=0;const beat=60/144,edl=[];
|
||||
const clips=shots.map((shot,i)=>{const [ep,input,beats,speed,volume,reason]=shot,len=beats*beat,m=map.get(ep);const c={id:randomUUID(),track:'video',mediaId:m.id,start:cursor,in:input,out:input+len*speed,speed,volume,fade:0,audioFade:.012,fit:'contain',crop:{x:0,y:.045,width:1,height:.8},saturation:1.12,contrast:1.08,brightness:.012};
|
||||
if(i===0)c.motion=[{time:0,zoom:1,x:.5,y:.45},{time:len,zoom:1.08,x:.5,y:.45}];
|
||||
if(i===shots.length-1){c.fade=.1;c.motion=[{time:0,zoom:1,x:.5,y:.5},{time:len,zoom:1.08,x:.5,y:.5}];}
|
||||
edl.push({index:i+1,episode:ep,sourceIn:input,sourceOut:c.out,timelineStart:cursor,duration:len,beats,speed,reason});cursor+=len;return c;});
|
||||
clips.push({id:randomUUID(),track:'audio',mediaId:music.id,start:0,in:0,out:30,speed:1,volume:.85,audioFade:.08});
|
||||
clips.push({id:randomUUID(),track:'subtitle',start:.15,in:0,out:2.7,speed:1,volume:1,text:'无 职 转 生',color:'#ffffff',fontSize:46});
|
||||
let project=commit(p,clips,'人工查看真实素材后按144BPM建立72拍时间轴');project.messages.push({id:randomUUID(),role:'user',text:'使用指定目录有声视频,制作超燃卡点30秒;使用RTX 5080。',time:new Date().toISOString()},{id:randomUUID(),role:'system',text:'真实视频帧人工核选;144BPM原创器乐,72拍,38个视频片段,保留部分原声动作音效。GPU模式:CUDA视频解码和NVENC中间/最终编码;字幕与部分滤镜使用CPU协同。',time:new Date().toISOString()});
|
||||
const projectFile=path.join(out,'无职转生_30秒燃向卡点.qycut');await saveProject(projectFile,project);await fs.writeFile(path.join(out,'剪辑清单.json'),JSON.stringify({bpm:144,beats:72,shots:edl},null,2));
|
||||
const dest=path.join(out,'无职转生_超燃卡点_30秒_RTX5080.mp4');let last=-1,engines=[];
|
||||
await exportVideo(project,dest,{acceleration:'gpu',bitrate:18000,onEncoder:e=>{engines.push(e);console.log('VIDEO ENCODER',e);}},undefined,(v,d)=>{const n=Math.floor(v*100);if(n!==last){console.log(n+'%',d);last=n;}});
|
||||
const meta=await probe(dest);const v=meta.streams.find(s=>s.codec_type==='video'),a=meta.streams.find(s=>s.codec_type==='audio');if(Math.abs(+meta.format.duration-30)>.06||!a)throw Error('最终输出时长或音轨验证失败');
|
||||
await run(ffmpeg,['-v','error','-hwaccel','cuda','-i',dest,'-f','null','-']);
|
||||
await run(ffmpeg,['-y','-v','error','-hwaccel','cuda','-i',dest,'-vf',"fps=1,scale=320:-2,tile=5x6",'-frames:v','1',path.join(out,'成片联系表.jpg')]);
|
||||
await fs.writeFile(path.join(out,'验证报告.json'),JSON.stringify({duration:Number(meta.format.duration),width:v.width,height:v.height,fps:v.avg_frame_rate,frames:v.nb_frames,videoCodec:v.codec_name,audioCodec:a.codec_name,engines,processingMode:'gpu',bpm:144,beats:72,cuts:shots.length,fileSize:meta.format.size,fullDecode:'passed'},null,2));
|
||||
console.log('DELIVERED',dest);
|
||||
@@ -0,0 +1,9 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {probe,run,ffmpeg} from '../desktop/core/media.mjs';
|
||||
const dir=process.argv[2];if(!dir)throw Error('需要素材目录参数');
|
||||
const out=path.resolve('.test-output/user-cut');await fs.mkdir(path.join(out,'contact'),{recursive:true});
|
||||
const files=(await fs.readdir(dir)).filter(n=>n.endsWith('.mp4')&&!/\.f\d+\./.test(n));const items=[];
|
||||
for(const name of files){const file=path.join(dir,name),j=await probe(file),v=j.streams.find(s=>s.codec_type==='video'),a=j.streams.find(s=>s.codec_type==='audio');items.push({name,path:file,duration:Number(j.format.duration),width:v?.width,height:v?.height,hasAudio:!!a,episode:Number(/~_~_(\d+)/.exec(name)?.[1]||0)});}
|
||||
await fs.writeFile(path.join(out,'sources.json'),JSON.stringify(items,null,2));console.log(JSON.stringify(items,null,2));
|
||||
for(const ep of [5,8,11,12,21]){const m=items.find(m=>m.episode===ep);if(!m)continue;const dest=path.join(out,'contact',`episode-${ep}.jpg`);await run(ffmpeg,['-y','-v','error','-i',m.path,'-vf',"fps=1/40,scale=240:-2,drawtext=fontfile='C\\:/Windows/Fonts/consola.ttf':text='%{pts\\:hms}':fontsize=18:fontcolor=white:box=1:boxcolor=black@0.65:x=5:y=5,tile=6x6",'-frames:v','1',dest]);console.log('Contact sheet',ep);}
|
||||
@@ -0,0 +1,7 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {run,ffmpeg} from '../desktop/core/media.mjs';
|
||||
const sources=JSON.parse(await fs.readFile('.test-output/user-cut/sources.json','utf8'));const out=path.resolve('.test-output/user-cut/selected');await fs.mkdir(out,{recursive:true});
|
||||
const choices=[[21,545.5],[21,549.5],[21,569.5],[21,574.5],[21,581.5],[21,666.5],[21,675.5],[21,687.5],[21,695.5],[21,708.5],[21,720.5],[21,729.5],[21,735.5],[11,649.5],[11,655.5],[11,664.5],[11,676.5],[11,682.5],[11,691.5],[5,1038.5],[5,1053.5],[5,1059.5],[5,1074.5],[5,1101.5],[8,1299.5],[8,1302.5],[8,1305.5]];
|
||||
for(const [ep,t] of choices){const m=sources.find(m=>m.episode===ep);await run(ffmpeg,['-y','-v','error','-hwaccel','cuda','-ss',String(t),'-i',m.path,'-frames:v','1','-vf',"scale=320:-2",path.join(out,`${ep}-${t}.jpg`)]);}
|
||||
console.log('Selected frames',choices.length);
|
||||
@@ -0,0 +1,16 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {createHash} from 'node:crypto';
|
||||
import {loadProject} from '../desktop/core/project.mjs';
|
||||
import {auditExport} from '../desktop/core/export-audit.mjs';
|
||||
import {run,ffmpeg,probe} from '../desktop/core/media.mjs';
|
||||
const dir=path.resolve('output/无职转生_30秒_修订版'),file=path.join(dir,'无职转生_30秒_抽帧复核版_RTX5080.mp4');
|
||||
const p=await loadProject(path.join(dir,'无职转生_修订版.qycut'));
|
||||
const old=JSON.parse(await fs.readFile(path.join(dir,'audit-location.json'),'utf8'));
|
||||
const audit=await auditExport(p,file,{acceleration:'gpu'});
|
||||
const equal=[];for(let i=0;i<audit.pages.length;i++){equal.push((await fs.readFile(audit.pages[i])).equals(await fs.readFile(old.pages[i])));await fs.copyFile(audit.pages[i],path.join(dir,`抽帧检查_第${i+1}页.jpg`));}
|
||||
await fs.writeFile(path.join(dir,'audit-location.json'),JSON.stringify(audit,null,2));
|
||||
const meta=await probe(file);await run(ffmpeg,['-v','error','-hwaccel','cuda','-i',file,'-f','null','-']);
|
||||
const a=await run(ffmpeg,['-hide_banner','-i',file,'-vn','-af','ebur128=peak=true','-f','null','-']);
|
||||
const report={file,sha256:createHash('sha256').update(await fs.readFile(file)).digest('hex'),duration:Number(meta.format.duration),video:meta.streams.find(s=>s.codec_type==='video'),audio:meta.streams.find(s=>s.codec_type==='audio'),fullDecode:'passed',audioLoudness:a.err.slice(-460),sampleCount:audit.sampleCount,reviewedPagePixelsUnchangedAfterAudioAdjustment:equal,manualVisualReview:'23个片段的69张起中尾帧已在会话中实际查看;与源片段内容对照。抽帧检查不替代逐帧动作识别或用户审美验收。',audit};
|
||||
await fs.writeFile(path.join(dir,'全片检查.json'),JSON.stringify(report,null,2));console.log(JSON.stringify({duration:report.duration,frames:report.video.nb_frames,equal,audio:report.audioLoudness,sha256:report.sha256},null,2));
|
||||
Reference in new issue
Block a user