03:00:0050% OFFClaim

Assemble an ordered PNG sequence into a review clip

Validate contiguous PNG names and hashes, reject missing or reordered inputs, then encode three original frames into a 1.5-second review MP4.

Build a review clip from existing still frames with an explicit two-FPS schedule. This is forward sequence assembly, with no generated in-between frames or reverse video frame extraction.

Previously recorded numerical observations below describe the original local fixture runs. For a reproduction, use the new receipt and its actual tool versions and hashes; an old observation is not a guaranteed result on every installation.

Preparation

  • Save each complete code block below under its displayed filename in one empty local folder. Run commands from that folder. The scripts create their synthetic inputs and manifests in the chosen output directory; inspect those files after running. Use an output directory that does not already exist. All relative paths below refer to this working folder.
  • Prepare Node.js and FFmpeg, setting FFMPEG_BIN when needed. The inputs are three original 160×90 PNGs with red, green and blue fields plus a white edge marker.
  • Read sequence.json: indices 1–3 are bound to frame-0001.png through frame-0003.png and their SHA-256 values, at a declared two FPS.
  • Use a new output directory and require the exact input filename set. A visually plausible frame in the wrong sequence is still a manifest failure.

Run

node run-recipe.mjs --out ./my-run

01. Freeze the image sequence

Generate the three practice PNGs and an explicit ordered manifest. Each row contains an index, exact basename and SHA-256. Do not rely on filesystem iteration order, which is not the editorial order of shots.

02. Reject gaps, extra names and wrong bytes

Before encoding, replay a swapped-row manifest, remove frame 2 temporarily, add frame 5 and supply a wrong hash. Each invalid case fails; finally blocks restore the original complete sequence before the actual encode.

03. Encode using the declared input rate

Use -framerate 2 -start_number 1 with frame-%04d.png and an explicit three-frame output cap. The encoder creates review.mp4 using yuv444p and no audio. Each source PNG contributes one frame; the intended duration is 1.5 seconds.

04. Verify frame count and colour order

Fully decode the MP4 and confirm exactly three 160×90 RGB frames. Sample the central field of every frame against its intended red/green/blue input within four channel values. The recorded worst difference is one; no interpolation was added.

Acceptance

  • The three-row manifest exactly matches contiguous frame-0001.png through frame-0003.png.
  • Swapped manifest rows are rejected before encoding.
  • A missing frame and an extra noncontiguous frame are separately rejected.
  • An incorrect expected PNG SHA-256 is rejected.
  • The actual review file decodes to exactly three 160×90 frames at the declared two-FPS assembly schedule.
  • The central colours appear red, green and blue in order within four channel values; all nine checks pass.

Troubleshooting

The clip contains the right images in the wrong order.

Correct only the manifest order and its index-to-filename binding, then rerun preflight before encoding.

Encoding stops early because a numbered frame is missing.

Restore the missing original PNG at the exact basename and hash. Do not silently duplicate its neighbour.

The review plays too quickly.

Change only the declared input framerate and document the new expected duration; preserve the three input identities and rerun frame-order checks.

Keep with the result

Keep sequence.json beside the assembled review. This fixture proves the chosen order and frame count; it does not create motion, extend frame holds beyond the chosen rate or qualify a distribution codec.

Complete source and input construction

Save every file below with its exact filename in the same folder. The source includes the input definitions and construction logic; code blocks are complete, including all companion modules.

common.mjs

import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { createHash } from 'node:crypto';
import { deflateSync } from 'node:zlib';
import { spawnSync } from 'node:child_process';
import http from 'node:http';
export { fs, path, http };
export const sha = b => createHash('sha256').update(b).digest('hex');
export const ensure = (v,m) => { if (!v) throw new Error(m); };
export const json = (p,v) => fs.writeFileSync(p,JSON.stringify(v,null,2)+'\n');
export function png(w,h,colour) {
  const raw=Buffer.alloc(h*(w*3+1));
  for(let y=0;y<h;y++) for(let x=0;x<w;x++) { const c=typeof colour==='function'?colour(x,y):colour; for(let k=0;k<3;k++) raw[y*(w*3+1)+1+x*3+k]=c[k]; }
  const crc=b=>{let c=0xffffffff;for(const n of b){c^=n;for(let j=0;j<8;j++)c=(c>>>1)^((c&1)?0xedb88320:0);}return(c^0xffffffff)>>>0;};
  const chunk=(t,b)=>{const n=Buffer.alloc(4),s=Buffer.from(t),c=Buffer.alloc(4);n.writeUInt32BE(b.length);c.writeUInt32BE(crc(Buffer.concat([s,b])));return Buffer.concat([n,s,b,c]);};
  const head=Buffer.alloc(13);head.writeUInt32BE(w);head.writeUInt32BE(h,4);head[8]=8;head[9]=2;
  return Buffer.concat([Buffer.from([137,80,78,71,13,10,26,10]),chunk('IHDR',head),chunk('IDAT',deflateSync(raw)),chunk('IEND',Buffer.alloc(0))]);
}
export function dimensions(b){ensure(b.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10])),'PNG_SIGNATURE');return[b.readUInt32BE(16),b.readUInt32BE(20)];}
export const maxDelta=(a,b)=>{ensure(a.length===b.length,'BYTE_LENGTH');let d=0;for(let i=0;i<a.length;i++)d=Math.max(d,Math.abs(a[i]-b[i]));return d;};
export const safeName=s=>typeof s==='string'&&/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/.test(s);
export async function request(url,method='GET',body){
  const u=new URL(url);ensure(u.hostname==='127.0.0.1'&&u.protocol==='http:','LOOPBACK_ONLY');
  return await new Promise((resolve,reject)=>{const q=http.request(u,{method,agent:false,headers:body?{'content-type':'application/json'}:{}},r=>{let size=0;const a=[];r.on('data',b=>{size+=b.length;if(size>2*1024*1024){r.destroy(new Error('RESPONSE_LIMIT'));return;}a.push(b);});r.on('error',reject);r.on('end',()=>resolve({status:r.statusCode,body:Buffer.concat(a)}));});q.setTimeout(3000,()=>q.destroy(new Error('HTTP_TIMEOUT')));q.on('error',reject);q.end(body===undefined?undefined:JSON.stringify(body));});
}
export async function closeServer(server){await new Promise((resolve,reject)=>{server.close(e=>e?reject(e):resolve());server.closeAllConnections();});}
export async function run(task,fn,media=false){
 const here=path.dirname(fileURLToPath(import.meta.url));const args=process.argv.slice(2);ensure(args.length===0||(args.length===2&&args[0]==='--out'),'USAGE: node run-recipe.mjs --out NEW_DIRECTORY');
 const out=path.resolve(args[1]||path.join(here,'my-run'));ensure(!fs.existsSync(out),'REFUSE_OVERWRITE');fs.mkdirSync(out,{recursive:true});
 const tmp=path.join(out,'.tmp');fs.mkdirSync(tmp);const tests=[],failures=[],commands=[];const scripts=Object.fromEntries(['run-recipe.mjs','common.mjs'].map(n=>[n,sha(fs.readFileSync(path.join(here,n)))]));
 const h={out,tmp,info:{},p:n=>path.join(out,n),check:(name,v,detail={})=>{ensure(v,`CHECK_FAILED:${name}`);tests.push({name,passed:true,...detail});},reject:(name,fn,pattern)=>{let e;try{fn();}catch(x){e=x;}ensure(e&&(!pattern||pattern.test(e.message)),`EXPECTED_REJECTION_MISSING:${name}`);const r={name,passed:true,expectedRejection:true,error:String(e.message).slice(0,900)};tests.push(r);failures.push(r);}};
 const bin=process.env.FFMPEG_BIN||'ffmpeg';
 h.ff=(args,allowFailure=false)=>{const all=['-hide_banner','-nostdin','-loglevel','error','-threads','1','-filter_threads','1',...args];const r=spawnSync(bin,all,{shell:false,timeout:15000,killSignal:'SIGKILL',maxBuffer:8*1024*1024});commands.push({args:all,status:r.status,signal:r.signal,stdoutBytes:r.stdout?.length||0,stderrTail:r.stderr?.toString().slice(-1800)||'',error:r.error?.message||null});if(!allowFailure)ensure(!r.error&&r.status===0,`FFMPEG:${r.error?.message||r.stderr?.toString().slice(-900)}`);return r;};
 h.decode=(file,w,hgt)=>{const r=h.ff(['-xerror','-err_detect','explode','-i',file,'-map','0:v:0','-an','-pix_fmt','rgb24','-f','rawvideo','pipe:1']);ensure(r.stdout.length>0&&r.stdout.length%(w*hgt*3)===0,'DECODE_GEOMETRY');return r.stdout;};
 let fatal=null;let ffmpeg=null;
 try{if(media){const r=h.ff(['-version']);ffmpeg={version:r.stdout.toString().split('\n')[0],binarySha256:path.isAbsolute(bin)?sha(fs.readFileSync(bin)):null};}await fn(h);ensure(tests.length>=6,'AT_LEAST_SIX_CHECKS');}
 catch(e){fatal=e.stack||String(e);process.exitCode=1;}
 finally{fs.rmSync(tmp,{recursive:true,force:true});const scriptsAfter=Object.fromEntries(Object.keys(scripts).map(n=>[n,sha(fs.readFileSync(path.join(here,n)))]));if(JSON.stringify(scriptsAfter)!==JSON.stringify(scripts)){fatal='SCRIPT_CHANGED_DURING_RUN';process.exitCode=1;}
 const receipt={task,recordedAt:new Date().toISOString(),nodeVersion:process.version,ffmpeg,scriptHashes:scripts,scriptBindingVerified:JSON.stringify(scriptsAfter)===JSON.stringify(scripts),fixtureOnly:true,providerModelTest:false,productionTaskRun:false,networkScope:'loopback-only or no network',passed:!fatal,checks:tests,observations:h.info,commands,fatal};json(h.p('execution-receipt.json'),receipt);json(h.p('failure-receipt.json'),{task,expectedFailureChecks:failures});fs.writeFileSync(h.p('checks.csv'),'check,result,expected_rejection\n'+tests.map(t=>`${t.name},${t.passed?'pass':'fail'},${Boolean(t.expectedRejection)}`).join('\n')+'\n');console.log(JSON.stringify({task,passed:!fatal,checks:tests.length,expectedRejections:failures.length,out}));if(fatal)console.error(fatal);}
}

run-recipe.mjs

import {fs,path,png,sha,json,ensure,safeName,run} from './common.mjs';
await run('frame-sequence-to-review-clip',async h=>{
 const dir=h.p('frames');fs.mkdirSync(dir);const colours=[[220,40,30],[30,200,60],[30,60,220]];const manifest=colours.map((c,i)=>{const file=`frame-${String(i+1).padStart(4,'0')}.png`;fs.writeFileSync(path.join(dir,file),png(160,90,(x,y)=>x<10?[245,245,245]:c));return{index:i+1,file,sha256:sha(fs.readFileSync(path.join(dir,file)))};});json(h.p('sequence.json'),{fps:2,frames:manifest});
 const validate=rows=>{ensure(rows.length===3,'FRAME_COUNT');rows.forEach((r,i)=>{ensure(r.index===i+1&&r.file===`frame-${String(i+1).padStart(4,'0')}.png`&&safeName(r.file),'FRAME_ORDER');ensure(fs.existsSync(path.join(dir,r.file)),'MISSING_FRAME');ensure(sha(fs.readFileSync(path.join(dir,r.file)))===r.sha256,'FRAME_HASH');});ensure(JSON.stringify(fs.readdirSync(dir).sort())===JSON.stringify(rows.map(r=>r.file).sort()),'EXTRA_FRAME');return true;};h.check('ordered-contiguous-input-accepted',validate(manifest));h.reject('swapped-order-rejected',()=>validate([manifest[1],manifest[0],manifest[2]]),/FRAME_ORDER/);fs.renameSync(path.join(dir,manifest[1].file),h.tmp+'/missing.png');try{h.reject('missing-frame-rejected',()=>validate(manifest),/MISSING_FRAME/);}finally{fs.renameSync(h.tmp+'/missing.png',path.join(dir,manifest[1].file));}fs.writeFileSync(path.join(dir,'frame-0005.png'),png(160,90,[2,3,4]));try{h.reject('noncontiguous-extra-frame-rejected',()=>validate(manifest),/EXTRA_FRAME/);}finally{fs.unlinkSync(path.join(dir,'frame-0005.png'));}h.reject('wrong-file-bytes-rejected',()=>validate(manifest.map((r,i)=>i===0?{...r,sha256:'0'.repeat(64)}:r)),/FRAME_HASH/);
 const out=h.p('review.mp4');h.ff(['-framerate','2','-start_number','1','-i',path.join(dir,'frame-%04d.png'),'-frames:v','3','-an','-c:v','libx264','-crf','0','-pix_fmt','yuv444p',out]);const decoded=h.decode(out,160,90);h.check('three-complete-frames-exported',decoded.length===3*160*90*3);let worst=0;for(let i=0;i<3;i++){const offset=(i*160*90+45*160+80)*3;const got=[...decoded.subarray(offset,offset+3)];const d=Math.max(...got.map((v,k)=>Math.abs(v-colours[i][k])));worst=Math.max(worst,d);h.check(`colour-order-frame-${i+1}`,d<=4,{rgb:got,maxDelta:d});}h.info={frameCount:3,fps:2,expectedDurationSeconds:1.5,width:160,height:90,worstColourDelta:worst,scope:'forward image-sequence assembly; no model interpolation'};
},true);

Technical references

Assemble an ordered PNG sequence into a review clip — Original task diagram; not a model output
Original task diagram; not a model output
Assemble an ordered PNG sequence into a review clip