Skip to content

feat: add Motion Studio (motion-graphics Shorts with a talking host) - #1783

Open
ashifhusainoo7 wants to merge 8 commits into
harry0703:mainfrom
ashifhusainoo7:feature/motion-studio
Open

ashifhusainoo7 wants to merge 8 commits into
harry0703:mainfrom
ashifhusainoo7:feature/motion-studio

Conversation

@ashifhusainoo7

@ashifhusainoo7 ashifhusainoo7 commented Nov 8, 2026 •

Copy link
Copy Markdown

Summary

Adds Motion Studio, an opt-in way to make vertical Shorts as word-timed motion graphics (big text, numbers and cards) with an animated character, instead of stock-footage stitching. It runs inside the existing API server at /studio/.

  • Character: upload a .glb (rigged models get jaw/eye/brow/wing animation; any other model bobs, turns and talks) or an image, or use none.
  • Script writer: the user picks provider, model and key (OpenAI, Anthropic, Gemini, OpenRouter, DeepSeek, Ollama, any OpenAI-compatible endpoint) through LiteLLM. The key is used for that job only and is never stored, logged or echoed.
  • Pipeline: LLM storyboard (validated, one repair round; scripts over 120 words, about 55 s, get one shortening round) -> voice -> headless Chrome renders frames piped into ffmpeg -> MP4.
  • Voice: free Edge TTS per beat (exact word timings), or OpenAI gpt-4o-mini-tts Marin/Cedar for a more natural single take. The OpenAI voices use the creator's OpenAI key from the request (never the server's); word times come from whisper-1 and are matched back to the script, so captions keep the script's spelling.
  • Palettes: seven colour palettes (same ink, paper, type and host; text contrast checked on each). Each new video gets the one used longest ago, so back-to-back videos never look the same.
  • Publishing: one-click "upload kit" (opens YouTube Studio, copies description and hashtags, downloads the MP4), because YouTube can't receive files or prefilled fields from another site.

Changes

  • New: app/controllers/v1/motion.py, app/models/motion.py, app/services/motion/, resource/motion/ (scene engine, three.js r178 MIT, Baloo 2 OFL), webui-studio/ (React + Vite source), resource/public/studio/ (built UI, committed so Python-only users need no Node), docs/motion-studio.md, scripts/motion_smoke.py, tests.
  • Touched: app/router.py (+1 router), app/asgi.py (static mount /motion-engine, .js MIME fix, and validation errors on /api/v1/motion/* no longer echo request input), pyproject.toml (optional extra motion = ["playwright>=1.49"]; resource/motion added to the wheel and sdist), README.md and README-en.md (one feature line each).
  • No change to existing flows. Every new route uses verify_token.

Notes for maintainers

  • uv.lock includes the new motion extra (playwright and greenlet only; no other package changes). uv lock --check passes, and uv sync --frozen works with and without --extra motion.
  • Playwright is optional. Without it, /api/v1/motion/options reports renderer.installed: false and the studio shows the install command.
  • Job status is in memory (one render at a time, 3 queued); finished jobs and uploads are swept after 7 days.

Test plan

  • pytest -q test/services/test_motion.py: 49 tests covering storyboard schema, writer repair, script length cap, palette rotation, OpenAI voice alignment and key handling, key never echoed, env-key fallback blocked, uploads and path traversal, voice timing, renderer loop (with a stand-in Playwright), job runner, cancel and timeout, API routes and auth. New code: 85% branch coverage.
  • Full suite passes locally; CI's ruff check and compileall steps are clean (also checked with a Python 3.11 syntax target)
  • scripts/motion_smoke.py renders the fixture storyboard end to end
  • Full UI run against a mock OpenAI-compatible provider: upload, generate, progress, video, YouTube kit, mobile 390px
  • Run against a real provider: OpenAI gpt-5-mini, Hindi voice, two full videos (about 2.5 min each); the key was not found in job files, the server log or API responses. The first run showed three issues, fixed in 9d24aa0: URL tokens split in captions, a word orphaned by the caption length cap, and number words in the description
  • OpenAI Marin voice on two real videos: word timings monotonic, beats and captions line up; key not found in job files or logs
  • uv lock --check, uv export --frozen --extra motion, and fresh uv sync --frozen --python 3.11 with and without --extra motion
  • Linux/Docker render check (developed on Windows)

Adds an opt-in studio at /studio/ that turns a title, topic, key points
and a character (.glb model, image or none) into a 1080x1920
motion-graphics Short: word-timed text, numbers and cards with an
animated host, instead of stock-footage stitching.

- Script writer via LiteLLM with a per-request key (OpenAI, Anthropic,
  Gemini, OpenRouter, DeepSeek, Ollama, OpenAI-compatible). The key is
  never stored, logged or echoed, and never falls back to server env keys.
- Storyboard JSON validated with pydantic, with one repair round.
- Edge TTS per beat for exact timing; headless Chrome frames piped into
  ffmpeg in a killable subprocess (optional extra: motion = playwright).
- YouTube upload kit: opens YouTube Studio, copies description and
  hashtags, downloads the MP4 (YouTube accepts no prefilled uploads).
- React + Vite source in webui-studio/; built output committed to
  resource/public/studio/ so Python-only users need no Node.
- Docs in docs/motion-studio.md; tests in test/services/test_motion.py.
- Join spoken tokens the script writes without spaces, so captions show
  "cybercrime.gov.in" instead of "cybercrime . gov . in".
- Split long caption phrases into even chunks instead of capping at six
  words, which could leave one word alone ("follow करना मत | भूलें").
- Tell the writer to use digits in the outro label and YouTube description;
  number words are for narration only.
The prompt now asks for 90 to 115 words, never more than 120. A script that
still runs over 120 words gets one round asking for about 105; if that
answer is invalid, longer or the provider fails, the original script is
kept, so length never fails a job. A real run of the same brief went from
182 words (77 s) to 108 words (48 s).
Every video used the same lilac/lime/coral look. Now each job gets the
palette the latest jobs used longest ago (lilac, peach, sky, bubblegum,
mint, butter, aqua), so back-to-back videos never share one, including
after a server restart.

Ink, paper, type and shapes stay fixed, and every palette keeps the same
OKLCH lightness structure, so the videos still read as one channel.
Checked: ink on stage >= 10:1, muted text >= 5:1, ink on accent >= 12:1.
The hard-coded "good" card colour is now var(--accent-deep).
Edge TTS records each beat separately, which resets the intonation every
few seconds. OpenAI voices read the whole script in one directed take with
gpt-4o-mini-tts; whisper-1 then returns word times, which are matched back
to the script's words (spelling variants such as आवाज़/आवाज or call/कौल
included), so captions keep the script's spelling and beats stay timed.

OpenAI voices reuse the script writer's OpenAI key: the API rejects them
with another provider, the key now lives in the job frame until the voice
is recorded, it is passed explicitly (never the server's env key), and
OpenAI errors become plain messages without the key.
…s word

A hook whose emphasis word came 9.5 s into the scene showed no number for
9 seconds. The main visual now pops on the emphasis word but no later than
1.6 s into the scene (compare: the second card by half-way).
… another

An English brief produced English cards and an English disclaimer in a
Hindi video.
@harry0703

Copy link
Copy Markdown
Owner

Thanks for putting this together. I tried the renderer locally with a small three-beat storyboard, real Edge TTS, Chrome and FFmpeg. It produced a valid 1080x1920 video with audio, and the frontend build passed too. That run used no character and no paid LLM, so it doesn't cover the full feature set.

One installation issue needs fixing: pyproject.toml adds the motion extra, but uv.lock hasn't been updated. These commands reproduce it on the current head:

uv export --frozen --extra motion --format requirements-txt --no-hashes
error: Extra `motion` is not defined in the project's `optional-dependencies` table

uv lock --check
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided.

This blocks using Motion Studio through the frozen dependency workflow. Installing Playwright manually let my render run, but that bypasses the project's lockfile and doesn't fix the reproducible install path. I haven't found this to break the existing video workflow.

Please update the lockfile and check both the default frozen install and the install with --extra motion. The 49 targeted tests passed locally, but they don't catch this dependency mismatch. I'll hold off on merging until that's fixed. Thanks again for the work on the studio.

uv lock with the motion optional dependency: adds playwright 1.65.0 and greenlet 3.5.6 and the motion extra; no other package changes. uv lock --check passes, and uv sync --frozen works with and without --extra motion.
@ashifhusainoo7

Copy link
Copy Markdown
Author

Thanks for testing it. Fixed in 1895c34: uv.lock now includes the motion extra (adds playwright 1.65.0 and greenlet 3.5.6; no other packages change). On that head, uv lock --check passes, uv export --frozen --extra motion --format requirements-txt --no-hashes lists playwright, and a fresh uv sync --frozen --python 3.11 installs without Playwright, while --extra motion adds it.

@ashifhusainoo7

Copy link
Copy Markdown
Author

Thanks for testing it. Fixed in 1895c34: uv.lock now includes the motion extra (adds playwright 1.65.0 and greenlet 3.5.6; no other packages change). On that head, uv lock --check passes, uv export --frozen --extra motion --format requirements-txt --no-hashes lists playwright, and a fresh uv sync --frozen --python 3.11 installs without Playwright, while --extra motion adds it.

@harry0703

@ashifhusainoo7

ashifhusainoo7 commented Nov 20, 2026 •

Copy link
Copy Markdown
Author

Hi @harry0703 i have done the changes and validated everything. Now if you can have a look and merge it, would be really hepful. I can understand that you would be occupied with lots of other things, still i would request to have a look at it if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants