import fs from 'node:fs/promises'; import path from 'node:path'; import {ffmpeg,run,probe} from './media.mjs'; import {duration} from './project.mjs'; // Sampling is evidence for a person to review, never an automatic semantic approval. export async function auditExport(project,file,options={},signal,progress){ file=path.resolve(file); const meta=await probe(file,signal),v=meta.streams.find(s=>s.codec_type==='video'); if(!v)throw Error('导出文件没有视频流'); const fps=project.settings.fps,total=Number(meta.format.duration),count=Number(v.nb_frames)||Math.round(total*fps); const shots=project.clips.filter(c=>c.track==='video').sort((a,b)=>a.start-b.start); const samples=shots.flatMap((c,i)=>{ const first=Math.round(c.start*fps),last=Math.min(count-1,Math.round((c.start+duration(c))*fps)-1); return [first,Math.floor((first+last)/2),last].map((frame,j)=>({clip:i+1,clipId:c.id,position:['起帧','中帧','尾帧'][j],frame,time:frame/fps,sourceTime:c.reverse?c.out-(frame/fps-c.start)*c.speed:c.in+(frame/fps-c.start)*(c.speed||1),mediaId:c.mediaId})); }).filter(s=>s.frame>=0&&s.frame({clip:0,position:'全片',frame,time:frame/fps}))); const dir=await fs.mkdtemp(file+'.frames-'),raw=path.join(dir,'frames');await fs.mkdir(raw); const unique=[...new Set(samples.map(s=>s.frame))].sort((a,b)=>a-b); const font=(process.platform==='win32'?path.join(process.env.WINDIR||'C:/Windows','Fonts','consola.ttf'):'/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf').replaceAll('\\','/').replaceAll(':','\\:'); // Batch expressions to stay below Windows process command line limits on large projects. let serial=1;for(let begin=0;begin`eq(n,${n})`).join('+')}',scale=384:216,drawtext=fontfile='${font}':text='%{pts\\:hms}':fontsize=19:fontcolor=white:box=1:boxcolor=black@0.8:x=5:y=5`,'-fps_mode','vfr','-start_number',String(serial),'-frames:v',String(frames.length),path.join(raw,'%06d.jpg')],{signal});serial+=frames.length;progress?.(.5*serial/unique.length,'提取成片起帧、中帧、尾帧'); } const pages=[]; for(let i=0;i