fffiloni commited on
Commit
13bc67d
·
verified ·
1 Parent(s): 38ff112

Predecode upcoming frames and keep one clock for every cue

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. assets/playback.js +18 -9
README.md CHANGED
@@ -25,7 +25,7 @@ models:
25
 
26
  A private research prototype for directing a continuous generated shot with short spoken cues. Version 0.2.0.
27
 
28
- Start the microphone, describe a scene and pause briefly. Each accepted direction generates one silent segment at 832 × 480 and 16 fps. The opening segment contains 61 frames (3.8125 s) and subsequent segments contain 64 (4 s). The last generated image stays in the monitor while you think or while the next cue is being interpreted. End session joins completed segments into a downloadable MP4. Microphone mute discards unsubmitted audio and stops capture. Unmute continues the same take. The monitor plays the generated frames on an inline canvas, including on iPhone. JPEG strips are decoded one at a time. The complete take uses a native MP4 player with inline playback and download.
29
 
30
  Fluid Speech Pro transcribes on CPU. Qwen updates the shot description using the last completed direction. FastFrames-S receives one ZeroGPU allocation per segment, with a 60-second maximum runtime for computation and checkpoint I/O. Between directions, the session keeps its exact occupied attention cache, decoder history, frame indices and random generator state on the Space's temporary filesystem. The previous checkpoint is replaced only after the next segment is complete. Ending the take releases the checkpoint. Closing the page or starting another take removes its session workspace. The recordings and resumable state are temporary and do not survive a Space restart.
31
 
 
25
 
26
  A private research prototype for directing a continuous generated shot with short spoken cues. Version 0.2.0.
27
 
28
+ Start the microphone, describe a scene and pause briefly. Each accepted direction generates one silent segment at 832 × 480 and 16 fps. The opening segment contains 61 frames (3.8125 s) and subsequent segments contain 64 (4 s). The last generated image stays in the monitor while you think or while the next cue is being interpreted. End session joins completed segments into a downloadable MP4. Microphone mute discards unsubmitted audio and stops capture. Unmute continues the same take. The monitor plays the generated frames on an inline canvas, including on iPhone. The browser decodes the next JPEG strip during playback and displays the frames on one 16 fps timeline. The complete take uses a native MP4 player with inline playback and download.
29
 
30
  Fluid Speech Pro transcribes on CPU. Qwen updates the shot description using the last completed direction. FastFrames-S receives one ZeroGPU allocation per segment, with a 60-second maximum runtime for computation and checkpoint I/O. Between directions, the session keeps its exact occupied attention cache, decoder history, frame indices and random generator state on the Space's temporary filesystem. The previous checkpoint is replaced only after the next segment is complete. Ending the take releases the checkpoint. Closing the page or starting another take removes its session workspace. The recordings and resumable state are temporary and do not survive a Space restart.
31
 
assets/playback.js CHANGED
@@ -27,19 +27,19 @@ function inlinePlayback(monitor, canvas, onStart, onEnd, onError) {
27
  return {source:img,close:()=>URL.revokeObjectURL(url)};
28
  } catch(error) {URL.revokeObjectURL(url);throw error;}
29
  }
30
- function display(strip, count, signal, first) {
31
  const ctx = canvas.getContext("2d",{alpha:false});
32
  return new Promise(resolve=>{
33
- let tick = 0, start, shown = -1;
34
  function finish(){cancelAnimationFrame(tick);signal.removeEventListener("abort",finish);resolve();}
35
  function frame(now){
36
  if(signal.aborted){finish();return;}
37
- if(start===undefined)start=now;
38
- const position=(now-start)*16/1000;
39
  const index=Math.min(count-1,Math.floor(position));
40
  if(index!==shown){
41
  ctx.drawImage(strip,0,index*480,832,480,0,0,832,480);shown=index;
42
- if(first && index===0)onStart();
43
  }
44
  if(position>=count){finish();return;}
45
  tick=requestAnimationFrame(frame);
@@ -59,10 +59,19 @@ function inlinePlayback(monitor, canvas, onStart, onEnd, onError) {
59
  if(!response.ok)throw new Error("Could not load segment frames");
60
  return response.blob();
61
  }));
62
- for(let i=0;i<blobs.length && !signal.aborted;i++){
63
- const strip=await loadStrip(blobs[i]);
64
- try{await display(strip.source,Math.min(8,cue.frames-8*i),signal,i===0);}
65
- finally{strip.close();}
 
 
 
 
 
 
 
 
 
66
  }
67
  if(!signal.aborted){active=null;onEnd();}
68
  } catch(error) {
 
27
  return {source:img,close:()=>URL.revokeObjectURL(url)};
28
  } catch(error) {URL.revokeObjectURL(url);throw error;}
29
  }
30
+ function display(strip, firstFrame, count, signal, clock) {
31
  const ctx = canvas.getContext("2d",{alpha:false});
32
  return new Promise(resolve=>{
33
+ let tick = 0, shown = -1;
34
  function finish(){cancelAnimationFrame(tick);signal.removeEventListener("abort",finish);resolve();}
35
  function frame(now){
36
  if(signal.aborted){finish();return;}
37
+ if(clock.start===undefined)clock.start=now;
38
+ const position=Math.max(0,(now-clock.start)*16/1000-firstFrame);
39
  const index=Math.min(count-1,Math.floor(position));
40
  if(index!==shown){
41
  ctx.drawImage(strip,0,index*480,832,480,0,0,832,480);shown=index;
42
+ if(firstFrame===0 && index===0)onStart();
43
  }
44
  if(position>=count){finish();return;}
45
  tick=requestAnimationFrame(frame);
 
59
  if(!response.ok)throw new Error("Could not load segment frames");
60
  return response.blob();
61
  }));
62
+ const clock = {};
63
+ let next = loadStrip(blobs[0]);
64
+ // Decode one strip ahead so all frames share a single 16 fps playback clock.
65
+ try {
66
+ for(let i=0;i<blobs.length && !signal.aborted;i++){
67
+ const strip=await next;
68
+ next=i+1<blobs.length ? loadStrip(blobs[i+1]) : null;
69
+ if(next)next.catch(()=>{});
70
+ try{await display(strip.source,i*8,Math.min(8,cue.frames-8*i),signal,clock);}
71
+ finally{strip.close();}
72
+ }
73
+ } finally {
74
+ if(next){try{(await next).close();}catch{}}
75
  }
76
  if(!signal.aborted){active=null;onEnd();}
77
  } catch(error) {