Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

3.2 KB
Raw Blame
// Shared resolution presets for video generation. Companion to
// `imageGenResolutions.js` — both the image and video generators feed their
// preset table into the shared `components/media/ResolutionField.jsx` control
// (preset dropdown + "Custom…" W×H), so the size UX stays consistent across both.
//
// Video sizes follow LTX-2's preferred latent boundaries (multiples of 64 on
// each edge); the aspect-ratio hints in the labels surface common shapes the
// user picks for (16:9 social, 9:16 vertical, 2:3 portrait, 1:1 grid).
export const VIDEO_RESOLUTIONS = [
  { label: '512×320 (16:10)', w: 512, h: 320 },
  { label: '640×384 (5:3)', w: 640, h: 384 },
  { label: '704×448 (16:10)', w: 704, h: 448 },
  { label: '768×512 (3:2 default)', w: 768, h: 512 },
  { label: '1024×576 (16:9)', w: 1024, h: 576 },
  { label: '576×1024 (9:16)', w: 576, h: 1024 },
  { label: '512×768 (portrait)', w: 512, h: 768 },
  { label: '512×512 (1:1)', w: 512, h: 512 },
  { label: '768×768 (1:1)', w: 768, h: 768 },
  // Append so aspect-based I2V defaults keep their existing quality canvas.
  { label: '384×256 (small preview)', w: 384, h: 256 },
  { label: '256×384 (small portrait preview)', w: 256, h: 384 },
];

export const DEFAULT_VIDEO_RESOLUTION = { w: 768, h: 512 };

// A few runtimes have a trained canvas that materially differs from LTX's
// shared preset list. MiniMax H3, for example, expects a 768px short edge and
// resolves 16:9 to 1344x768. Keep those options on the model registry (beside
// its frame/fps capabilities) and fall back to the shared LTX-friendly list for
// every existing/custom model that does not declare one.
export const resolutionOptionsForModel = (model) => (
  Array.isArray(model?.resolutionOptions) && model.resolutionOptions.length > 0
    ? model.resolutionOptions
    : VIDEO_RESOLUTIONS
);

export const defaultResolutionForModel = (model) => {
  const width = Number(model?.defaultWidth);
  const height = Number(model?.defaultHeight);
  return width > 0 && height > 0
    ? { w: width, h: height }
    : { ...DEFAULT_VIDEO_RESOLUTION };
};

// Pick the preset whose aspect ratio is closest to a source image's, so an I2V
// default doesn't cover-crop the subject out of a mismatched frame (the server
// resizes the source with force_original_aspect_ratio=increase,crop). Every
// preset already satisfies its model's declared resolution grid, so the
// nearest-aspect preset needs no additional rounding here. Aspect
// error is compared in log space so a too-wide and an equally-too-tall preset
// are penalised symmetrically. Returns `{ w, h }`, or null when the inputs are
// unusable (non-positive dims / empty preset list) so the caller can no-op.
export const snapAspectToImage = (presets, imgW, imgH) => {
  const w = Number(imgW);
  const h = Number(imgH);
  if (!(w > 0) || !(h > 0) || !Array.isArray(presets) || presets.length === 0) return null;
  const target = w / h;
  let best = null;
  let bestErr = Infinity;
  for (const p of presets) {
    if (!(p?.w > 0) || !(p?.h > 0)) continue;
    const err = Math.abs(Math.log((p.w / p.h) / target));
    if (err < bestErr) { bestErr = err; best = p; }
  }
  return best ? { w: best.w, h: best.h } : null;
};