ai
3 мин
17 ноября 2026 г.
Источник: Dev.to AI Feed

Build a one-shot video prompt composer in plain JavaScript

maqiang ma
maqiang ma
RSS AI Ingest
Build a one-shot video prompt composer in plain JavaScript

A short video brief becomes easier to review when it separates what is in the shot from what moves. This small JavaScript example turns a structured shot description into a prompt you can copy into a video tool. It runs locally, makes no ne...

A short video brief becomes easier to review when it separates what is in the shot from what moves. This small JavaScript example turns a structured shot description into a prompt you can copy into a video tool. It runs locally, makes no network requests, and does not generate a video. Model one shot, not a whole sequence Use one subject, one main action, one setting and one camera move. This makes later comparisons easier to interpret. It does not guarantee the model will follow every instruction. const normalize = (value) => String(value ?? "").trim().replace(/\s+/g, " "); function composeShot(input) { const shot = Object.fromEntries( Object.entries(input).map(([key, value]) => [key, normalize(value)]) ); for (const key of ["subject", "action", "setting"]) { if (!shot[key]) throw new Error(`Missing ${key}`); } return [ `${shot.subject} ${shot.action} in ${shot.setting}.`, shot.camera && `Camera: ${shot.camera}.`, shot.light && `Lighting: ${shot.light}.`, shot.keep && `Keep consistent: ${shot.keep}.`, ].filter(Boolean).join(" "); } const base = { subject: "A lavender running shoe", action: "turns slightly on a display stand", setting: "a quiet cream-colored studio", camera: "locked-off medium close-up", light: "soft daylight from the left", keep: "shoe color, sole shape and plain background", }; console.log(composeShot(base)); console.log(composeShot({ ...base, camera: "slow push-in" })); The two outputs differ only in the camera field. You can inspect that change before spending a generation attempt. The second output is an alternative brief, not evidence that the rendered clips will differ only in camera motion: generative outputs are stochastic. Add a few meaningful checks const prompt = composeShot(base); console.assert(prompt.includes("Camera: locked-off medium close-up.")); console.assert(!prompt.includes("undefined")); let rejectedBlankSubject = false; try { composeShot({ ...base, subject: " " }); } catch { rejectedBlankSubject = true; } console.assert(rejectedBlankSubject); These checks cover a required-field failure and an optional-field formatting problem. They do not test visual quality. In a UI, show validation errors beside the relevant input, keep the composed prompt editable and offer a copy button. Avoid inserting a long style preset the user cannot see. Text first or image first? For text to video, include enough information to establish the subject and setting. For image to video, the starting image already provides visual context, so concentrate the written brief on the motion and the elements you want to preserve. Upload only material you are entitled to use. You can try the workflow in FreeGenVideo, a Free AI Video Generator. It supports text prompts and starting images in the browser with no sign-up or login. The current allowance is one free video per day, resetting at 00:00 UTC; check the generator for available output options. This post does not claim a generation was run for either sample brief. Review the result separately from the prompt A well-formed prompt can still produce an unsuitable clip. Check subject continuity, object shape, background changes and unwanted camera movement. Keep the input brief next to the result so you can describe what actually changed. With a limited daily allowance, it helps to refine the brief locally first, then choose one variation intentionally. Keep a small record of the prompt and the observed result, rather than interpreting a single clip as a reliable benchmark. Disclosure: this article was prepared autonomously with AI assistance as part of FreeGenVideo outreach. The JavaScript is a local prompt composer, not a FreeGenVideo API integration.

Хотите внедрить ИИ в ваш бренд?

Спроектируем и развернем автономных агентов и современный цифровой стек под ваши задачи.

Рассчитать проект