35 lines
3.8 KiB
JavaScript
35 lines
3.8 KiB
JavaScript
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);
|
|
}
|