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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review: wire ltx2 video controls
Adam Eivya4aee30e6e87
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsxindex 1792c5fd3a..b9170b91be 100644--- a/client/src/pages/VideoGen.jsx+++ b/client/src/pages/VideoGen.jsx@@ -121,6 +121,7 @@ export default function VideoGen() {const [chunks, setChunks] = useState(1);const [steps, setSteps] = useState('');const [guidanceScale, setGuidanceScale] = useState('');+ const [imageStrength, setImageStrength] = useState('');const [seed, setSeed] = useState('');const [tiling, setTiling] = useState('auto');const [disableAudio, setDisableAudio] = useState(false);@@ -358,6 +359,7 @@ export default function VideoGen() {// a2v uses uploaded audio so the constraint is meaningless there too.setDisableAudio(false);setNoMusic(false);+ setChunks(1);// Auto-select the smallest (first) ltx2-runtime model so the user// doesn't land on a blocked state. Only fires when the current model// can't handle a2v — if they already have a dgrauet model selected@@ -443,6 +445,7 @@ export default function VideoGen() {tiling,disableAudio: disableAudio ? 'true' : 'false',mode,+ imageStrength: imageStrength || '',// ltx2-extend bypasses the last-frame i2v path: we send the source// video's history id directly so the server resolves it to a disk// path and routes through ExtendPipeline. Legacy extend (mlx_video)@@ -458,7 +461,7 @@ export default function VideoGen() {// Audio File goes through under the multipart field 'audioFile'. Server// routes it to the durable uploads dir and into the a2v helper.audioFile: mode === 'a2v' ? (audioFile || '') : '',- chunks: chunks > 1 ? chunks : '',+ chunks: mode !== 'a2v' && chunks > 1 ? chunks : '',};};@@ -1026,22 +1029,24 @@ export default function VideoGen() {)}</div>- <div>- <label className="block text-xs font-medium text-gray-400 mb-1" title="Chain N renders end-to-end. Each chunk's last frame seeds the next, then they're stitched into one clip. Wall time scales linearly with chunks.">- Chunks- </label>- <select- value={chunks}- onChange={(e) => setChunks(Number(e.target.value))}- className="w-full bg-port-bg border border-port-border rounded-lg px-2 py-2 text-sm text-white focus:outline-none focus:border-port-accent disabled:opacity-50"- >- {[1, 2, 3, 4, 5, 6, 7, 8].map((n) => (- <option key={n} value={n}>- {n === 1 ? '1 (single)' : `${n} (~${((n * numFrames) / fps).toFixed(0)}s total)`}- </option>- ))}- </select>- </div>+ {mode !== 'a2v' && (+ <div>+ <label className="block text-xs font-medium text-gray-400 mb-1" title="Chain N renders end-to-end. Each chunk's last frame seeds the next, then they're stitched into one clip. Wall time scales linearly with chunks.">+ Chunks+ </label>+ <select+ value={chunks}+ onChange={(e) => setChunks(Number(e.target.value))}+ className="w-full bg-port-bg border border-port-border rounded-lg px-2 py-2 text-sm text-white focus:outline-none focus:border-port-accent disabled:opacity-50"+ >+ {[1, 2, 3, 4, 5, 6, 7, 8].map((n) => (+ <option key={n} value={n}>+ {n === 1 ? '1 (single)' : `${n} (~${((n * numFrames) / fps).toFixed(0)}s total)`}+ </option>+ ))}+ </select>+ </div>+ )}<div><label className="block text-xs font-medium text-gray-400 mb-1">FPS</label>@@ -1101,6 +1106,22 @@ export default function VideoGen() {/></div>+ {(mode === 'image' || (mode === 'extend' && currentModel?.runtime !== 'ltx2')) && (+ <div className="col-span-2 sm:col-span-3">+ <div className="flex items-center justify-between gap-3 mb-1">+ <label className="block text-xs font-medium text-gray-400">Image Strength</label>+ <span className="text-[11px] text-gray-500">{imageStrength || '1.0'}</span>+ </div>+ <input+ type="range" min={0} max={1} step={0.05}+ value={imageStrength || 1}+ onChange={(e) => setImageStrength(e.target.value)}+ className="w-full accent-port-accent"+ title="Higher values preserve the source frame more strongly"+ />+ </div>+ )}+<div className="col-span-2 sm:col-span-3"><label className="block text-xs font-medium text-gray-400 mb-1">Tiling</label><select@@ -1303,4 +1324,3 @@ export default function VideoGen() {</div>);}-diff --git a/scripts/generate_ltx2.py b/scripts/generate_ltx2.pyindex 1a6ac0c378..dcefb2b8de 100644--- a/scripts/generate_ltx2.py+++ b/scripts/generate_ltx2.py@@ -87,6 +87,8 @@ def parse_args() -> argparse.Namespace:help="One-stage steps; for fflf this maps to stage1-steps")p.add_argument("--stage2-steps", type=int, default=None)p.add_argument("--cfg-scale", type=float, default=None)+ p.add_argument("--image-strength", type=float, default=None,+ help="First-frame conditioning strength for image mode (0.0-1.0).")p.add_argument("--dev-transformer", default=None,help="Filename of the non-distilled (dev) transformer inside the model repo. ""Required for fflf mode — KeyframeInterpolationPipeline rejects pure-distilled "@@ -113,11 +115,76 @@ def parse_args() -> argparse.Namespace:return p.parse_args()+def bind_output_fps(pipe, fps: float) -> None:+ """Make pipeline generate_and_save() calls decode at the requested FPS."""+ decode_and_save = pipe._decode_and_save_video++ def decode_with_fps(video_latent, audio_latent, output_path, fps=fps):+ return decode_and_save(video_latent, audio_latent, output_path, fps=fps)++ pipe._decode_and_save_video = decode_with_fps+++def configure_image_strength(image_strength: float | None) -> None:+ """Thread PortOS' I2V strength into ltx-2-mlx conditioning constructors."""+ if image_strength is None:+ return+ if image_strength < 0.0 or image_strength > 1.0:+ raise SystemExit("--image-strength must be between 0.0 and 1.0")++ from ltx_core_mlx.conditioning.types.latent_cond import VideoConditionByLatentIndex as BaseCondition+ from ltx_pipelines_mlx import ti2vid_one_stage++ class PortOSVideoCondition(BaseCondition):+ def __init__(self, frame_indices, clean_latent, strength=1.0):+ super().__init__(frame_indices, clean_latent, strength=image_strength)++ ti2vid_one_stage.VideoConditionByLatentIndex = PortOSVideoCondition+ try:+ from ltx_pipelines_mlx import ti2vid_two_stages+ ti2vid_two_stages.VideoConditionByLatentIndex = PortOSVideoCondition+ except ImportError:+ pass+ emit_status(f"Using image strength {image_strength:g}")+++def run_two_stage(args: argparse.Namespace, image: str | None = None) -> str:+ """T2V/I2V path that honors CFG via the dgrauet two-stage pipeline."""+ from ltx_pipelines_mlx import TwoStagePipeline+ emit_status(f"Loading two-stage pipeline ({args.model})…")+ emit_stage(1, 0, 1, "Loading model")+ pipe = TwoStagePipeline(+ model_dir=args.model,+ gemma_model_id=args.gemma,+ dev_transformer=args.dev_transformer or "transformer-dev.safetensors",+ distilled_lora=args.distilled_lora or "ltx-2.3-22b-distilled-lora-384.safetensors",+ distilled_lora_strength=args.lora_strength,+ )+ bind_output_fps(pipe, args.fps)+ emit_stage(1, 1, 1, "Loaded")+ emit_status("Generating with CFG…")+ return pipe.generate_and_save(+ prompt=args.prompt,+ output_path=args.output,+ image=image,+ height=args.height,+ width=args.width,+ num_frames=args.num_frames,+ seed=args.seed,+ stage1_steps=args.steps if args.steps is not None else 30,+ stage2_steps=args.stage2_steps,+ cfg_scale=args.cfg_scale if args.cfg_scale is not None else 3.0,+ )++def run_text(args: argparse.Namespace) -> str:+ if args.cfg_scale is not None:+ return run_two_stage(args)from ltx_pipelines_mlx import TextToVideoPipelineemit_status(f"Loading T2V pipeline ({args.model})…")emit_stage(1, 0, 1, "Loading model")pipe = TextToVideoPipeline(model_dir=args.model, gemma_model_id=args.gemma)+ bind_output_fps(pipe, args.fps)emit_stage(1, 1, 1, "Loaded")emit_status("Generating T2V…")return pipe.generate_and_save(@@ -132,12 +199,18 @@ def run_text(args: argparse.Namespace) -> str:def run_image(args: argparse.Namespace) -> str:+ configure_image_strength(args.image_strength)+ if args.cfg_scale is not None:+ if not args.image:+ raise SystemExit("--image is required for image mode")+ return run_two_stage(args, image=args.image)from ltx_pipelines_mlx import ImageToVideoPipelineif not args.image:raise SystemExit("--image is required for image mode")emit_status(f"Loading I2V pipeline ({args.model})…")emit_stage(1, 0, 1, "Loading model")pipe = ImageToVideoPipeline(model_dir=args.model, gemma_model_id=args.gemma)+ bind_output_fps(pipe, args.fps)emit_stage(1, 1, 1, "Loaded")emit_status("Generating I2V…")return pipe.generate_and_save(diff --git a/server/routes/videoGen.js b/server/routes/videoGen.jsindex 6ea2f54eae..7694f6bf94 100644--- a/server/routes/videoGen.js+++ b/server/routes/videoGen.js@@ -327,6 +327,8 @@ router.post('/', frameImageUpload, asyncHandler(async (req, res) => {extendFromVideoPath = candidate;}+ const effectiveChunks = body.mode === 'a2v' ? 1 : (body.chunks ?? 1);+// Enqueue rather than spawn synchronously — the mediaJobQueue worker will// run this when no other render is in flight. Caller never sees BUSY.const { jobId, position, status } = enqueueJob({@@ -353,7 +355,7 @@ router.post('/', frameImageUpload, asyncHandler(async (req, res) => {extendFromVideoPath,mode: body.mode,imageStrength: body.imageStrength,- chunks: body.chunks ?? 1,+ chunks: effectiveChunks,},});// Match the legacy response shape (jobId, generationId, filename, model,diff --git a/server/routes/videoGen.test.js b/server/routes/videoGen.test.jsindex 4a90e24125..a08d1e679c 100644--- a/server/routes/videoGen.test.js+++ b/server/routes/videoGen.test.js@@ -207,6 +207,25 @@ describe('videoGen routes', () => {}));});+ it('forces audio-to-video submissions to a single chunk', async () => {+ setPendingUpload({+ fieldname: 'audioFile',+ originalname: 'song.wav',+ mimetype: 'audio/wav',+ path: '/tmp/song.wav',+ });+ const r = await request(app).post('/api/video-gen/').send({+ prompt: 'sync to the track',+ mode: 'a2v',+ chunks: 4,+ });+ expect(r.status).toBe(200);+ expect(mediaJobQueue.enqueueJob).toHaveBeenCalledWith(expect.objectContaining({+ kind: 'video',+ params: expect.objectContaining({ mode: 'a2v', chunks: 1 }),+ }));+ });+it('rejects chunks above the 1..8 cap', async () => {const r = await request(app).post('/api/video-gen/').send({prompt: 'too long',diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.jsindex 464e74b594..32f1b5e99e 100644--- a/server/services/videoGen/local.js+++ b/server/services/videoGen/local.js@@ -87,7 +87,7 @@ export const saveHistory = (h) => atomicWrite(HISTORY_FILE, h);// The helper lives in the ltx-2-mlx venv (so its `import ltx_pipelines_mlx`// resolves) but the script file lives in the PortOS repo so updates ship// with PortOS releases instead of the user's HF cache.-const buildLtx2Args = ({ model, prompt, negativePrompt, width, height, numFrames, fps, steps, guidance, seed, sourceImagePath, lastImagePath, extendFromVideoPath, audioFilePath, mode, disableAudio, outputPath, textEncoderRepo }) => {+const buildLtx2Args = ({ model, prompt, negativePrompt, width, height, numFrames, fps, steps, guidance, seed, sourceImagePath, lastImagePath, extendFromVideoPath, audioFilePath, mode, imageStrength, disableAudio, outputPath, textEncoderRepo }) => {if (!existsSync(LTX2_VENV_PYTHON)) {throw new ServerError(`ltx-2-mlx venv not found at ${LTX2_VENV_PYTHON}. Run \`INSTALL_LTX2=1 bash scripts/setup-image-video.sh\` to install.`,@@ -171,6 +171,7 @@ const buildLtx2Args = ({ model, prompt, negativePrompt, width, height, numFrames'--cfg-scale', String(guidance),];if (negativePrompt) args.push('--negative-prompt', negativePrompt);+ if (imageStrength != null) args.push('--image-strength', String(imageStrength));if (disableAudio) args.push('--no-audio');if (helperMode === 'image' && sourceImagePath) args.push('--image', sourceImagePath);if (helperMode === 'fflf') {@@ -202,7 +203,7 @@ const buildArgs = ({ pythonPath, modelId, model, prompt, negativePrompt, width,// runtime. Existing notapalindrome models default to runtime: 'mlx_video'// (or undefined in legacy registries — see backfillRuntime in mediaModels.js).if (model.runtime === 'ltx2') {- return buildLtx2Args({ model, prompt, negativePrompt, width, height, numFrames, fps, steps, guidance, seed, sourceImagePath, lastImagePath, extendFromVideoPath, audioFilePath, mode, disableAudio, outputPath, textEncoderRepo });+ return buildLtx2Args({ model, prompt, negativePrompt, width, height, numFrames, fps, steps, guidance, seed, sourceImagePath, lastImagePath, extendFromVideoPath, audioFilePath, mode, imageStrength, disableAudio, outputPath, textEncoderRepo });}if (mode === 'a2v') {throw new ServerError(@@ -826,6 +827,7 @@ export async function stitchVideos(videoIds, opts = {}) {proc.on('close', (code) => code === 0 ? resolve() : reject(new ServerError('Stitch failed', { status: 500, code: 'FFMPEG_FAILED' })));proc.on('error', (err) => reject(new ServerError(`ffmpeg failed to spawn: ${err.message}`, { status: 500, code: 'FFMPEG_FAILED' })));});+ await optimizeForStreaming(outPath);} finally {await unlink(listFile).catch(() => {});}