# tein-video-workflow

Adopt this skill: https://proskills.md/skills/other/sirioberati-genjustsu-open-source-workflow-agents-skills-tein-video-workflow

Page: https://proskills.md/skills/other/sirioberati-genjustsu-open-source-workflow-agents-skills-tein-video-workflow
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: .agents/skills/tein-video-workflow/SKILL.md
size: 3627
sha: 29d94fd7f481dc4e92ab12e221d717ac29afacae
upstream: https://github.com/sirioberati/genjustsu-open-source-workflow/blob/main/.agents/skills/tein-video-workflow/SKILL.md

```text
---
name: tein-video-workflow
description: Run this project's depth, SAM 3 and Enhancor video subject replacement workflow, including full-clip mask review, draft generation, retrieval, and approved HD export.
---

Read the project root AGENTS.md and docs/AGENT-OPERATIONS.md before running a job. Resolve the root as the folder containing workflow.py, not a machine-specific path. Consult docs/ENHANCOR-API.md for request routing and recovery and docs/MEDIA-HOSTING.md before changing upload providers.

Use workflow.py and the local UI; do not recreate credentials or hardcode prior users' media, subjects or request IDs. Carry authorized preparation and collection through to the final preview. Full-clip visual mask QA is mandatory before any generation; if you cannot inspect the video, ask the user to review it. Fix coverage failures with raw masks and, when needed, original-RGB segmentation; preserve the depth model's colors. Approval is invalid after artifact changes.

Prepare +3-semitone isolated vocals inside the video. Route an image identity reference to Edit and video identity reference to Omni. Show the exact prompt and honor the authorized submission scope. Restore the entire original soundtrack on return. Inspect saved request IDs before retrying; resume retrieval instead of duplicating paid requests. Ask before HD unless explicitly approved already. Bound repair attempts to the authorized scope; stop and explain persistent provider or visual failures rather than claiming success.

## Fast alternative: face mesh

Choose **Fast · Face mesh** in the UI, or use `workflow.py prepare VIDEO --mode face_mesh`. Install the optional worker once with `bash setup-face-mesh.sh` (Python 3.12 required; isolated `.venv-face`). The model downloads from Google's official storage on first use.

This path keeps the original video, tracks and saves facial landmarks, draws the mesh, isolates vocals and embeds the +3 pitched vocals. It makes **no depth or SAM calls**. It is currently designed for a single centered speaker; inspect all frames and stop on tracking gaps or incorrect face alignment. Do not claim mask review in this mode: review facial tracking and audio instead. Saved artifact hashes gate submission.

Use the same character references, draft-first submission, collection, original-audio restoration and explicitly approved HD upgrade. In the prompt, explain that mesh lines are motion guidance and must disappear, replace the complete original identity including hair, and preserve all dialogue and timing. Image reference uses Edit; video identity uses Omni. Keep advanced depth mode available. Do not submit automatically during setup.

### Combined depth + face mesh

Select **Advanced + Face mesh** in the UI or use `workflow.py prepare VIDEO --mode depth_mesh`. This runs the original depth/SAM pipeline, preserves its depth composite, then tracks the face from the original frames and overlays the mesh onto that composite. Landmarks are saved in `face-landmarks.json`. Review BOTH mask coverage and face tracking before approval. All artifacts, including depth, mask, mesh and embedded audio, are bound to review approval. Follow the same draft → approved HD → original-audio restoration flow.

For setup with all three preparation modes, also install Python 3.12 and run `bash setup-face-mesh.sh`. This creates an isolated mesh environment; the main app can retain its existing Python version. A Google Face Landmarker model is downloaded at first use. No SAM/depth inference is used by fast mode. Mesh modes are experimental and currently optimized for one centered speaker.
```

## File: README.md
upstream: https://github.com/sirioberati/genjustsu-open-source-workflow/blob/main/README.md

````text
<p align="center">
  <a href="https://tein.ai"><img src="docs/branding/tein-ai-banner.svg" width="960" alt="TEIN AI — Open-source AI workflows. Click to join the waitlist." /></a>
</p>
<p align="center"><a href="https://tein.ai"><strong>Join TEIN AI →</strong></a></p>

<p align="center">
  <a href="examples/advanced-black-nodes-v8-audio.mp4"><img src="examples/previews/workflow.gif" width="28%" alt="Workflow animation — click for full video with audio" /></a>
  <a href="examples/1006%20%281%29.mp4"><img src="examples/previews/example-1.gif" width="34%" alt="Example 1 — click for full video with audio" /></a>
  <a href="examples/1006%20%281%29%283%29.mp4"><img src="examples/previews/example-2.gif" width="34%" alt="Example 2 — click for full video with audio" /></a>
</p>
<p align="center"><em>Click any preview to open its full video with audio.</em></p>

<h1 align="center"> Genjustsu — Open Source Workflow</h1>
<p align="center">Your scene. New characters.</p>
<p align="center">
  <a href="https://tein.ai"><strong>Join TEIN AI</strong></a> ·
  <a href="https://enhancor.ai"><strong>Get the Seedance API</strong></a> ·
  <a href="docs/SETUP-AGENT.md">Agent setup</a> ·
  <a href="examples/README.md">Examples</a> ·
  <a href="LICENSE">MIT license</a>
</p>

A local UI and agent-assisted workflow for replacing video subjects using colored depth, SAM 3 masks and Seedance through Enhancor. Draft first; approve before 1080p. The final export restores the **entire original source audio**, not generated audio.

## Get access

- **[Sign up at TEIN.ai](https://tein.ai)** for early access: “The cheapest APIs, open source workflows, and more.”
- **[Get the Seedance API at Enhancor.ai](https://enhancor.ai)** — this workflow uses its Seedance integration with human-face support (`pass_faces: true`), draft previews, and approved 1080p generation. Get your own key from the [API dashboard](https://app.enhancor.ai/api-dashboard). Current the lowest price in the market; with unrestricted use.

## Easiest setup: let your coding agent install it

Extract the ZIP, open **this folder** in Codex or another coding agent with terminal/file access, and paste:

> Set up this TEIN Genjustsu — Open Source Workflow project for me. Read `docs/SETUP-AGENT.md` and follow it end to end. Detect my OS, install missing Python/Rubber Band/cloudflared prerequisites using the supported package manager, create the main virtual environment, install dependencies, install Python 3.12 and run `bash setup-face-mesh.sh` for both mesh modes, and create `.env` without overwriting it. Open `.env` so I can enter my own keys privately. Run the local tests, launch the app and its callback-only tunnel, run the strict readiness check on a free localhost port, verify the UI and companion images, and give me the working URL. Work independently through setup, respecting system permission prompts. Do not submit paid generations. If keys are missing, launch the UI and clearly tell me generation is waiting for them.

The launcher starts a callback-only Quick Tunnel when no custom webhook is configured. Keep it running with the app. The agent uses the included [setup runbook](docs/SETUP-AGENT.md). You only need to supply your own provider keys and approve any required system installation. No separate agent install is required. Native Windows users should use WSL2; macOS/Linux launch scripts are included.

## Manual setup

1. Install Python 3.12+ (the development runtime was Python 3.14) and Rubber Band CLI:
   - macOS: `brew install rubberband cloudflared`
   - Ubuntu/Debian or WSL: `sudo apt install rubberband-cli python3-venv`
   - Install [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/) too, unless you already have a public HTTPS webhook receiver. On launch it creates a temporary callback-only tunnel; the UI and media stay on localhost.
2. In this folder, run `bash setup.sh`. This creates an isolated `.venv`, installs `requirements.txt`, creates a blank `.env`, and checks dependencies. To enable all three modes, install Python 3.12 and run `bash setup-face-mesh.sh`, then `.venv/bin/python doctor.py --mesh`. On macOS, install the worker interpreter with `brew install python@3.12` if needed.
3. Fill `.env` with **your own** `ENHANCOR_API_KEY` and `REPLICATE_API_TOKEN`. Get them from [Enhancor](https://app.enhancor.ai/api-dashboard) and [Replicate](https://replicate.com/account/api-tokens). Fund/enable the relevant API accounts. `HF_TOKEN` is optional for the Hugging Face depth alternative.
4. Run `./start.command` (or `bash start.command`). Open **http://127.0.0.1:8770**. Use `PORT=8771 bash start.command` if the port is occupied.
   - Once running, check `.venv/bin/python doctor.py --require-keys`. Enhancor requires a webhook URL: `launch.py` supplies one through cloudflared, or you can set `ENHANCOR_WEBHOOK_URL` yourself. Keep the app/tunnel running.
5. Upload your own MP4/MOV, prepare it, inspect the entire mask and prepared video, approve that exact mask, provide your own character references, review the prompt, and create a draft.
6. When you like the draft, click the 1080p approval button. The completed draft and HD result remain separate; both final previews use source audio.

No local model weights or GPU are needed for the default hosted setup. Python packages and the Rubber Band executable are required locally. No API keys, signed media URLs, or old jobs are included. Four user-selected demonstration videos are included in `examples/`. The bundled TEIN companion artwork is part of the UI.

## What happens

1. Save the source unchanged; extract audio and separate vocals/music with Demucs on Replicate.
2. Pitch isolated vocals **+3 semitones**, maintaining duration with Rubber Band.
3. Normalize the working video to 24 fps, up to 960 pixels; obtain colored depth with `lucataco/depth-anything-video`. Preserve returned colors.
4. Use SAM 3 raw PNG masks on depth. Check alignment, coverage and background spill. An agent can retry segmentation on the original RGB if depth loses detail.
5. Composite the depth subject over the original background. Mandatory full-clip visual mask review gates every generation. Approval is bound to hashes of the current artifacts.
6. Embed the pitched vocals into the composite MP4. Send this video, **no standalone audio**, with character references.
7. Enhancor Seedance **Edit** for image references; **Omni / multi_reference** for a video identity reference. Generate a draft by default.
8. Poll for completion, download the result, discard its audio and copy the complete original soundtrack into the final MP4.
9. After explicit HD approval, complete the accepted draft at 1080p and restore the soundtrack again.

## Autonomous agent operation

Open this folder in your coding agent and ask it to follow `AGENTS.md` and `.agents/skills/tein-video-workflow/SKILL.md`. No particular agent vendor or model is required, but it must be able to inspect video and files, run Python, and access the network. An agent service is **not** bundled or silently started. The UI/server automates processing and result collection; the agent or user performs visual QA and creative review.

Example: “Use the Genjustsu workflow for my clip and references. Prepare and inspect the entire mask, repair it if needed, show the prompt, submit the authorized draft, and retrieve the final preview. Wait for my approval before HD.”

See [agent operations](docs/AGENT-OPERATIONS.md), [API integration](docs/ENHANCOR-API.md), [models](docs/MODELS.md), [media hosting](docs/MEDIA-HOSTING.md), and [troubleshooting](docs/TROUBLESHOOTING.md).

## Recovery and checks

```bash
.venv/bin/python doctor.py --require-keys
.venv/bin/python test_composite.py
.venv/bin/python -m unittest discover -s tests
.venv/bin/python workflow.py status LOCAL_JOB_ID
.venv/bin/python workflow.py resume LOCAL_JOB_ID
.venv/bin/python workflow.py resume LOCAL_JOB_ID --hd
```

The server resumes saved Se
````
