34 lines
1.9 KiB
JavaScript
34 lines
1.9 KiB
JavaScript
export function nativeVideoGraph(template, request, files, prefix) {
|
|
if (!files.hero) throw new Error('Identity still is required; never substitute the start frame.')
|
|
const g=structuredClone(template), s=request.settings
|
|
g.hero.inputs.image=files.hero
|
|
Object.assign(g['155'].inputs,{prompt:request.compiledPrompt,width:s.width,height:s.height,length:Math.ceil((s.duration*24-5)/17)*17+5,ref_image_size:'max'})
|
|
g['155'].inputs['ref_images.ref_image_0']=['hero',0]
|
|
let conditioning=['155',0]
|
|
for (const [name,image,frame] of [['start',files.start,0],['end',files.end,-1],...(files.guides||[]).map((f,i)=>[`guide${i}`,f.image,f.frame])]) {
|
|
if (!image) continue
|
|
g[`load_${name}`]={class_type:'LoadImage',inputs:{image}}
|
|
g[name]={class_type:'MiniMaxH3AddGuide',inputs:{positive:conditioning,latent:['155',1],vae:['161',0],image:[`load_${name}`,0],frame_idx:frame}}
|
|
conditioning=[name,0]
|
|
}
|
|
g.guidance.inputs={conditioning,guidance:s.cfg}
|
|
g['171'].inputs.noise_seed=s.seed
|
|
g['179'].inputs.value=s.steps;g['180'].inputs.value=s.steps;g['181'].inputs.value=s.turbo
|
|
g['92'].inputs.filename_prefix=prefix+'/video'
|
|
g.anchor_frame={class_type:'ImageFromBatch',inputs:{image:['164',0],batch_index:-1,length:1}}
|
|
g.anchor_save={class_type:'SaveImage',inputs:{images:['anchor_frame',0],filename_prefix:prefix+'/anchor'}}
|
|
return g
|
|
}
|
|
export function attachHeroReference(g, image) {
|
|
if (!image) return g
|
|
const guider = g['18']; if (!guider) throw new Error('Klein reference conditioning is missing.')
|
|
g.hero_load={class_type:'LoadImage',inputs:{image}}
|
|
g.hero_encode={class_type:'VAEEncode',inputs:{pixels:['hero_load',0],vae:['6',0]}}
|
|
for (const name of ['positive','negative']) {
|
|
if (!guider.inputs[name]) continue
|
|
g[`hero_${name}`]={class_type:'ReferenceLatent',inputs:{conditioning:guider.inputs[name],latent:['hero_encode',0]}}
|
|
guider.inputs[name]=[`hero_${name}`,0]
|
|
}
|
|
return g
|
|
}
|