Skip to content

nexu-io/openmotion / skills/openmotion-recreate

openmotion-recreate

Verified

Recreate a reference video (a link or file) as the user's own film with OpenMotion: rebuild it as an editable OpenMotion project and hand it over open in the editor, keeping the original content or swapping in the user's copy, brand and assets. This includes small edits to the user's own finished video when no editable project for it exists. "Make one like this" and "I want this feel" both count as recreation. In a workspace with the user's product material, a bare link alone means "make one like this for us". References that also contain portraits, product photography, live-action or AI footage, narration or music are in scope: those parts use configured media generation while the structure stays editable. Not for only analysing or discussing a video. Use openmotion-director when the reference is only inspiration for an original film, openmotion-template-to-video for an existing template, openmotion-production for edits to an existing editable OpenMotion project, and openmotion-video-to-template for a reusable template package.

scripts/measure_frame.mjs

View on GitHub
#!/usr/bin/env node
// Compare a reference frame and a remix frame with numbers.
//
// Both frames are scaled to the same size so pixel values compare directly.
//
// Whole frame (always reported):
//   mean_luma   average brightness 0-255
//   detail      share of pixels on a sharp edge (lines, labels, wireframes);
//               a lower value means a sparser or blurrier picture
//   accent      share of strongly coloured pixels (brand-colour lines, fills)
//
// Region (with --region): the box around the content that differs from the
// region's background, whichever is lighter or darker. For one line of text its
// height is roughly the cap/ascender height; for a logo it is the logo height.
// A box that touches the region edge usually means the region is too small or
// the content is clipped; touching the frame edge means it is cut off.
//
// Usage:
//   node measure_frame.mjs REF REMIX --t 12.0 [--ref-t 12.4]
//   node measure_frame.mjs REF REMIX --frame 360 [--ref-frame 372]
//        [--region x,y,w,h] [--ref-region x,y,w,h]
//        [--size 1920x1080] [--threshold 60]
// Times are in seconds; regions are in pixels of --size (default: remix size).
// Frame indices are zero-based decoded video frames. Use them for short events
// whose exact frame could be skipped by a rounded seek time.
// ffmpeg/ffprobe: HYPERFRAMES_FFMPEG_PATH / FFMPEG_PATH (and the FFPROBE
// equivalents) when set, then the copies beside the Node running this script,
// then PATH. No npm dependencies.
import { spawnSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import path from 'node:path';
import { parseArgs } from 'node:util';

// The self-contained package keeps Node at runtime/node/bin/node (Windows:
// runtime/node/node.exe) and FFmpeg at runtime/media/bin, but puts neither on
// the agent's PATH; run this script with that Node and it finds FFmpeg itself.
const windows = process.platform === 'win32';
const bundled = path.join(path.dirname(process.execPath), windows ? '..' : '../..', 'media', 'bin');
function binary(name, keys) {
  for (const key of keys) if (process.env[key]) return process.env[key];
  const candidate = path.join(bundled, name + (windows ? '.exe' : ''));
  return existsSync(candidate) ? candidate : name;
}
const ffmpeg = binary('ffmpeg', ['HYPERFRAMES_FFMPEG_PATH', 'FFMPEG_PATH']);
const ffprobe = binary('ffprobe', ['HYPERFRAMES_FFPROBE_PATH', 'FFPROBE_PATH']);

function fail(message) {
  console.error(message);
  process.exit(1);
}

function run(command, args) {
  const result = spawnSync(command, args, { maxBuffer: 1 << 30 });
  if (result.error?.code === 'ENOENT') fail(`${command} not found: set FFMPEG_PATH/FFPROBE_PATH, or run this script with the package's own Node`);
  if (result.error) fail(`${command}: ${result.error.message}`);
  if (result.status !== 0) fail(`${command} failed: ${result.stderr.toString().trim()}`);
  return result.stdout;
}

function probeSize(file) {
  const line = run(ffprobe, ['-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=width,height', '-of', 'csv=p=0', file])
    .toString().trim().split(/\r?\n/)[0];
  const [w, h] = line.split(',').map(Number);
  return [w, h];
}

function rgbFrame(file, selection, w, h) {
  const indexed = selection.frame !== undefined;
  const seek = indexed ? [] : ['-ss', String(selection.time)];
  const select = indexed ? `select=eq(n\\,${selection.frame}),` : '';
  const raw = run(ffmpeg, ['-v', 'error', ...seek, '-i', file, '-frames:v', '1',
    '-vf', `${select}scale=${w}:${h}:flags=area,format=rgb24`,
    ...(indexed ? ['-fps_mode', 'passthrough'] : []), '-f', 'rawvideo', '-']);
  const n = w * h;
  const description = indexed ? `frame ${selection.frame}` : `${selection.time}s`;
  if (raw.length < n * 3) fail(`could not decode ${description} from ${file}`);
  const gray = new Uint8Array(n);
  let chroma = 0;
  for (let i = 0; i < n; i++) {
    const r = raw[i * 3], g = raw[i * 3 + 1], b = raw[i * 3 + 2];
    gray[i] = (77 * r + 150 * g + 29 * b) >> 8;
    if (Math.max(r, g, b) - Math.min(r, g, b) > 60) chroma++;
  }
  return { gray, chroma };
}

function frameSelection(time, frame, fallback, label) {
  if (time !== undefined && frame !== undefined) fail(`Specify only one time or frame index for ${label}`);
  if (frame !== undefined) {
    const index = Number(frame);
    if (frame.trim() === '' || !Number.isSafeInteger(index) || index < 0) fail(`${label} frame index must be a nonnegative safe integer`);
    return { frame: index };
  }
  if (time !== undefined) {
    const seconds = Number(time);
    if (time.trim() === '' || !Number.isFinite(seconds) || seconds < 0) fail(`${label} time must be finite and nonnegative`);
    return { time: seconds };
  }
  return fallback;
}

const round = (value, digits) => Number(value.toFixed(digits));

function wholeFrame({ gray, chroma }, w, h) {
  let edges = 0, sum = 0;
  for (let i = 0; i < gray.length; i++) sum += gray[i];
  for (let y = 0; y < h - 1; y++) {
    for (let x = 0; x < w - 1; x++) {
      const i = y * w + x, v = gray[i];
      if (Math.abs(v - gray[i + 1]) > 24 || Math.abs(v - gray[i + w]) > 24) edges++;
    }
  }
  const n = w * h;
  return { mean_luma: round(sum / n, 1), detail: round(edges / n, 4), accent: round(chroma / n, 4) };
}

function parseRegion(name, value, w, h) {
  const parts = value.split(',').map(Number);
  if (parts.length !== 4 || !parts.every(Number.isInteger)) fail(`--${name} must be four integers x,y,w,h, got "${value}"`);
  const [x, y, rw, rh] = parts;
  if (x < 0 || y < 0 || rw < 2 || rh < 2 || x + rw > w || y + rh > h) {
    fail(`--${name} ${value} must lie inside the ${w}x${h} frame and be at least 2x2 pixels`);
  }
  return parts;
}

function regionBox(gray, w, h, [x0, y0, rw, rh], threshold) {
  const border = [];
  for (let x = x0; x < x0 + rw; x++) border.push(gray[y0 * w + x], gray[(y0 + rh - 1) * w + x]);
  for (let y = y0; y < y0 + rh; y++) border.push(gray[y * w + x0], gray[y * w + x0 + rw - 1]);
  border.sort((a, b) => a - b);
  const bg = border[Math.floor(border.length / 2)];
  let minX = Infinity, maxX = -1, minY = Infinity, maxY = -1;
  for (let y = y0; y < y0 + rh; y++) {
    for (let x = x0; x < x0 + rw; x++) {
      if (Math.abs(gray[y * w + x] - bg) >= threshold) {
        if (x < minX) minX = x;
        if (x > maxX) maxX = x;
        if (y < minY) minY = y;
        maxY = y;
      }
    }
  }
  if (maxY < 0) return { background_luma: bg, bbox: null };
  return {
    background_luma: bg,
    bbox: [minX, minY, maxX - minX + 1, maxY - minY + 1],
    height_px: maxY - minY + 1,
    width_px: maxX - minX + 1,
    touches_region_edge: minX === x0 || minY === y0 || maxX === x0 + rw - 1 || maxY === y0 + rh - 1,
    touches_frame_edge: minX === 0 || minY === 0 || maxX === w - 1 || maxY === h - 1,
  };
}

const { values: a, positionals } = parseArgs({
  allowPositionals: true,
  options: {
    t: { type: 'string' }, 'ref-t': { type: 'string' }, region: { type: 'string' }, 'ref-region': { type: 'string' },
    frame: { type: 'string' }, 'ref-frame': { type: 'string' },
    size: { type: 'string' }, threshold: { type: 'string', default: '60' }, help: { type: 'boolean', short: 'h' },
  },
});
if (a.help || positionals.length !== 2 || (a.t === undefined && a.frame === undefined)) {
  console.log('usage: node measure_frame.mjs REF REMIX (--t SECONDS | --frame INDEX) [--ref-t SECONDS | --ref-frame INDEX] [--region x,y,w,h] [--ref-region x,y,w,h] [--size WxH] [--threshold 60]');
  process.exit(a.help ? 0 : 2);
}
const [refFile, remixFile] = positionals;
const [w, h] = a.size ? a.size.toLowerCase().split('x').map(Number) : probeSize(remixFile);
if (!(Number.isInteger(w) && Number.isInteger(h) && w > 0 && h > 0)) fail(`invalid frame size ${w}x${h}`);
const remixSelection = frameSelection(a.t, a.frame, undefined, 'remix');
const refSelection = frameSelection(a['ref-t'], a['ref-frame'], remixSelection, 'reference');
const threshold = Number(a.threshold);
const refFrame = rgbFrame(refFile, refSelection, w, h), mixFrame = rgbFrame(remixFile, remixSelection, w, h);
const ref = wholeFrame(refFrame, w, h), mix = wholeFrame(mixFrame, w, h);
const out = {
  size: [w, h], ref_t: refSelection.time ?? null, remix_t: remixSelection.time ?? null,
  ref_frame: refSelection.frame, remix_frame: remixSelection.frame, ref, remix: mix,
  brightness_ok: mix.mean_luma >= ref.mean_luma * 0.9,
  detail_ok: mix.detail >= ref.detail * 0.7,
  accent_ok: ref.accent < 0.002 || mix.accent >= ref.accent * 0.6,
};
if (a.region || a['ref-region']) {
  const mixRegion = parseRegion('region', a.region || a['ref-region'], w, h);
  const refRegion = parseRegion('ref-region', a['ref-region'] || a.region, w, h);
  ref.region = regionBox(refFrame.gray, w, h, refRegion, threshold);
  mix.region = regionBox(mixFrame.gray, w, h, mixRegion, threshold);
  // An element that cannot be found must never read as a pass: a missing remix
  // element fails, and an empty reference region means the measurement is blocked.
  if (!ref.region.bbox) {
    out.region_status = 'blocked';
    out.region_error = 'no content in the reference region; choose a region around the reference element and measure again';
    out.height_ok = false;
    out.clipped = null;
  } else if (!mix.region.bbox) {
    out.region_status = 'failed';
    out.region_error = 'no content in the remix region; the element is missing or the region is wrong';
    out.height_ok = false;
    out.clipped = null;
  } else {
    out.region_status = 'measured';
    out.height_ratio = round(mix.region.height_px / ref.region.height_px, 2);
    out.height_ok = mix.region.height_px / ref.region.height_px >= 0.8;
    out.clipped = mix.region.touches_frame_edge;
  }
}
console.log(JSON.stringify(out, null, 2));
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall