Skip to content

One-click character swap for videos: an open-source, local Higgsfield Genjutsu alternative built on ComfyUI and MiniMax H3, with FLUX.3 Klein relighting.

Compare the source and the result with a before/after wipe (#3)

mixbag20d1e0f068e7
diff --git a/app/globals.css b/app/globals.css
index 7b31627..092e6ec 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -177,3 +177,23 @@ input[type="range"] { accent-color: var(--accent); width: 220px; max-width: 100%
.photo-pick { background: var(--bg); align-items: center; }
.photo-pick button { padding: 3px; }
.photo-pick img { width: 34px; height: 44px; object-fit: cover; border-radius: 5px; display: block; }
+
+.compare {
+ position: relative; aspect-ratio: var(--ratio); width: min(100%, 70vh * var(--ratio)); justify-self: center;
+ border-radius: 12px; overflow: hidden; background: #000;
+}
+.compare video { position: absolute; inset: 0; height: 100%; max-height: none; object-fit: contain; }
+.compare .before { pointer-events: none; clip-path: inset(0 calc(100% - var(--split)) 0 0); }
+.compare-label { position: absolute; top: 10px; left: 10px; padding: 2px 8px; border-radius: 99px; background: #000a; font-size: 0.78em; pointer-events: none; }
+.compare-label.after { left: auto; right: 10px; }
+.compare-line { position: absolute; top: 0; bottom: 0; left: var(--split); width: 24px; margin-left: -12px; cursor: ew-resize; touch-action: none; }
+.compare-line::before { content: ""; position: absolute; top: 0; bottom: 0; left: 11px; width: 2px; background: var(--accent); }
+.compare-line::after {
+ content: ""; position: absolute; top: 50%; left: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%;
+ background: var(--accent); box-shadow: 0 0 0 3px #0008;
+}
+.compare-line:focus-visible { outline: none; }
+.compare-line:focus-visible::after { box-shadow: 0 0 0 3px var(--text); }
+/* Keep the result's native controls visible while they are shown. */
+.compare:hover .before, .compare.paused .before { clip-path: inset(0 calc(100% - var(--split)) 72px 0); }
+.compare:hover .compare-line, .compare.paused .compare-line { bottom: 72px; }
diff --git a/components/openjutsu.tsx b/components/openjutsu.tsx
index 25c5248..1654d26 100644
--- a/components/openjutsu.tsx
+++ b/components/openjutsu.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, useRef, useState, type DragEvent, type ReactNode } from "react";
+import { useEffect, useRef, useState, type CSSProperties, type DragEvent, type PointerEvent, type ReactNode } from "react";
import type { PublicJob } from "../lib/comfy.ts";
import type { SetupRequest, SetupResult } from "../lib/setup.ts";
import type { NodeInfo } from "../lib/progress.ts";
@@ -617,6 +617,7 @@ export function Openjutsu() {
{run ? (
<RunView
run={run} job={job} progress={progress} preview={preview} streamError={streamError} now={now}
+ before={video ? { url: video.url, start: whole ? 0 : part.start } : null}
onCancel={cancel} onReset={reset} onFix={fixResult} onGenerate={video && character && !submitting && mode === "simple" ? () => submit("simple") : null}
margin={margin} onMargin={setMargin} onRecheck={video && !submitting ? () => submit("mask") : null}
photos={shown.map((c) => c.url)}
@@ -986,8 +987,9 @@ export function Openjutsu() {
);
}
-function RunView({ run, job, progress, preview, streamError, now, onCancel, onReset, onFix, onGenerate, margin, onMargin, onRecheck, photos, onMontage, frames }: {
+function RunView({ run, job, progress, preview, streamError, now, before, onCancel, onReset, onFix, onGenerate, margin, onMargin, onRecheck, photos, onMontage, frames }: {
run: Run; job: PublicJob | null; progress: Progress | null; preview: string; streamError: string; now: number;
+ before: { url: string; start: number } | null;
onCancel: () => void; onReset: () => void; onFix: (post: Post) => void; onGenerate: (() => void) | null;
margin: Margin; onMargin: (margin: Margin) => void; onRecheck: (() => void) | null;
photos: string[]; onMontage: ((tracks: string, labels: Label[]) => void) | null; frames: string;
@@ -1018,7 +1020,7 @@ function RunView({ run, job, progress, preview, streamError, now, onCancel, onRe
if (status === "succeeded" && job?.video) {
return (
<section className="panel result">
- <video src={job.video.url} controls autoPlay playsInline />
+ {before ? <Compare before={before} after={job.video.url} /> : <video src={job.video.url} controls autoPlay playsInline />}
{run.kind === "montage" && job.data && <KeptNote url={job.data} />}
<div className="row">
<a className="primary" href={`${job.video.url}?download`} download={job.video.name}>Download MP4</a>
@@ -1072,6 +1074,68 @@ function RunView({ run, job, progress, preview, streamError, now, onCancel, onRe
);
}
+// The result plays with its own controls; the source follows it from the start of the part used, clipped to the left of the divider.
+function Compare({ before, after }: { before: { url: string; start: number }; after: string }) {
+ const result = useRef<HTMLVideoElement>(null);
+ const source = useRef<HTMLVideoElement>(null);
+ const [split, setSplit] = useState(50);
+ const [ratio, setRatio] = useState(16 / 9);
+ const [paused, setPaused] = useState(true);
+
+ function follow(drift = 0) {
+ const r = result.current, s = source.current;
+ if (!r || !s) return;
+ const target = r.currentTime + before.start;
+ if (Math.abs(s.currentTime - target) > drift) s.currentTime = target;
+ }
+
+ function play() {
+ const s = source.current;
+ if (!s || !result.current) return;
+ s.playbackRate = result.current.playbackRate;
+ follow();
+ s.play().catch(() => {});
+ setPaused(false);
+ }
+
+ function pause() {
+ source.current?.pause();
+ follow();
+ setPaused(true);
+ }
+
+ function drag(event: PointerEvent<HTMLDivElement>) {
+ const box = event.currentTarget.parentElement!.getBoundingClientRect();
+ setSplit(Math.min(100, Math.max(0, ((event.clientX - box.left) / box.width) * 100)));
+ }
+
+ return (
+ <div className={`compare ${paused ? "paused" : ""}`} style={{ "--split": `${split}%`, "--ratio": ratio } as CSSProperties}>
+ <video
+ ref={result} src={after} controls autoPlay playsInline
+ onLoadedMetadata={(event) => event.currentTarget.videoHeight && setRatio(event.currentTarget.videoWidth / event.currentTarget.videoHeight)}
+ onPlay={play} onPause={pause} onSeeking={() => follow()} onTimeUpdate={() => follow(0.1)}
+ onRateChange={(event) => { if (source.current) source.current.playbackRate = event.currentTarget.playbackRate; }}
+ />
+ <video ref={source} className="before" src={before.url} muted playsInline preload="auto" aria-hidden onLoadedMetadata={() => follow()} />
+ <span className="compare-label">Before</span>
+ <span className="compare-label after">After</span>
+ <div
+ className="compare-line" role="slider" tabIndex={0} aria-label="Before and after divider"
+ aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(split)}
+ onPointerDown={(event) => { event.currentTarget.setPointerCapture(event.pointerId); drag(event); }}
+ onPointerMove={(event) => event.currentTarget.hasPointerCapture(event.pointerId) && drag(event)}
+ onKeyDown={(event) => {
+ const step = event.key === "ArrowLeft" ? -5 : event.key === "ArrowRight" ? 5 : 0;
+ if (!step) return;
+ event.preventDefault();
+ setSplit((current) => Math.min(100, Math.max(0, current + step)));
+ }}
+ />
+ </div>
+ );
+}
+
function MaskCheck({ url, clipSeconds, checked, margin, onMargin, onRecheck, onGenerate, onBack }: {
url: string; clipSeconds: number; checked: Margin; margin: Margin; onMargin: (margin: Margin) => void;
onRecheck: (() => void) | null; onGenerate: (() => void) | null; onBack: () => void;