Compare commits

..
95 Commits
Author SHA1 Message Date
chris.dumas a4063ef60a Replace H3 nodes with generic sequential video tools 2026-10-11 10:15:36 +00:00
chris.dumas b5eb941c4b Keep curator auxiliary refs input-aligned 2026-09-17 16:02:27 +00:00
chris.dumas bfaa5fa733 Merge latest upstream Long Videos 2026-09-17 15:57:25 +00:00
chris.dumas 9923a3e417 Add handoff context frames 2026-09-10 11:44:18 +00:00
chris.dumas ea6fae7e56 Align beat prompt with upstream Long Videos 2026-09-10 10:34:53 +00:00
chris.dumas 72f9b07ed8 Replace Long Videos with upstream sampler 2026-09-10 09:46:37 +00:00
chris.dumas 8d4232a142 Restore compiled prompt reference descriptions 2026-09-10 08:34:32 +00:00
chris.dumas d68d04254f Prune stale prompt curator outputs 2026-09-10 08:30:42 +00:00
chris.dumas 22398c5213 Simplify H3 prompt curator component outputs 2026-09-10 08:26:39 +00:00
chris.dumas 1a4cfbfd7e Add compiled prompt reference output pairs 2026-09-10 08:15:33 +00:00
chris.dumas eac4e73b47 Expose individual prompt reference descriptions 2026-09-10 07:59:11 +00:00
chris.dumas e973a0d785 Expose H3 prompt curator components 2026-09-09 15:34:06 +00:00
chris.dumas 388de1d837 Sync helper preset text boxes 2026-09-07 13:26:29 +00:00
chris.dumas 338150648b Add BGM helper for H3 prompt curator 2026-09-07 08:13:45 +00:00
chris.dumas 7de62226f2 Strip legacy anchor style note 2026-09-07 08:01:22 +00:00
chris.dumas a51141cb26 Add location helper reference outputs 2026-09-07 07:46:24 +00:00
chris.dumas dd8ef84379 Add character helper reference outputs 2026-09-05 18:00:17 +00:00
chris.dumas d20b257134 Add H3 prompt subject count guard 2026-09-05 17:54:43 +00:00
chris.dumas 173205ca51 Add H3 prompt curator 2026-09-05 16:43:05 +00:00
chris.dumas 98833ba99d Restore general character and location helpers 2026-09-04 15:52:40 +00:00
chris.dumas a7f7225b3a Bypass learned latent upscaler on low VRAM 2026-09-04 15:24:30 +00:00
chris.dumas 5dc5c2ce8b Prioritize temporal fallback for latent upscale OOM 2026-09-04 15:10:38 +00:00
chris.dumas 83645811f4 Reuse conditioning for refinement tiles 2026-09-04 14:52:43 +00:00
chris.dumas 216bc05762 Retry temporal split after latent upscale OOM 2026-09-04 14:43:25 +00:00
chris.dumas 49e099ee7f Log H3 latent upscale tiling plan 2026-09-04 14:14:24 +00:00
chris.dumas 32a16645b5 Use adaptive CUDA latent upscale chunking 2026-09-04 12:09:59 +00:00
chris.dumas 7bb0b0abea Reuse conditioning for latent upscale refine 2026-09-04 11:49:21 +00:00
chris.dumas 0b189dcf7a Keep latent upscaler loaded during pass 2026-09-04 11:04:26 +00:00
chris.dumas e8599055a1 Force temporal chunks for CUDA latent upscale 2026-09-04 10:22:41 +00:00
chris.dumas 618a48e4d9 Harden latent upscale GPU cleanup 2026-09-04 10:05:24 +00:00
chris.dumas cbabcf8208 Offload H3 before latent upscale 2026-09-04 09:49:34 +00:00
chris.dumas fbfbe4ef5a Extend H3 spatial fallback ladder 2026-09-04 09:22:35 +00:00
chris.dumas 5b52793fad Clamp H3 spatial overlaps to tile size 2026-09-04 09:05:29 +00:00
chris.dumas 7e45c81589 Reset overlap in H3 spatial retries 2026-09-04 08:48:20 +00:00
chris.dumas 027865b9ca Tighten H3 spatial fallback retries 2026-09-04 08:27:54 +00:00
chris.dumas 9f0c546681 Remove latent upscale CPU fallback 2026-09-04 08:13:27 +00:00
chris.dumas 30ae81b86b Jump latent upscale fallback to spatial split 2026-09-04 08:00:06 +00:00
chris.dumas 179fa0778e Add CPU fallback for latent upscale OOM 2026-09-04 07:33:10 +00:00
chris.dumas a34c9eb4ff Reduce latent upscale VRAM pressure 2026-09-04 07:21:38 +00:00
chris.dumas 782a7d658b Fix temporal chunking to use H3 token grid 2026-09-04 07:06:08 +00:00
chris.dumas 04a61af874 Add temporal OOM backoff for latent upscale 2026-09-04 06:54:35 +00:00
chris.dumas a0d80bcc47 Add temporal chunking to latent upscale 2026-09-04 06:41:03 +00:00
chris.dumas fbb5f799cd Unload latent upscale model on OOM 2026-09-03 20:30:58 +00:00
chris.dumas 9dc3c405a6 Clamp latent upscale fallback tile minimum 2026-09-03 20:15:58 +00:00
chris.dumas 21ae4d62e0 Keep latent upscale shrink steps 32-aligned 2026-09-03 19:59:50 +00:00
chris.dumas 836a6eba33 Back off latent upscale tile size on OOM 2026-09-03 19:43:15 +00:00
chris.dumas 3b63d33ec7 Tile latent upscale model inference 2026-09-03 19:01:13 +00:00
chris.dumas c62921c3e8 Stop retrying latent upscale OOMs as sampling 2026-09-03 18:46:56 +00:00
chris.dumas 3ab6342ce5 Handle legacy latent upscale payloads 2026-09-03 18:33:01 +00:00
chris.dumas 51e03a39b7 Reduce latent upscale branch memory 2026-09-03 18:08:44 +00:00
chris.dumas f7b94ccaef Free first-pass latent before refinement 2026-09-03 16:34:12 +00:00
chris.dumas f6120a8500 Adopt full MMH3 spatial split controls 2026-09-03 16:15:43 +00:00
chris.dumas 0e119646ab Add remaining spatial split settings 2026-09-03 15:47:59 +00:00
chris.dumas c89570eae9 Expand latent upscale spatial stitch controls 2026-09-03 15:35:39 +00:00
chris.dumas 36d9f4369c Add spatial batching to latent upscale 2026-09-03 15:12:42 +00:00
chris.dumas 2cb3c694f0 Fix latent upscale summary scope leak 2026-09-03 14:37:24 +00:00
chris.dumas 5c12cd18a3 Expose latent upscale sampler controls 2026-09-03 13:05:32 +00:00
chris.dumas c1d937e0e2 Add H3 latent upscale refinement stage 2026-09-03 12:53:57 +00:00
chris.dumas 306816534b Bump package version to 0.1.1 2026-09-03 12:18:26 +00:00
chris.dumas e098e44bf1 Simplify H3 beat timing and cleanup 2026-09-03 08:56:43 +00:00
chris.dumas 769257513b Harden H3 detail-pass cleanup 2026-09-03 07:18:13 +00:00
chris.dumas ab6ba86d76 Fix H3 shot mode runtime error 2026-09-02 15:20:07 +00:00
chris.dumas ecd8ca6336 Align H3 prompt refs with beat numbering 2026-09-02 15:06:41 +00:00
chris.dumas 76b88b0c59 Clean up per-beat H3 script output 2026-09-02 14:52:58 +00:00
chris.dumas 62fbbdd98e Use socket picture labels in ref summaries 2026-09-02 14:44:54 +00:00
chris.dumas 85e15c910a Fix H3 section control interactions 2026-09-02 14:39:10 +00:00
chris.dumas 30400038c2 Add collapsible H3 long video sections 2026-09-02 13:25:54 +00:00
chris.dumas c8ddedbd57 Remove picture id from reference nodes 2026-09-02 13:20:38 +00:00
chris.dumas 6684c5f2e0 Remove legacy H3 ref image aliases 2026-09-02 13:06:25 +00:00
chris.dumas 08630964d5 Keep multiline beat prompts intact 2026-09-02 13:00:25 +00:00
chris.dumas 271e7de300 Fix tag-driven H3 ref routing 2026-09-02 12:55:51 +00:00
chris.dumas 130b268d1e Fix named reference lookup for long videos 2026-08-31 09:40:51 +00:00
chris.dumas a2dabaab7e Revert "Revert long videos ref routing to release"
This reverts commit 00985b73b3.
2026-08-30 21:37:15 +00:00
chris.dumas b7c3bba199 Revert "Restore missing named refs helper"
This reverts commit dfead66b9e.
2026-08-30 21:37:06 +00:00
chris.dumas 35ec12159e Revert "Retry long videos decode with tiling fallback"
This reverts commit 6a7bec5d03.
2026-08-30 21:36:58 +00:00
chris.dumas 58b1c77c19 Revert "Restore long videos release snapshot"
This reverts commit 4a0f5cfcd4.
2026-08-30 21:36:50 +00:00
chris.dumas 4a0f5cfcd4 Restore long videos release snapshot 2026-08-30 21:06:22 +00:00
chris.dumas 6a7bec5d03 Retry long videos decode with tiling fallback 2026-08-30 20:28:47 +00:00
chris.dumas dfead66b9e Restore missing named refs helper 2026-08-30 13:23:13 +00:00
chris.dumas 00985b73b3 Revert long videos ref routing to release 2026-08-30 10:07:45 +00:00
chris.dumas ffae1d87a5 Restore character ref regression tests 2026-08-29 12:20:38 +00:00
chris.dumas 74aca203ab Restore release-era character ref routing 2026-08-29 12:18:38 +00:00
chris.dumas e08281c12b Prioritize character refs over location refs 2026-08-29 11:36:53 +00:00
chris.dumas faaeb374e0 Document named ref routing guardrail 2026-08-29 11:02:21 +00:00
chris.dumas 0bac83a689 Fix named character ref routing 2026-08-29 10:51:01 +00:00
chris.dumas 08365c7df5 Add long videos timing breakdown 2026-08-29 00:22:48 +00:00
chris.dumas 9cbab72e86 Optimize long videos ref bookkeeping 2026-08-28 22:09:12 +00:00
chris.dumas e29d01ad24 Tighten tagged ref routing and anchor presets 2026-08-28 15:45:22 +00:00
chris.dumas ddd7dbb5af Harden and streamline H3 reference matching 2026-08-28 13:49:01 +00:00
chris.dumas 1ad68ee9e4 Stop ref wardrobe from fighting live character memory 2026-08-28 13:16:05 +00:00
chris.dumas e64ad0fae4 Expand H3 reference-node documentation 2026-08-28 12:48:33 +00:00
chris.dumas deb6f1d033 Clarify H3 long videos state behavior 2026-08-28 12:36:46 +00:00
chris.dumas 72d4d74dd3 Clarify H3 long videos guide behavior 2026-08-28 12:27:12 +00:00
chris.dumas c42cf436c5 Document H3 long videos node 2026-08-28 11:43:11 +00:00
chris.dumas eeca789c27 Tidy H3 long videos input layout 2026-08-28 11:36:39 +00:00
18 changed files with 482 additions and 12492 deletions
+27 -229
View File
@@ -1,247 +1,45 @@
# DumasNodes
`DumasNodes` is a ComfyUI custom-node pack for generic utility workflows under the Dumas brand.
Generic ComfyUI utility nodes under the Dumas brand. The repository contains
image, JSON and video utilities and intentionally has no model-specific video
sampler dependency.
## Included Nodes
## Video nodes
- `Dumas Image Compare`
- Inputs: optional `image1`, optional `image2`
- Outputs: `new image`
- Saves preview images for the built-in compare UI and passes through the second image when present, otherwise the first.
- Bundles a `js/` frontend extension so the compare viewer renders inside both classic ComfyUI and Nodes 2.0.
### Dumas Standalone Video
- `Save Image Dumas`
- Inputs: `images`, `folder`, `pattern`, `format`, `quality`, `embed_workflow`, `save_on_run`, optional `name`, optional `name_2`
- Output: none
- Saves images to any folder, not just ComfyUI's output directory.
- Supports filename tokens including `%input%`, `%input2%`, `%date:yyyy-MM-dd%`, `%counter%`, `%width%`, `%height%`, and `%batch_num%`.
Encodes an IMAGE batch and optional AUDIO into two files:
- `Load Images from Folder Dumas`
- Inputs: configured on-node via folder picker and image gallery
- Outputs: `image`, `mask`, `width`, `height`, `filename`, `index`, `total`
- Loads one or many images from any folder on disk as ComfyUI list outputs.
- Supports manual picks, `Select all`, `First N`, and `Select random` so each run can choose one random image from the visible folder tree.
- `full_clip`: every generated frame, including any continuation overlap
- `complete_clip`: the same clip with `overlap_frames` removed before encoding
- `Dumas H3 Plan Attach Scene Images`
- Inputs: `plan`, `scene_index`, optional `image1`..`image9`
- Outputs: `plan`, `connected_images`
- Attaches up to nine optional image sockets to one MiniMax H3 plan scene while keeping the plan JSON-serializable for the upstream archive system.
- Chain one node per scene that needs its own nine-image bundle.
The full clip is the source for the next sequential generation. The complete
clip is the assembly-ready segment. Removing the overlap before encoding means
the final join does not need to re-encode an already assembled film.
- `Dumas H3 Plan Extract Scene Images`
- Inputs: `plan`, `scene_index`
- Outputs: `plan`, `image1`..`image9`, `connected_images`
- Reads back the nine optional images for a selected MiniMax H3 plan scene, for example by connecting the current `clip_index`.
### Dumas Join Video Clips (No Re-encode)
- `Dumas H3 Long Videos (FL2VA + REF2VA)`
- Inputs: H3 model stack, prompt socket, optional `first_frame`, optional `ref_1`..`ref_9`, plus the upstream long-video control surface for pacing, continuity, audio, overlays, and guards
- Outputs: `images`, `audio`, `info`, `script`, `frames_per_shot`, `total_frames`, `shots`, `video_seconds`, `fps`, `fps_int`, `latent`, `soundscape`
- First-pass Dumas port of the `MiniMax-H3-Longvideos` sampler, brought in as a local starting point for long-form H3 chaining work.
- Keeps the upstream split-beats / handoff / ref-routing behavior close to source so future Dumas-specific improvements can be compared against a known baseline.
- Only the canonical `DumasH3LongVideos` node key is exposed now; the older FL2VA/REF2VA alias entries are no longer duplicated in the Add Node menu.
- Prompt `<Picture N>` tags now map to the actual ref socket numbers you wire, even with gaps such as only `ref_2` and `ref_7` connected.
- Character refs now contribute appearance and wardrobe context from the same structured object, while location refs contribute environment context from theirs.
- The default ref2v bias is now stronger: `ref_mode` defaults to `auto ref2v` so untagged prompts condition every shot instead of only shot 1, and `ref_noise_aug` defaults to `0.95` rather than the upstream-literal `0.999`.
- Per-shot directives now support `continuity:`, `ref_mode:`, `ref_noise_aug:`, `anchor_add:`, `soundscape:`, and `music:` in addition to the existing timing and wardrobe directives.
Accepts up to six completed clip paths and concatenates them with FFmpeg stream
copy (`-c copy`). It validates codec, dimensions, frame rate, pixel format and
audio compatibility before joining. The input clips must already have their
continuation overlap removed.
- `Dumas H3 Beat Prompt`
- Inputs: authored through the custom front-end beat editor
- Output: `prompt`
- Builds one H3 prompt block per beat, with quick controls for per-shot timing, continuity, ref behavior, anchor additions, soundscape, and music while staying compatible with direct text editing.
## Other nodes
- `Dumas H3 Shot Length`
- Inputs: `shot_seconds`, `fps`, optional `cap_to_h3_max`
- Outputs: `seconds`, `frames`, `info`
- Emits one H3-safe shot length as both seconds and a grid-aligned frame count for wiring into the long-video sampler and preview helpers.
- `Dumas H3 Model Inspector`
- Input: `model`
- Outputs: `format`, `report`
- Reports the detected H3 base precision / quant format and the relevant compute-capability hints for the current card.
- `Dumas Character Reference`
- Inputs: `image`, `picture_id`, `character_id`, `name`, `alias`, `gender`, `age`, `nationality`, `occupation`, `height_feet`, `height_inches`, `accent`, `description`, `general`, `wardrobe`
- Output: `reference`
- Builds one structured `REFERENCE` object carrying the conditioning image, identity description, wardrobe, general notes, and simple facts together.
- `Dumas Location Reference`
- Inputs: `image`, `picture_id`, `location_id`, `name`, `alias`, `description`, `general`
- Output: `reference`
- Builds one structured `REFERENCE` object for a location/environment so H3 can use the same socket type for both character and scenic refs.
- `Dumas Anchor Style`
- Inputs: `anchor_style`, `style_description`
- Output: `anchor`
- Offers a large preset dropdown of anchor-style titles such as cinematic action movie, comedy, found footage, 90s sitcom, mobile/cell phone captured, news broadcast, mockumentary, heist thriller, cyberpunk neon, nature documentary, courtroom drama, and more.
- The preset wording is tuned for H3-safe persistent anchors: camera language, lighting, texture, production treatment, and tone, without naming characters or describing one-off actions.
- Selecting a preset fills the editable description field, and the edited multiline description is the `STRING` value passed downstream into H3 anchor sockets such as `anchor_override`.
- `Dumas JSON String to Object`
- Input: `json_string`
- Output: parsed `JSON`
- Use it to turn raw JSON text into a structured object.
- `Dumas JSON Object to String`
- Inputs: `json_object`, `pretty`, `sort_keys`
- Output: serialized `STRING`
- Use it to compact or pretty-print JSON for prompts, logs, or file output.
- `Dumas Strip Iteration Suffix`
- Input: `filename`
- Output: cleaned `STRING`
- Keeps only the part before the first underscore, for example `asset_build_003.png -> asset.png` and `char123_pose.png -> char123.png`.
- `Dumas Slugify String`
- Input: `text`
- Output: slug `STRING`
- Converts text into a lowercase URL/file-safe slug, for example `Crème brûlée 2026 -> creme-brulee-2026`.
- `Dumas JSON Get Value`
- Inputs: `json_object`, `path`
- Output: `JSON`
- Reads a nested value using dot paths like `user.profile.name` or `items.0.id`.
- `Dumas JSON Set Value`
- Inputs: `json_object`, `path`, `value_json`
- Output: updated `JSON`
- Writes a parsed JSON value into a nested path without mutating the original object.
- `Dumas JSON Has Key`
- Inputs: `json_object`, `path`
- Output: `BOOLEAN`
- Checks whether a nested path exists.
- `Dumas JSON Remove Key`
- Inputs: `json_object`, `path`
- Output: updated `JSON`
- Removes a nested key or array item by path.
- `Dumas JSON Pick Fields`
- Inputs: `json_object`, `paths`
- Output: filtered `JSON`
- Builds a new object from newline-separated paths that exist in the input.
- `Dumas JSON Merge Objects`
- Inputs: `base_object`, `overlay_object`
- Output: merged `JSON`
- Deep-merges dictionaries so overlay values replace or extend the base object.
- `Dumas JSON Keys`
- Input: `json_object`
- Outputs: `keys` as JSON array, `count` as integer
- Lists the top-level keys of an object and reports how many there are.
- `Dumas JSON Array Length`
- Input: `json_array`
- Output: `INT`
- Returns the length of a JSON array.
- `Dumas JSON Array Append`
- Inputs: `json_array`, `value_json`
- Output: updated `JSON`
- Appends a parsed JSON value to the end of an array.
- `Dumas JSON Array Slice`
- Inputs: `json_array`, `start`, `end`, `step`
- Output: sliced `JSON`
- Returns an array slice. `end=0` means "slice to the end".
- `Dumas JSON Array Iterator`
- Inputs: `json_input`, `index`, `mode`
- Outputs: `item`, `current_index`, `total_items`
- Returns the current array item and position, with `mode` set to `fixed`, `incr`, or `decr`.
- `Dumas JSON Object Iterator`
- Inputs: `json_input`, `index`, `mode`
- Outputs: `key`, `value`, `current_index`, `total_items`
- Returns the current object entry in insertion order, with `mode` set to `fixed`, `incr`, or `decr`.
- `Dumas JSON Flatten`
- Input: `json_input`
- Output: flat `JSON`
- Flattens nested objects and arrays into dot-path keys.
- `Dumas JSON Unflatten`
- Input: `flat_json_object`
- Output: nested `JSON`
- Rebuilds nested JSON from a flat dot-path object.
All nodes live in the `Dumas/JSON` category.
- Dumas Image Compare
- Save Image Dumas
- Load Images from Folder Dumas
- Dumas JSON helpers
## Installation
1. Change into your ComfyUI custom nodes directory:
Copy or clone this repository into `ComfyUI/custom_nodes/DumasNodes` and restart
ComfyUI. FFmpeg and FFprobe must be available on `PATH` for the video nodes.
```bash
cd /path/to/ComfyUI/custom_nodes
```
## Development
2. Clone this repository:
Run the fast unit tests from the repository root:
```bash
git clone https://git.dumas.ddns.net/chris.dumas/DumasNodes.git
```
3. Restart ComfyUI.
## Usage
Use dot paths for nested access:
```text
user.profile.name
items.0.id
settings.render.width
```bash
python -m unittest discover -s tests -p 'test_*.py'
```
`Dumas JSON Set Value` expects `value_json` to be valid JSON, so strings should be quoted:
```json
"Dumas"
```
```json
{"enabled": true, "retries": 3}
```
`Dumas JSON Pick Fields` expects one path per line:
```text
user.name
meta.active
items.0.id
```
`Dumas JSON Array Slice` treats `end=0` as "use the rest of the array".
`Dumas JSON Array Iterator` clamps to valid bounds:
```text
fixed -> use index as-is
incr -> use index + 1
decr -> use index - 1
```
`Dumas JSON Object Iterator` uses the same index rules and iterates object entries in their existing key order.
`Dumas JSON Flatten` and `Dumas JSON Unflatten` use the same dot-path format as the other path-based nodes.
`Dumas Image Compare` accepts one or two images. The `new image` socket forwards `image2` when connected so you can keep the "after" image moving through the workflow, and falls back to `image1` if only one input is present.
`Save Image Dumas` leaves `folder` empty to use ComfyUI's output directory. `name` feeds `%input%` and `name_2` feeds `%input2%`, so a pattern like `project/%input%_%input2%_%counter%` can combine two upstream strings into the saved filename.
`Dumas H3 Plan Attach Scene Images` and `Dumas H3 Plan Extract Scene Images` are a companion pair for `ComfyUI-MiniMaxH3-Contex-Loop` and the local `ref2v` lane. The upstream H3 plan node cannot dynamically grow nine new image sockets for every JSON-defined scene, so Dumas stores scene image bindings beside the plan using a lightweight token and an in-memory registry. That keeps `plan.json` archiving intact while still letting you wire up nine IMAGE sockets per scene through chained helper nodes.
`Dumas Character Reference` and `Dumas Location Reference` live in `Dumas/MiniMax`. Both output a structured `REFERENCE` object that carries the image plus its semantic payload. `Dumas H3 Long Videos` accepts those `REFERENCE` sockets directly on `ref_1`..`ref_9`, resolves `<Picture N>` against the wired slot positions, and can also pull character wardrobe context from the structured ref data when `character_memory` is left blank.
`Dumas Strip Iteration Suffix` keeps the part before the first underscore and drops the rest. Names like `char123_pose_final.png` become `char123.png`, while names with no underscore such as `char123.png` are left untouched.
`Dumas Slugify String` lowercases text, strips accents, replaces non-alphanumeric runs with `-`, and trims leading or trailing dashes.
## Roadmap
This repo is intended to grow into a broader set of Dumas-branded generic utility nodes, including JSON helpers and adjacent data-manipulation tools.
## License
MIT.
-386
View File
@@ -1,386 +0,0 @@
# Dumas Reference System Spec
## Goal
Replace the current image-only / text-fragment character-reference flow with one
structured reference system that works for both:
- characters
- locations / environments
Compatibility with old graphs is **not** a goal. This is a clean redesign for a
single-user workflow.
## Core Direction
The system should stop treating a reference as "just an image".
A reference should be one structured object that carries:
- the image used for model conditioning
- the semantic identity of the reference
- the descriptive text tied to that reference
- the routing metadata needed by H3 beat / prompt logic
This object type is called `REFERENCE`.
## Main Outcomes
After this redesign:
- H3 ref sockets accept `REFERENCE`, not raw `IMAGE`
- `<Picture N>` resolves to the bound `REFERENCE` object
- character references can provide identity, description, and wardrobe from one source
- location references can provide environment description from one source
- beat prompt logic no longer has to guess where a name or picture tag should pull
its descriptive payload from
## Reference Kinds
`REFERENCE` is one base type with a `kind` field.
Initial supported kinds:
- `character`
- `location`
Future kinds could be added later if useful, but they are out of scope for the
first pass.
## Reference Object Schema
The `REFERENCE` object should be a plain JSON-serializable structure plus an
attached Comfy image payload where needed by downstream nodes.
Conceptual schema:
```json
{
"kind": "character",
"id": "francine",
"name": "Francine",
"aliases": [],
"picture_id": 1,
"picture_label": "<Picture 1>",
"image": "<IMAGE>",
"summary": "Same character shown in <Picture 1>.",
"description": "Face, hair, proportions, persistent visual identity.",
"wardrobe": "Clothing / styling / persistent look notes.",
"general": "Freeform notes.",
"facts": {
"gender": "",
"age": "",
"nationality": "",
"occupation": "",
"height_feet": "",
"height_inches": "",
"accent": ""
}
}
```
For locations:
```json
{
"kind": "location",
"id": "coffee-shop-01",
"name": "Coffee Shop",
"aliases": [],
"picture_id": 2,
"picture_label": "<Picture 2>",
"image": "<IMAGE>",
"summary": "Environment shown in <Picture 2>.",
"description": "Persistent environment / layout / atmosphere description.",
"wardrobe": "",
"general": "Freeform notes.",
"facts": {}
}
```
## Field Meaning
### Shared fields
- `kind`
- Required.
- `character` or `location`.
- `id`
- Required.
- Stable, slug-like internal identifier.
- Used for matching and future persistence.
- `name`
- Optional but strongly recommended.
- Human-readable label.
- `aliases`
- Optional list of alternate match names.
- `picture_id`
- Optional integer representing the intended `<Picture N>` identity.
- This is authoring metadata, not the final socket position.
- `picture_label`
- Derived convenience text like `<Picture 1>`.
- `image`
- Required.
- The actual Comfy `IMAGE` payload used for reference conditioning.
- `summary`
- Short purpose statement for prompt assembly and debugging.
- `description`
- Primary descriptive payload tied to the reference.
- For characters this is the physical identity description.
- For locations this is the environment/layout/atmosphere description.
- `general`
- Optional freeform notes.
- `facts`
- Optional structured detail map.
### Character-only field
- `wardrobe`
- Optional but expected for character references.
- Persistent clothing / styling / accessories / visual state notes.
### Location usage note
For `kind = "location"`, `wardrobe` should be empty.
## Producer Nodes
### 1. Character helper replacement
Current `Dumas Character Helper` should be redesigned into a character reference
builder.
Recommended name:
- `Dumas Character Reference`
Inputs:
- `image`
- `picture_id`
- `character_id`
- `name`
- `alias`
- `gender`
- `age`
- `nationality`
- `occupation`
- `height_feet`
- `height_inches`
- `accent`
- `description`
- `wardrobe`
- `general`
Outputs:
- `reference` (`REFERENCE`)
Notes:
- This node should stop emitting the current mixed output pattern.
- It should build one clean `REFERENCE` object with `kind = "character"`.
### 2. Location / environment helper
Add a new builder node.
Recommended name:
- `Dumas Location Reference`
Inputs:
- `image`
- `picture_id`
- `location_id`
- `name`
- `alias`
- `description`
- `general`
Outputs:
- `reference` (`REFERENCE`)
Notes:
- This node builds one `REFERENCE` object with `kind = "location"`.
- It should not attempt to mimic character-specific fields.
## Consumer Changes
## H3 Long Videos
Current numbered sockets:
- `ref_image_1` .. `ref_image_9`
should become:
- `ref_1` .. `ref_9`
Type:
- `REFERENCE`
Each socket should provide access to:
- the underlying `image`
- the structured metadata
### Internal handling
The H3 node should internally derive two parallel lanes:
1. reference images for model conditioning
2. reference definitions for semantic beat / prompt resolution
It must no longer depend on detached text sources to know what a reference means.
## Beat / prompt resolution rules
### Resolution by `<Picture N>`
If a beat contains `<Picture N>`:
- map `N` to the bound socket position in that shot
- resolve the bound `REFERENCE`
- use the resolved object's data when generating the shot-level descriptive payload
### Resolution by character name
For `kind = "character"`:
- match against `name`
- match against `aliases`
- optionally match `id`
When a character is matched:
- pull identity text from `description`
- pull clothing / styling from `wardrobe`
- pull additional context from `general` and `facts` if needed
### Resolution by location
For `kind = "location"`:
- `<Picture N>` should resolve directly
- later name-based location matching can be added if useful, but the first pass
does not need aggressive free-text environment matching
When a location is matched:
- pull environment text from `description`
- optionally use `general`
## Prompt Assembly Expectations
Character refs should contribute:
- who the subject is
- what persistent visual identity should be preserved
- what clothing / styling should persist
Location refs should contribute:
- where the scene is
- what environment layout / mood / persistent scenic identity should be preserved
The node should keep these conceptually separate.
Character reference text should not be mistaken for environment text.
Location reference text should not be mistaken for wardrobe or identity text.
## Multi-reference Behavior
The system must support multiple references bound at once.
Typical cases:
- one character + one location
- multiple character references
- one character sheet reused across many beats
The H3 node should preserve current numbered socket behavior for explicit routing,
but with `REFERENCE` objects replacing plain images.
## Plan / scene integration
The current H3 plan scene image system should evolve in parallel.
Where plan scenes currently carry image bundles, they should eventually carry
reference bundles instead.
This is not required for the first code pass if it would enlarge the change too
much, but the implementation should avoid boxing us into image-only assumptions.
## Non-goals
Not required for first pass:
- backward compatibility with old image-only graphs
- migration helpers
- automatic graph conversion
- advanced location name matching
- persistent storage outside the graph object itself
## Recommended Implementation Order
1. Define the `REFERENCE` type contract in code.
2. Replace `Dumas Character Helper` with a character-reference builder node.
3. Add `Dumas Location Reference`.
4. Update H3 long videos sockets from `IMAGE` to `REFERENCE`.
5. Update internal ref collection logic to extract both image and metadata.
6. Update beat / prompt resolution to use `REFERENCE` objects.
7. Update tests.
8. Update README and workflow docs.
## Testing Requirements
Add tests for:
- character reference object construction
- location reference object construction
- `<Picture N>` resolving to the correct `REFERENCE`
- name-based character lookup resolving to the correct `REFERENCE`
- wardrobe text being pulled only from character refs
- location description being pulled only from location refs
- mixed character + location ref usage in one prompt
- sparse numbered sockets still resolving correctly
## Open Design Choices
These should be decided during implementation, but the default recommendation is:
- one `REFERENCE` output per helper node
- numbered H3 sockets remain explicit
- no separate cast object in first pass
- no compatibility fallback path
## Summary
This redesign turns references into first-class structured inputs.
The key rule is:
> A reference socket should carry both the image and the meaning of that image.
That is the change that removes the current ambiguity between:
- image conditioning
- character identity
- wardrobe data
- location / environment description
+5 -23
View File
@@ -10,38 +10,20 @@ from .dumas_json_nodes import (
NODE_CLASS_MAPPINGS as JSON_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as JSON_NODE_DISPLAY_NAME_MAPPINGS,
)
from .dumas_h3_longvideos import (
NODE_CLASS_MAPPINGS as H3_LONGVIDEO_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as H3_LONGVIDEO_NODE_DISPLAY_NAME_MAPPINGS,
)
from .dumas_h3_shot_length import (
NODE_CLASS_MAPPINGS as H3_SHOT_LENGTH_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as H3_SHOT_LENGTH_NODE_DISPLAY_NAME_MAPPINGS,
)
from .dumas_h3_inspector import (
NODE_CLASS_MAPPINGS as H3_INSPECTOR_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as H3_INSPECTOR_NODE_DISPLAY_NAME_MAPPINGS,
)
from .dumas_h3_beat_prompt import (
NODE_CLASS_MAPPINGS as H3_BEAT_PROMPT_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as H3_BEAT_PROMPT_NODE_DISPLAY_NAME_MAPPINGS,
from .dumas_video_nodes import (
NODE_CLASS_MAPPINGS as VIDEO_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as VIDEO_NODE_DISPLAY_NAME_MAPPINGS,
)
NODE_CLASS_MAPPINGS = {}
NODE_CLASS_MAPPINGS.update(JSON_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(IMAGE_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(H3_LONGVIDEO_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(H3_SHOT_LENGTH_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(H3_INSPECTOR_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(H3_BEAT_PROMPT_NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(VIDEO_NODE_CLASS_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS.update(JSON_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(IMAGE_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(H3_LONGVIDEO_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(H3_SHOT_LENGTH_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(H3_INSPECTOR_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(H3_BEAT_PROMPT_NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(VIDEO_NODE_DISPLAY_NAME_MAPPINGS)
WEB_DIRECTORY = "./js"
-86
View File
@@ -1,86 +0,0 @@
import json
_DEFAULT_BEAT = "Describe this beat."
_DEFAULT_STATE = {"beats": [{"text": _DEFAULT_BEAT}]}
def _clone_default_state():
return {"beats": [{"text": _DEFAULT_BEAT}]}
def _parse_beat_prompt_state(value):
if isinstance(value, dict):
raw = value
else:
text = str(value or "").strip()
if not text:
return _clone_default_state()
try:
raw = json.loads(text)
except Exception:
return _clone_default_state()
beats = []
for item in list(raw.get("beats") or []):
if isinstance(item, dict):
text = str(item.get("text") or "")
else:
text = str(item or "")
beats.append({"text": text})
if not beats:
return _clone_default_state()
return {"beats": beats}
def _assemble_beat_prompt(state):
parsed = _parse_beat_prompt_state(state)
chunks = []
for beat in parsed["beats"]:
text = str(beat.get("text") or "").strip()
if text:
chunks.append(text)
return "\n\n".join(chunks)
class DumasH3BeatPromptNode:
DESCRIPTION = (
"Build a MiniMax H3 prompt from one textbox per beat, with a front-end beat "
"editor that can append directive examples and expose per-shot controls for "
"timing, continuity, ref behavior, anchor additions, soundscape, and music."
)
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("prompt",)
FUNCTION = "build_prompt"
CATEGORY = "Dumas/MiniMax"
@classmethod
def INPUT_TYPES(cls):
return {
"required": {},
"hidden": {
"H3BeatPromptState": ("STRING", {"default": json.dumps(_DEFAULT_STATE)}),
},
}
def build_prompt(self, H3BeatPromptState=""):
return (_assemble_beat_prompt(H3BeatPromptState),)
NODE_CLASS_MAPPINGS = {
"DumasH3BeatPrompt": DumasH3BeatPromptNode,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"DumasH3BeatPrompt": "Dumas H3 Beat Prompt",
}
__all__ = [
"DumasH3BeatPromptNode",
"NODE_CLASS_MAPPINGS",
"NODE_DISPLAY_NAME_MAPPINGS",
"_assemble_beat_prompt",
"_parse_beat_prompt_state",
]
-177
View File
@@ -1,177 +0,0 @@
"""
H3 Model Inspector (detect the base precision / quant format)
==============================================================
Reads the loaded MODEL and reports which precision/quant format the H3 DiT is
stored in: BF16, FP8 (e4m3 / e5m2), INT8 (+ convrot), NVFP4, MXFP8,
ConvRot-W4A4, W4A8, or a mix. Report-only — a manual hint you read and act on.
WHY IT'S FUTURE-PROOF (incl. MXFP8 "once one comes out")
--------------------------------------------------------
It doesn't sniff dtypes and guess. ComfyUI tags every quantized layer at load
with module.quant_format, using fixed strings it already recognizes:
nvfp4, mxfp8, float8_e4m3fn, float8_e5m2, int8_tensorwise, convrot_w4a4,
asym_w4a8_int8 (see comfy/ops.py).
This node reads that tag. MXFP8 is already a recognized format in ComfyUI
(comfy/ops.py + comfy/float.py + model_management.supports_mxfp8_compute), so
the day someone ships an MXFP8 H3 checkpoint, this node labels it correctly
with no change. Any brand-new tag lands under "other: <tag>" instead of
crashing, so it degrades gracefully.
It also reports whether YOUR card can run NVFP4 / MXFP8 natively
(model_management.supports_nvfp4_compute / supports_mxfp8_compute).
NOT detected: pruned vs full (that's an architecture axis — factorized AdaLN —
not a quant format). Reported as a caveat, not guessed.
INSTALL: drop into ComfyUI/custom_nodes/, restart.
Node: MiniMax-H3 -> Model Inspector.
"""
# ---- pure helpers (no torch; unit-testable) -------------------------------
_FRIENDLY = {
"float8_e4m3fn": "FP8 (e4m3)",
"float8_e5m2": "FP8 (e5m2)",
"mxfp8": "MXFP8",
"nvfp4": "NVFP4",
"int8_tensorwise": "INT8",
"int8_tensorwise+convrot": "INT8 convrot",
"convrot_w4a4": "ConvRot W4A4 (int4)",
"asym_w4a8_int8": "W4A8 (int4/int8)",
"bf16": "BF16",
"fp16": "FP16",
}
# implication note per format, tied to a Blackwell 16GB context
_IMPLICATION = {
"NVFP4": "native on Blackwell (sm_120); half the size of INT8.",
"MXFP8": "needs Blackwell + torch >= 2.10 for native compute.",
"FP8 (e4m3)": "fp8 storage; runs on Ada/Blackwell.",
"FP8 (e5m2)": "fp8 storage; runs on Ada/Blackwell.",
"INT8": "int8 storage.",
"INT8 convrot": "int8+ConvRot — needs working sm_120 kernels (absent on some 50-series setups).",
"ConvRot W4A4 (int4)": "4-bit ConvRot; requires the matching custom nodes/branch.",
"W4A8 (int4/int8)": "4-bit weight / 8-bit activation.",
"BF16": "full precision; largest footprint, cleanest LoRA apply.",
"FP16": "half precision.",
}
def friendly(fmt):
return _FRIENDLY.get(fmt, f"other: {fmt}")
def summarize(counts):
"""counts: {raw_format: n}. Returns (label, per_format_summary_lines).
Label = the dominant NON-bf16/fp16 quant format if any (the main blocks),
else the dominant plain dtype."""
quant = {k: v for k, v in counts.items() if k not in ("bf16", "fp16")}
lines = []
for raw, n in sorted(counts.items(), key=lambda kv: -kv[1]):
lines.append(f" {friendly(raw)}: {n} layer(s)")
if quant:
top = max(quant.items(), key=lambda kv: kv[1])[0]
label = friendly(top)
elif counts:
top = max(counts.items(), key=lambda kv: kv[1])[0]
label = friendly(top)
else:
label = "unknown"
return label, lines
# ---- ComfyUI node ---------------------------------------------------------
def _detect(model):
"""Walk the DiT modules, tally quant_format tags (and dtype for the rest).
Returns (label, counts, report_lines). Imports torch/mm lazily so the pure
helpers above stay importable without a ComfyUI runtime."""
import torch
import comfy.model_management as mm
# locate the diffusion model inside the ModelPatcher
dm = getattr(getattr(model, "model", None), "diffusion_model", None)
if dm is None:
dm = getattr(model, "model", None) or model
def dtype_label(dt):
return {
torch.bfloat16: "bf16", torch.float16: "fp16",
torch.float8_e4m3fn: "float8_e4m3fn", torch.float8_e5m2: "float8_e5m2",
torch.int8: "int8_tensorwise",
}.get(dt, str(dt).replace("torch.", ""))
counts = {}
if hasattr(dm, "modules"):
for m in dm.modules():
fmt = getattr(m, "quant_format", None)
if fmt is not None:
# distinguish int8 convrot via the packed weight's params
if fmt == "int8_tensorwise":
params = getattr(getattr(m, "weight", None), "_params", None)
if getattr(params, "convrot", False):
fmt = "int8_tensorwise+convrot"
counts[fmt] = counts.get(fmt, 0) + 1
continue
w = getattr(m, "weight", None)
if w is not None and hasattr(w, "dtype"):
counts[dtype_label(w.dtype)] = counts.get(dtype_label(w.dtype), 0) + 1
label, lines = summarize(counts)
# hardware capability for the relevant 4-bit/8-bit formats
try:
nv = mm.supports_nvfp4_compute()
except Exception:
nv = None
try:
mx = mm.supports_mxfp8_compute()
except Exception:
mx = None
report = [f"Detected base precision: {label}"]
report += lines
impl = _IMPLICATION.get(label)
if impl:
report.append(f" -> {impl}")
report.append(f" card supports NVFP4 compute: {nv}; MXFP8 compute: {mx}")
if label == "MXFP8" and mx is False:
report.append(" WARNING: MXFP8 file but this card/torch can't run it natively.")
if label == "NVFP4" and nv is False:
report.append(" WARNING: NVFP4 file but this card can't run it natively.")
report.append(" (pruned-vs-full is a separate architecture axis; not detected here.)")
return label, counts, "\n".join(report)
class H3ModelInspector:
CATEGORY = "Dumas/MiniMax"
FUNCTION = "inspect"
RETURN_TYPES = ("STRING", "STRING")
RETURN_NAMES = ("format", "report")
OUTPUT_NODE = True
@classmethod
def INPUT_TYPES(cls):
return {"required": {"model": ("MODEL",)}}
def inspect(self, model):
label, _counts, report = _detect(model)
return (label, report)
NODE_CLASS_MAPPINGS = {"DumasH3ModelInspector": H3ModelInspector}
NODE_DISPLAY_NAME_MAPPINGS = {"DumasH3ModelInspector": "Dumas H3 Model Inspector"}
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
if __name__ == "__main__":
# exercise the pure aggregation logic with mocked layer tallies
cases = {
"NVFP4 file (200 main + bf16 rest)": {"nvfp4": 200, "bf16": 132},
"INT8 convrot": {"int8_tensorwise+convrot": 170, "bf16": 30},
"plain bf16": {"bf16": 340},
"FP8": {"float8_e4m3fn": 200, "bf16": 140},
"MXFP8 (future file)": {"mxfp8": 200, "bf16": 132},
"some unknown new tag": {"fp6_e3m2": 200, "bf16": 132},
}
for name, counts in cases.items():
label, lines = summarize(counts)
print(f"{name:38s} -> {label}")
File diff suppressed because it is too large Load Diff
-255
View File
@@ -1,255 +0,0 @@
"""
PIL text overlays for H3 Long Videos -- watermark and intro title.
Text is COMPOSITED onto the decoded frames, never asked of the model. H3 (like
every video diffusion model) renders text as plausible-looking letterforms that
drift, warp and re-spell themselves frame to frame; a watermark that changes
shape every frame is worse than none. Compositing gives pixel-identical text on
every frame at zero sampling cost, and keeps the words out of the prompt where
they would otherwise steal conditioning from the actual shot.
Both overlays are WHITE text drawn on a fully transparent RGBA layer, then
alpha-blended over the video -- so only the glyphs themselves land on the frame
and the picture shows through everywhere else.
Everything here is best-effort: any failure returns the frames untouched with a
note, because a cosmetic overlay must never lose a finished render.
"""
import torch
BLEND_CHUNK = 64 # frames blended per slice -- bounds peak RAM on long chains
# Auto-fit: text is wrapped, then shrunk in FIT_SHRINK steps until the block fits
# inside the margins. MIN_FONT_PX is the point below which the text would be
# unreadable anyway, so the loop stops there and lets PIL clip rather than spin.
MIN_FONT_PX = 8
FIT_SHRINK = 0.92
FIT_STEPS = 48
# Fonts to try when the requested one cannot be loaded. PIL resolves bare names
# against the system font directory, so "arial.ttf" works on Windows as-is.
FONT_FALLBACKS = ("arial.ttf", "segoeui.ttf", "DejaVuSans.ttf", "LiberationSans-Regular.ttf")
# Anchor -> (x, y) as a fraction of the free space: 0 = hard against the left/top
# margin, 1 = hard against the right/bottom, 0.5 = centered.
POSITIONS = {
"bottom-right": (1.0, 1.0),
"bottom-left": (0.0, 1.0),
"bottom-center": (0.5, 1.0),
"top-right": (1.0, 0.0),
"top-left": (0.0, 0.0),
"top-center": (0.5, 0.0),
"center": (0.5, 0.5),
"lower-third": (0.5, 0.72),
}
def _load_font(name, px):
"""A truetype font at px, falling back through the known-present faces and
finally to PIL's bitmap default (which ignores size -- ugly, but never fatal)."""
from PIL import ImageFont
px = max(8, int(px))
for cand in ([name] if name else []) + list(FONT_FALLBACKS):
try:
return ImageFont.truetype(cand, px)
except Exception:
continue
return ImageFont.load_default()
def _measure(draw, text, font, stroke_px, spacing):
"""(x0, y0, x1, y1) of a multi-line block, tolerant of older Pillow builds."""
try:
return draw.multiline_textbbox((0, 0), text, font=font, align="center",
stroke_width=stroke_px, spacing=spacing)
except TypeError: # older Pillow: no stroke/spacing kwargs
return draw.multiline_textbbox((0, 0), text, font=font, align="center")
def _wrap(draw, text, font, max_w, stroke_px, spacing):
"""Greedy word-wrap every hard line to max_w. A single word wider than the
frame cannot be broken -- the shrink loop in render_text_layer handles that."""
out = []
for hard in text.split("\n"):
words = hard.split()
if not words:
out.append("")
continue
cur = words[0]
for wd in words[1:]:
trial = cur + " " + wd
b = _measure(draw, trial, font, stroke_px, spacing)
if b[2] - b[0] <= max_w:
cur = trial
else:
out.append(cur)
cur = wd
out.append(cur)
return "\n".join(out)
def _fit(draw, text, font_name, px, max_w, max_h, stroke_px, line_spacing, wrap=True):
"""Largest size at or below px whose wrapped block fits (max_w, max_h).
Without this, a title is drawn at the requested size and whatever runs past the
frame is simply CLIPPED by PIL -- silently, with no error and no note. That is
the whole "overlays don't work at other resolutions" failure: the size is a
percentage, so the same text that fits 1344x768 overflows a 512-wide portrait
canvas and loses its outer characters."""
px = max(MIN_FONT_PX, int(px))
for _ in range(FIT_STEPS):
font = _load_font(font_name, px)
spacing = int(max(0.0, px * (line_spacing - 1.0)))
fitted = _wrap(draw, text, font, max_w, stroke_px, spacing) if wrap else text
box = _measure(draw, fitted, font, stroke_px, spacing)
if (box[2] - box[0] <= max_w and box[3] - box[1] <= max_h) or px <= MIN_FONT_PX:
return font, fitted, box, spacing, px
px = max(MIN_FONT_PX, int(px * FIT_SHRINK))
return font, fitted, box, spacing, px
def render_text_layer(width, height, text, font_px, position="bottom-right",
margin_pct=3.0, font_name="", stroke_px=0, line_spacing=1.15,
wrap=True):
"""White text on a transparent RGBA canvas the size of one frame.
The block is WRAPPED and SHRUNK until it fits inside the margins, so the same
settings render legibly on every supported preset -- portrait canvases and the
512 tier included -- instead of being clipped at the frame edge.
Returns (rgb, alpha, bbox): rgb [H,W,3] float 0..1, alpha [H,W,1] float 0..1
(zero everywhere except the glyphs and their optional stroke), and the tight
(x0, y0, x1, y1) box of non-transparent pixels so the blend only has to touch
the region the text actually occupies. None when there is nothing to draw."""
from PIL import Image, ImageDraw
import numpy as np
text = (text or "").strip()
if not text:
return None
img = Image.new("RGBA", (int(width), int(height)), (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
stroke_px = max(0, int(stroke_px))
margin = int(min(width, height) * max(0.0, margin_pct) / 100.0)
ax, ay = POSITIONS.get(position, POSITIONS["bottom-right"])
# Measure first, so the block is placed by its real size rather than a guess --
# and fit it to the space the margins actually leave.
max_w = max(1, int(width) - 2 * margin)
max_h = max(1, int(height) - 2 * margin)
font, text, box, spacing, font_px = _fit(draw, text, font_name, font_px, max_w, max_h,
stroke_px, line_spacing, wrap)
tw, th = box[2] - box[0], box[3] - box[1]
free_w = max(0, int(width) - 2 * margin - tw)
free_h = max(0, int(height) - 2 * margin - th)
x = margin + free_w * ax - box[0]
y = margin + free_h * ay - box[1]
kwargs = dict(font=font, fill=(255, 255, 255, 255), align="center")
if stroke_px:
kwargs.update(stroke_width=stroke_px, stroke_fill=(0, 0, 0, 255))
try:
draw.multiline_text((x, y), text, spacing=spacing, **kwargs)
except TypeError:
draw.multiline_text((x, y), text, **kwargs)
arr = np.asarray(img, dtype=np.float32) / 255.0 # [H, W, 4]
alpha = arr[..., 3:4]
if not alpha.any():
return None
# Tight bbox of drawn pixels: blending a whole 1344x768 frame for a corner
# watermark would cost ~50x more work on a 3000-frame chain.
ys, xs = np.nonzero(alpha[..., 0] > 0.0)
bbox = (int(xs.min()), int(ys.min()), int(xs.max()) + 1, int(ys.max()) + 1)
return (torch.from_numpy(arr[..., :3].copy()),
torch.from_numpy(alpha.copy()),
bbox)
def blend_layer(frames, layer, frame_alpha=None, opacity=1.0):
"""Alpha-composite a rendered layer over frames [N,H,W,3] in 0..1, in place.
frame_alpha is an optional per-frame multiplier (length N) -- that is what
makes an intro title hold and then fade instead of sitting on the whole
video. Frames whose multiplier is 0 are skipped entirely."""
if layer is None:
return frames
rgb, alpha, (x0, y0, x1, y1) = layer
n = frames.shape[0]
if frame_alpha is None:
frame_alpha = torch.ones(n, dtype=torch.float32)
frame_alpha = frame_alpha.to(torch.float32).clamp(0.0, 1.0) * float(opacity)
a_crop = alpha[y0:y1, x0:x1, :].to(frames.dtype)
c_crop = rgb[y0:y1, x0:x1, :].to(frames.dtype)
live = (frame_alpha > 0).nonzero().flatten().tolist()
for s in range(0, len(live), BLEND_CHUNK):
idx = live[s:s + BLEND_CHUNK]
fa = frame_alpha[idx].to(frames.dtype).view(-1, 1, 1, 1)
sub = frames[idx, y0:y1, x0:x1, :]
a = a_crop * fa
frames[idx, y0:y1, x0:x1, :] = sub * (1.0 - a) + c_crop * a
return frames
def hold_fade_alpha(total_frames, hold_frames, fade_frames):
"""Per-frame opacity for an intro: full through hold_frames, then a linear
ramp to zero over fade_frames, then nothing. Returns a length-N tensor."""
a = torch.zeros(int(total_frames), dtype=torch.float32)
hold = max(0, min(int(hold_frames), int(total_frames)))
a[:hold] = 1.0
fade = max(0, min(int(fade_frames), int(total_frames) - hold))
if fade:
a[hold:hold + fade] = torch.linspace(1.0, 0.0, fade + 2)[1:-1]
return a
def apply_overlays(frames, fps, watermark="", wm_position="bottom-right", wm_size_pct=4.0,
wm_opacity=0.75, wm_margin_pct=3.0, intro="", intro_seconds=3.0,
intro_fade=0.6, intro_size_pct=9.0, intro_position="center",
font_name="", stroke_px=0):
"""Composite the watermark (every frame) and the intro title (first seconds
only, then faded out). Returns (frames, note). Never raises -- a cosmetic
overlay must not be able to destroy a finished render."""
notes = []
if frames is None or frames.ndim != 4 or frames.shape[0] == 0:
return frames, ""
n, h, w = frames.shape[0], frames.shape[1], frames.shape[2]
frames = frames.contiguous()
# Size from the SHORT edge, not the height. Height is the long edge on every
# portrait preset, so a height-based percentage drew 9:16 text ~1.75x larger
# than the same setting at 16:9 -- on the canvas with the LEAST room for it.
# The short edge makes one setting mean the same apparent size at every ratio.
short = min(int(w), int(h))
if (watermark or "").strip():
try:
layer = render_text_layer(w, h, watermark, short * max(0.5, wm_size_pct) / 100.0,
wm_position, wm_margin_pct, font_name, stroke_px)
if layer is not None:
blend_layer(frames, layer, None, wm_opacity)
notes.append(f"watermark composited ({wm_position}, {wm_opacity:.0%})")
except Exception as e:
notes.append(f"watermark skipped ({type(e).__name__}: {e})")
if (intro or "").strip():
try:
layer = render_text_layer(w, h, intro, short * max(0.5, intro_size_pct) / 100.0,
intro_position, 6.0, font_name, stroke_px)
if layer is not None:
hold = round(max(0.0, float(intro_seconds)) * fps)
fade = round(max(0.0, float(intro_fade)) * fps)
fa = hold_fade_alpha(n, hold, fade)
if fa.max() > 0:
blend_layer(frames, layer, fa, 1.0)
notes.append(f"intro title composited ({hold}f hold + {fade}f fade)")
else:
notes.append("intro title skipped (no hold or fade frames)")
except Exception as e:
notes.append(f"intro title skipped ({type(e).__name__}: {e})")
return frames, "; ".join(notes)
-66
View File
@@ -1,66 +0,0 @@
"""
H3 Shot Length (single model-free source for shot length)
==========================================================
Holds ONE shot-length value and emits it as both seconds and a grid-aligned
H3 frame count. Because it never reads the model, it can sit upstream of
Kijai's Model Preview Override without creating a cycle -- unlike the preview
node or the sampler, which read the model to compute their frame counts and so
cannot feed anything that produces the model.
Wire:
H3 Shot Length (seconds) -> H3 Long Videos FL2VA (shot_seconds)
H3 Shot Length (frames) -> Model Preview Override (preview_frames)
One value, entered once here, drives both -- no manual re-entry, no cycle.
Note: this is a FIXED shot length you choose. The sampler's *auto* (VRAM-
picked) length can't be used for preview_frames, because computing it requires
reading the model, which is the very dependency that creates the loop. Set the
sampler's shot_seconds from this node's `seconds` output so the two agree.
"""
H3_MAX_FRAMES = 362
def align_up_grid(n):
n = max(5, int(n))
while n % 17 != 5:
n += 1
return n
class H3ShotLength:
CATEGORY = "Dumas/MiniMax"
FUNCTION = "emit"
RETURN_TYPES = ("FLOAT", "INT", "STRING")
RETURN_NAMES = ("seconds", "frames", "info")
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"shot_seconds": ("FLOAT", {"default": 5.0, "min": 0.2, "max": 15.1, "step": 0.5,
"tooltip": "Length of each shot. Feeds the sampler's shot_seconds AND (as frames) "
"the preview override. Max ~15s (362 frames)."}),
"fps": ("INT", {"default": 24, "min": 1, "max": 60}),
},
"optional": {
"cap_to_h3_max": ("BOOLEAN", {"default": True,
"tooltip": "Clamp frames to 362 (~15s), H3's single-clip maximum."}),
},
}
def emit(self, shot_seconds, fps, cap_to_h3_max=True):
fps = max(1, int(fps))
frames = align_up_grid(round(float(shot_seconds) * fps))
capped = cap_to_h3_max and frames > H3_MAX_FRAMES
if capped:
frames = H3_MAX_FRAMES
info = (f"{shot_seconds:g}s/shot @ {fps}fps -> {frames} frames"
f"{' (capped 362)' if capped else ''}")
return (round(float(shot_seconds), 3), frames, info)
NODE_CLASS_MAPPINGS = {"DumasH3ShotLength": H3ShotLength}
NODE_DISPLAY_NAME_MAPPINGS = {"DumasH3ShotLength": "Dumas H3 Shot Length"}
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
+86 -1853
View File
File diff suppressed because it is too large Load Diff
+50 -29
View File
@@ -277,7 +277,14 @@ class DumasJSONStringToObjectNode:
def INPUT_TYPES(cls):
return {
"required": {
"json_string": ("STRING", {"multiline": True}),
"json_string": (
"STRING",
{
"multiline": True,
"default": '{\n "shots": [\n {\n "prompt": "Francine stands by the window."\n }\n ]\n}',
"tooltip": "Raw JSON text to parse into a structured JSON object."
},
),
}
}
@@ -299,7 +306,14 @@ class DumasStripIterationSuffixNode:
def INPUT_TYPES(cls):
return {
"required": {
"filename": ("STRING", {"default": "", "multiline": False}),
"filename": (
"STRING",
{
"default": "francine_pose_final.png",
"multiline": False,
"tooltip": "Filename to normalize by removing everything after the first underscore in the stem."
},
),
}
}
@@ -316,7 +330,14 @@ class DumasSlugifyStringNode:
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"default": "", "multiline": False}),
"text": (
"STRING",
{
"default": "Francine Coffee Shop",
"multiline": False,
"tooltip": "Text to slugify into lowercase ASCII words joined with hyphens."
},
),
}
}
@@ -334,8 +355,8 @@ class DumasJSONObjectToStringNode:
return {
"required": {
"json_object": ("JSON",),
"pretty": ("BOOLEAN", {"default": True}),
"sort_keys": ("BOOLEAN", {"default": False}),
"pretty": ("BOOLEAN", {"default": True, "tooltip": "Pretty-print the JSON with indentation."}),
"sort_keys": ("BOOLEAN", {"default": False, "tooltip": "Sort object keys alphabetically before serializing."}),
}
}
@@ -355,7 +376,7 @@ class DumasJSONGetValueNode:
return {
"required": {
"json_object": ("JSON",),
"path": ("STRING", {"default": "", "multiline": False}),
"path": ("STRING", {"default": "shots.0.prompt", "multiline": False, "tooltip": "Dot-path to read, such as 'shots.0.prompt'."}),
}
}
@@ -373,8 +394,8 @@ class DumasJSONSetValueNode:
return {
"required": {
"json_object": ("JSON",),
"path": ("STRING", {"default": "", "multiline": False}),
"value_json": ("STRING", {"multiline": True, "default": "null"}),
"path": ("STRING", {"default": "shots.0.prompt", "multiline": False, "tooltip": "Dot-path to write, such as 'shots.0.prompt' or 'shots.1.duration'."}),
"value_json": ("STRING", {"multiline": True, "default": '"Francine stands by the window."', "tooltip": "JSON value to store at the path. Must be valid JSON, so strings need quotes."}),
}
}
@@ -398,7 +419,7 @@ class DumasJSONHasKeyNode:
return {
"required": {
"json_object": ("JSON",),
"path": ("STRING", {"default": "", "multiline": False}),
"path": ("STRING", {"default": "shots.0.prompt", "multiline": False, "tooltip": "Dot-path to test for existence."}),
}
}
@@ -416,7 +437,7 @@ class DumasJSONRemoveKeyNode:
return {
"required": {
"json_object": ("JSON",),
"path": ("STRING", {"default": "", "multiline": False}),
"path": ("STRING", {"default": "shots.0.prompt", "multiline": False, "tooltip": "Dot-path to remove from the object."}),
}
}
@@ -434,7 +455,7 @@ class DumasJSONPickFieldsNode:
return {
"required": {
"json_object": ("JSON",),
"paths": ("STRING", {"multiline": True, "default": ""}),
"paths": ("STRING", {"multiline": True, "default": "shots.0.prompt\nshots.0.duration", "tooltip": "One dot-path per line. Only those fields are copied into the output object."}),
}
}
@@ -463,8 +484,8 @@ class DumasJSONMergeObjectsNode:
def INPUT_TYPES(cls):
return {
"required": {
"base_object": ("JSON",),
"overlay_object": ("JSON",),
"base_object": ("JSON", {"tooltip": "Base JSON object to start from."}),
"overlay_object": ("JSON", {"tooltip": "Overlay JSON object whose keys replace or merge into the base object."}),
}
}
@@ -482,7 +503,7 @@ class DumasJSONKeysNode:
def INPUT_TYPES(cls):
return {
"required": {
"json_object": ("JSON",),
"json_object": ("JSON", {"tooltip": "JSON object whose top-level keys should be listed."}),
}
}
@@ -502,7 +523,7 @@ class DumasJSONArrayLengthNode:
def INPUT_TYPES(cls):
return {
"required": {
"json_array": ("JSON",),
"json_array": ("JSON", {"tooltip": "JSON array whose length should be measured."}),
}
}
@@ -521,8 +542,8 @@ class DumasJSONArrayAppendNode:
def INPUT_TYPES(cls):
return {
"required": {
"json_array": ("JSON",),
"value_json": ("STRING", {"multiline": True, "default": "null"}),
"json_array": ("JSON", {"tooltip": "JSON array to append to."}),
"value_json": ("STRING", {"multiline": True, "default": '{"prompt":"Francine looks toward the door."}', "tooltip": "JSON value to append. Must be valid JSON."}),
}
}
@@ -548,10 +569,10 @@ class DumasJSONArraySliceNode:
def INPUT_TYPES(cls):
return {
"required": {
"json_array": ("JSON",),
"start": ("INT", {"default": 0, "step": 1}),
"end": ("INT", {"default": 0, "step": 1}),
"step": ("INT", {"default": 1, "step": 1, "min": 1}),
"json_array": ("JSON", {"tooltip": "JSON array to slice."}),
"start": ("INT", {"default": 0, "step": 1, "tooltip": "Zero-based start index."}),
"end": ("INT", {"default": 0, "step": 1, "tooltip": "Zero-based end index. Use 0 to mean 'to the end'."}),
"step": ("INT", {"default": 1, "step": 1, "min": 1, "tooltip": "Slice step size."}),
}
}
@@ -572,9 +593,9 @@ class DumasJSONArrayIteratorNode:
def INPUT_TYPES(cls):
return {
"required": {
"json_input": ("JSON",),
"index": ("INT", {"default": 0, "min": 0, "step": 1}),
"mode": (["fixed", "incr", "decr"], {"default": "fixed"}),
"json_input": ("JSON", {"tooltip": "JSON array to iterate over."}),
"index": ("INT", {"default": 0, "min": 0, "step": 1, "tooltip": "Current zero-based index."}),
"mode": (["fixed", "incr", "decr"], {"default": "fixed", "tooltip": "Keep the index fixed, increment it, or decrement it before reading."}),
}
}
@@ -600,9 +621,9 @@ class DumasJSONObjectIteratorNode:
def INPUT_TYPES(cls):
return {
"required": {
"json_input": ("JSON",),
"index": ("INT", {"default": 0, "min": 0, "step": 1}),
"mode": (["fixed", "incr", "decr"], {"default": "fixed"}),
"json_input": ("JSON", {"tooltip": "JSON object whose key/value pairs should be iterated in insertion order."}),
"index": ("INT", {"default": 0, "min": 0, "step": 1, "tooltip": "Current zero-based index into the object's items."}),
"mode": (["fixed", "incr", "decr"], {"default": "fixed", "tooltip": "Keep the index fixed, increment it, or decrement it before reading."}),
}
}
@@ -628,7 +649,7 @@ class DumasJSONFlattenNode:
def INPUT_TYPES(cls):
return {
"required": {
"json_input": ("JSON",),
"json_input": ("JSON", {"tooltip": "Nested JSON value to flatten into dot-path keys."}),
}
}
@@ -645,7 +666,7 @@ class DumasJSONUnflattenNode:
def INPUT_TYPES(cls):
return {
"required": {
"flat_json_object": ("JSON",),
"flat_json_object": ("JSON", {"tooltip": "Flat JSON object whose keys are dot-paths to rebuild into nested JSON."}),
}
}
+240
View File
@@ -0,0 +1,240 @@
"""Generic video helpers for sequential ComfyUI projects.
The nodes in this module deliberately operate on ordinary IMAGE/AUDIO values
and completed video paths. They do not depend on a particular video model or
custom sampler.
"""
import json
import os
import re
import subprocess
import tempfile
import time
import wave
from pathlib import Path
try:
import numpy as np
except ImportError: # The ComfyUI runtime provides NumPy; keep import-time tests lightweight.
np = None
import folder_paths
_SAFE_NAME = re.compile(r"[^A-Za-z0-9_.-]+")
def _safe_name(value, fallback):
name = _SAFE_NAME.sub("_", str(value or "").strip()).strip("._")
return name or fallback
def _output_path(prefix, suffix="mp4"):
root = Path(folder_paths.get_output_directory())
root.mkdir(parents=True, exist_ok=True)
stamp = time.strftime("%Y%m%d_%H%M%S")
return root / f"{_safe_name(prefix, 'clip')}_{stamp}_{time.time_ns() % 1000000:06d}.{suffix}"
def _audio_arrays(audio):
if np is None:
raise RuntimeError("NumPy is required to encode video frames.")
if not audio:
return None
waveform = audio.get("waveform") if isinstance(audio, dict) else None
sample_rate = int(audio.get("sample_rate", 48000)) if isinstance(audio, dict) else 48000
if waveform is None:
return None
values = waveform.detach().cpu().numpy() if hasattr(waveform, "detach") else np.asarray(waveform)
if values.ndim == 3:
values = values[0]
if values.ndim == 1:
values = values[None, :]
if values.shape[0] == 1:
values = np.repeat(values, 2, axis=0)
values = values[:2]
return np.clip(values, -1.0, 1.0), sample_rate
def _write_wav(audio, path, start_sample=0):
prepared = _audio_arrays(audio)
if prepared is None:
return None
values, sample_rate = prepared
values = values[:, start_sample:]
interleaved = (values.T * 32767.0).astype("<i2").tobytes()
with wave.open(str(path), "wb") as stream:
stream.setnchannels(values.shape[0])
stream.setsampwidth(2)
stream.setframerate(sample_rate)
stream.writeframes(interleaved)
return sample_rate
def _encode_images(images, audio, output_path, fps, start_frame=0):
if images is None or len(images) <= start_frame:
raise ValueError("Dumas video output has no frames after the requested overlap.")
first = images[0].detach().cpu().numpy() if hasattr(images[0], "detach") else np.asarray(images[0])
height, width = int(first.shape[0]), int(first.shape[1])
wav_path = None
audio_rate = None
try:
prepared = _audio_arrays(audio)
if prepared is not None:
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as handle:
wav_path = Path(handle.name)
audio_rate = _write_wav(audio, wav_path, int(round(start_frame / fps * prepared[1])))
command = [
"ffmpeg", "-hide_banner", "-loglevel", "error", "-y",
"-f", "rawvideo", "-pix_fmt", "rgb24", "-s", f"{width}x{height}",
"-r", str(float(fps)), "-i", "-",
]
if wav_path is not None:
command += ["-i", str(wav_path)]
command += ["-map", "0:v:0", "-c:v", "libx264", "-preset", "fast", "-crf", "18", "-pix_fmt", "yuv420p"]
if wav_path is not None:
command += ["-map", "1:a:0", "-c:a", "aac", "-b:a", "192k", "-shortest"]
command += ["-movflags", "+faststart", str(output_path)]
process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
for frame in images[start_frame:]:
array = frame.detach().cpu().numpy() if hasattr(frame, "detach") else np.asarray(frame)
if array.shape[:2] != (height, width) or array.shape[-1] < 3:
raise ValueError("All video frames must have the same RGB dimensions.")
process.stdin.write(np.ascontiguousarray(np.clip(array[..., :3] * 255.0, 0, 255).astype(np.uint8)).tobytes())
process.stdin.close()
except Exception:
process.kill()
process.wait()
raise
error = process.stderr.read().decode("utf-8", "replace")
result = process.wait()
if result != 0:
raise RuntimeError(f"ffmpeg could not encode the video: {error.strip()}")
finally:
if wav_path is not None:
wav_path.unlink(missing_ok=True)
return str(output_path)
def _probe(path):
result = subprocess.run(
["ffprobe", "-v", "error", "-show_streams", "-show_format", "-of", "json", str(path)],
capture_output=True, text=True, check=False,
)
if result.returncode != 0:
raise RuntimeError(f"ffprobe could not inspect {path}: {result.stderr.strip()}")
return json.loads(result.stdout or "{}")
def _join_signature(info):
streams = info.get("streams", [])
video = next((item for item in streams if item.get("codec_type") == "video"), None)
audio = next((item for item in streams if item.get("codec_type") == "audio"), None)
if video is None:
raise ValueError("Every joined clip must contain a video stream.")
return (
video.get("codec_name"), video.get("width"), video.get("height"),
video.get("pix_fmt"), video.get("r_frame_rate"),
(audio or {}).get("codec_name"), (audio or {}).get("sample_rate"),
(audio or {}).get("channels"),
)
class DumasStandaloneVideoNode:
"""Save a full generated clip and a trimmed, assembly-ready clip."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"images": ("IMAGE",),
"fps": ("FLOAT", {"default": 24.0, "min": 1.0, "max": 240.0, "step": 0.001}),
"overlap_frames": ("INT", {"default": 0, "min": 0, "max": 4096}),
"filename_prefix": ("STRING", {"default": "dumas/clip"}),
},
"optional": {"audio": ("AUDIO",)},
}
RETURN_TYPES = ("STRING", "STRING", "INT", "FLOAT")
RETURN_NAMES = ("full_clip", "complete_clip", "complete_frames", "duration")
FUNCTION = "save"
CATEGORY = "Dumas/Video"
OUTPUT_NODE = True
def save(self, images, fps, overlap_frames, filename_prefix, audio=None):
total = len(images)
overlap = int(overlap_frames)
if overlap >= total:
raise ValueError(f"Overlap ({overlap}) must be smaller than the clip ({total} frames).")
full = _output_path(f"{filename_prefix}_full")
complete = _output_path(f"{filename_prefix}_complete")
_encode_images(images, audio, full, float(fps), 0)
_encode_images(images, audio, complete, float(fps), overlap)
count = total - overlap
return str(full), str(complete), count, count / float(fps)
class DumasJoinVideoClipsNode:
"""Concatenate already-complete clips with FFmpeg stream copy."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {"clip_1": ("STRING", {"default": "", "multiline": False})},
"optional": {
"clip_2": ("STRING", {"default": ""}),
"clip_3": ("STRING", {"default": ""}),
"clip_4": ("STRING", {"default": ""}),
"clip_5": ("STRING", {"default": ""}),
"clip_6": ("STRING", {"default": ""}),
"filename_prefix": ("STRING", {"default": "dumas/assembled_video"}),
},
}
RETURN_TYPES = ("STRING", "INT", "FLOAT")
RETURN_NAMES = ("joined_clip", "clip_count", "duration")
FUNCTION = "join"
CATEGORY = "Dumas/Video"
OUTPUT_NODE = True
def join(self, clip_1, clip_2="", clip_3="", clip_4="", clip_5="", clip_6="", filename_prefix="dumas/assembled_video"):
clips = [str(path).strip().strip('"').strip("'") for path in (clip_1, clip_2, clip_3, clip_4, clip_5, clip_6) if str(path or "").strip()]
if not clips:
raise ValueError("Connect at least one completed clip.")
if any(not os.path.isfile(path) for path in clips):
missing = next(path for path in clips if not os.path.isfile(path))
raise FileNotFoundError(f"Completed clip not found: {missing}")
signatures = [_join_signature(_probe(path)) for path in clips]
if any(signature != signatures[0] for signature in signatures[1:]):
raise ValueError("Clips do not share compatible codec, dimensions, frame rate, pixel format or audio format.")
output = _output_path(filename_prefix)
with tempfile.NamedTemporaryFile("w", suffix=".txt", delete=False, encoding="utf-8") as handle:
list_path = Path(handle.name)
for path in clips:
escaped = str(Path(path).resolve()).replace("'", "'\\''")
handle.write(f"file '{escaped}'\n")
try:
command = ["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-f", "concat", "-safe", "0", "-i", str(list_path), "-c", "copy", "-movflags", "+faststart", str(output)]
result = subprocess.run(command, capture_output=True, text=True, check=False)
if result.returncode != 0:
raise RuntimeError(f"ffmpeg could not join the clips without re-encoding: {result.stderr.strip()}")
finally:
list_path.unlink(missing_ok=True)
duration = float((_probe(output).get("format") or {}).get("duration") or 0.0)
return str(output), len(clips), duration
NODE_CLASS_MAPPINGS = {
"DumasStandaloneVideo": DumasStandaloneVideoNode,
"DumasJoinVideoClips": DumasJoinVideoClipsNode,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"DumasStandaloneVideo": "Dumas Standalone Video",
"DumasJoinVideoClips": "Dumas Join Video Clips (No Re-encode)",
}
-85
View File
@@ -1,85 +0,0 @@
import { app } from "/scripts/app.js";
const NODE_NAME = "DumasAnchorStyle";
const STYLE_INPUT = "anchor_style";
const DESCRIPTION_INPUT = "style_description";
const H3_NOTE = " Keep this anchor focused on persistent camera language, lighting, texture, environment treatment, and tone; do not name characters or describe one-off actions.";
const PRESETS = {
"cinematic action movie": "Big-screen action cinema with assertive visual storytelling: dynamic camera placement, strong forward momentum, crisp geography, muscular lighting contrast, practical atmosphere, and a sense of physical consequence. Favor heroic framing, controlled handheld energy or motivated tracking moves, dramatic silhouettes, tasteful lens flares, impact-driven pacing, and polished studio spectacle without drifting into comic-book unreality unless the shot explicitly asks for it." + H3_NOTE,
"comedy": "Play the scene for comedic readability and timing: clear staging, expressive performances, slightly heightened reactions, clean eyelines, and visual beats that leave room for the joke to land. Use bright approachable lighting, grounded but playful production design, readable framing, and a tone that feels observant, awkward, or absurd without becoming broad parody unless the action supports it." + H3_NOTE,
"found footage": "Captured as raw found-footage material by someone physically present in the scene: imperfect handheld movement, reactive reframing, clipped composition, sudden zooms or focus hunts, practical exposure changes, and the feeling that the camera operator is discovering events in real time. Keep the image messy but legible, accidental rather than cinematic, with authentic panic, hesitation, and ambient noise." + H3_NOTE,
"90s sitcom": "Classic 1990s multi-camera sitcom language: bright even stage lighting, cozy production design, clean master coverage, medium-wide proscenium framing, fast readable blocking, and performances calibrated for studio audience laughs. The world should feel warm, slightly idealized, and television-friendly, with practical interiors, punchy pauses, and visual simplicity that prioritizes character business." + H3_NOTE,
"mobile/cell phone captured": "Looks like it was shot casually on a phone by an ordinary person: vertical-video instincts even when the frame is horizontal, imperfect stabilization, auto-exposure breathing, clipped highlights, shallow device-grade dynamic range, and opportunistic framing. Keep it intimate, immediate, and plausibly amateur, with sudden pans, uncertain focus, and informal proximity that feel genuinely captured." + H3_NOTE,
"news broadcast": "Television news coverage with clear institutional polish: composed framing, practical key lighting, sober color balance, authoritative pacing, and a documentarian sense of informational clarity. Favor reporter or live-hit visual grammar, observational cutaway logic, steady camera operation, concise emphasis, and a tone that feels current, factual, and broadcast-safe rather than entertainment-first." + H3_NOTE,
"prestige tv drama": "Prestige television drama with premium streaming polish: restrained confidence, textured naturalism, nuanced performances, motivated camera movement, and carefully shaped practical lighting. The mood should feel mature and expensive, with layered production design, cinematic color separation, and emotionally observant framing that trusts silence and subtext." + H3_NOTE,
"psychological thriller": "Unsettling psychological-thriller grammar: controlled tension, negative space, ambiguous visual information, subtle distortion of normality, and lighting that suggests emotional danger more than physical spectacle. Favor lingering compositions, invasive close-ups, reflective surfaces, uneasy stillness, and a slow escalation of dread." + H3_NOTE,
"horror": "Lean into horror atmosphere and threat: moody low-key lighting, oppressive space, directional contrast, tactile production texture, and suspenseful framing that weaponizes what is barely seen. The scene should feel unsafe and anticipatory, with sound-implied menace, uneasy empty areas in frame, and a commitment to dread over cheap chaos." + H3_NOTE,
"science fiction epic": "Expansive science-fiction worldbuilding with polished futuristic scale: elegant production design, disciplined visual effects logic, atmospheric depth, and camera language that makes technology feel integrated and believable. Balance awe with clarity, using sleek surfaces, volumetric light, controlled color motifs, and a sense of society beyond the immediate shot." + H3_NOTE,
"space opera": "Large-scale space opera with mythic emotion and visual grandeur: bold silhouettes, operatic lighting, sweeping camera movement, heroic compositions, and a heightened sense of destiny. Keep the worlds rich and theatrical, with dramatic color, iconic staging, and spectacle that feels earnest and adventurous." + H3_NOTE,
"western": "Cinematic western visual language: expansive landscapes, strong horizon lines, weathered textures, harsh natural light, deliberate blocking, and a sense of moral tension embedded in open space. Favor patient compositions, boots-on-dust realism, iconic stand-off geometry, and tactile period detail without romanticizing away the grit." + H3_NOTE,
"neo-noir": "Neo-noir mood with urban tension and seductive darkness: hard contrast, reflective surfaces, sodium vapor or neon accents, morally complicated framing, and a sense that every location hides compromise. Use rain, smoke, glass, and deep shadow strategically, with stylish but controlled camera work." + H3_NOTE,
"period drama": "Refined period-drama treatment with historical texture, tailored production design, graceful camera movement, and careful social observation. Light the world with soft elegance and believable practical motivation, prioritizing fabric, architecture, etiquette, and emotional restraint over flashy stylization." + H3_NOTE,
"documentary vérité": "Observational documentary vérité: minimally intrusive camera behavior, natural available light, patient real-time watchfulness, and an emphasis on lived-in truth over visual perfection. The frame can breathe, drift, and adjust as events unfold, but it should always feel honestly present rather than staged." + H3_NOTE,
"music video": "Stylized music-video direction with strong visual authorship: rhythmic movement, bold color design, heightened pose, graphic composition, and a willingness to prioritize vibe and image over literal realism. Keep it polished and intent-driven, with kinetic transitions, fashion-forward staging, and synchronized intensity." + H3_NOTE,
"luxury commercial": "Premium commercial polish aimed at aspiration and desirability: immaculate composition, glossy surfaces, refined lighting control, slow confident camera movement, and tactile focus on premium materials. Everything should feel precise, expensive, and seductively curated, with no accidental mess unless it serves the concept." + H3_NOTE,
"true crime reenactment": "True-crime reenactment style with documentary dramatization: moody but legible lighting, restrained suspense, partial visual withholding, and a tone that suggests reconstruction rather than action filmmaking. Use practical locations, careful anonymity or selective detail, and sober tension that feels broadcast-doc adjacent." + H3_NOTE,
"surveillance / cctv": "Fixed surveillance-camera capture with institutional detachment: elevated or corner-mounted viewpoint, wide coverage, unflattering perspective, limited dynamic range, compressed detail, and an impersonal observational tone. Avoid cinematic composition; the power comes from banality, distance, and timestamp-era bluntness." + H3_NOTE,
"bodycam": "Police or security bodycam perspective: chest-mounted, wide-angle, unstable, close to breath and motion, with abrupt tilts, partial occlusion, clipped framing, and urgent first-person proximity. The footage should feel evidentiary and high-stress, more reactive than composed, while remaining coherent enough to follow action." + H3_NOTE,
"vlog / creator video": "Online creator or vlog visual style: personable direct address, flattering but casual framing, expressive presentation, and a self-aware sense of on-camera performance. Lighting should feel creator-friendly and approachable, with clean image quality, lifestyle polish, and a balance between authenticity and charisma." + H3_NOTE,
"anime cinematic": "High-end anime feature or prestige series look translated into shot design: expressive composition, dynamic perspective, graphic silhouette readability, emotionally heightened staging, and clean intentional shape language. Push atmosphere, color motifs, and dramatic key moments while keeping spatial storytelling clear." + H3_NOTE,
"indie mumblecore": "Low-budget indie mumblecore naturalism: intimate handheld or locked-off simplicity, imperfect but observant framing, natural light or modest practicals, and performances that feel conversational rather than plot-driven. Let awkward pauses, environmental plainness, and human messiness carry the tone instead of visual over-design." + H3_NOTE,
"elevated fantasy": "Sophisticated fantasy realism with mythic texture and grounded physical detail: rich environments, atmospheric scale, carefully motivated magical elements, and a serious emotional register. The world should feel old, inhabited, and culturally specific, with visual wonder rooted in tactile materials rather than generic glow." + H3_NOTE,
"procedural cop show": "Mainstream procedural television style: efficient visual clarity, stable coverage, lightly stylized realism, and quick storytelling that privileges evidence, reactions, and spatial logic. Use functional but polished lighting, confident blocking, and a tone that feels network-accessible, competent, and case-driven." + H3_NOTE,
"romantic drama": "Emotion-first romantic drama treatment: tender close observation, flattering naturalistic light, soft but not mushy contrast, and framing that prioritizes vulnerability, chemistry, and meaningful silence. The scene should feel intimate, earnest, and visually attentive to touch, glance, and emotional hesitation." + H3_NOTE,
"grindhouse exploitation": "Aggressive grindhouse/exploitation texture: rough-edged energy, dirty contrast, oversaturated or faded color bias, abrasive zooms, tactile film wear vibes, and sensational staging that feels dangerous, pulpy, and disreputable. Keep the image gleefully imperfect and confrontational rather than polished." + H3_NOTE,
"video essay b-roll": "Thoughtful video-essay b-roll style: visually articulate, idea-supporting imagery with tasteful motion, strong graphic clarity, and composition that feels editorially useful. The tone should be polished but not flashy, descriptive rather than dramatic, with images that communicate theme, context, and texture efficiently." + H3_NOTE,
"reality tv": "Unscripted reality-TV coverage: reactive zooms, multiple-camera energy implied in the framing, practical interiors, performance-aware spontaneity, and a tone that amplifies interpersonal drama. Keep it bright, legible, and emotionally available, with visual beats that feel captured in the moment rather than authored." + H3_NOTE,
"mockumentary": "Dry mockumentary television language: documentary-adjacent framing, subtle handheld correction, practical lighting, awkwardly observational composition, and a restrained deadpan tone. Favor unshowy zooms, banal office or domestic realism, and the sense that the camera crew is tolerated but not invisible." + H3_NOTE,
"arthouse european drama": "Arthouse European drama with patient formal control: composed frames, long takes, naturalistic light, architectural blocking, and emotional understatement. Favor stillness, social texture, understated color, and a feeling of psychological interiority carried by space, rhythm, and observation." + H3_NOTE,
"heist thriller": "Precision heist-thriller treatment: controlled camera motion, spatial legibility, cool confidence, metallic surfaces, disciplined blocking, and tension built through logistics and timing. Keep the atmosphere sleek, high-competence, and pressure-driven, with crisp visual geography and tactile procedural detail." + H3_NOTE,
"war film": "Grounded war-film intensity: unstable but purposeful camera behavior, particulate atmosphere, desaturated or earth-heavy color, physical debris, and a sense of fatigue under pressure. Favor battlefield confusion held inside readable geography, practical smoke, dirty textures, and severe consequential realism." + H3_NOTE,
"cyberpunk neon": "Dense cyberpunk-neon treatment: saturated artificial color, wet reflective surfaces, layered signage glow, polluted atmosphere, and a future built from crowding, commerce, and exhaustion. Favor deep perspective, volumetric haze, mixed light temperatures, and a sleek but grimy high-tech urban mood." + H3_NOTE,
"teen drama": "Contemporary teen-drama polish: emotionally legible framing, attractive soft-contrast lighting, heightened color styling, and a tone tuned to vulnerability, longing, status, and social friction. Keep the world glossy but recognizably lived-in, with image-making that feels youthful, immediate, and emotionally open." + H3_NOTE,
"soap opera": "Daytime soap-opera visual grammar: bright even lighting, clean coverage, dramatic reaction framing, polished interiors, and emotional emphasis that reads quickly and clearly. Favor smooth camera operation, attractive presentation, and heightened sincerity over realism or subtle restraint." + H3_NOTE,
"sports broadcast": "Live sports-broadcast treatment: long-lens observation, decisive coverage, graphic clarity, crowd-scale energy, and camera choices that prioritize play readability and event momentum. Keep the look live, crisp, and production-truck efficient rather than cinematic, with fast reframing and institutional polish." + H3_NOTE,
"nature documentary": "Premium nature-documentary look: patient long-lens observation, environmental atmosphere, tactile weather detail, and a sense of scale that respects habitat and natural behavior. Favor pristine image clarity, measured camera movement, dawn or dusk richness, and reverent attention to terrain, foliage, and light." + H3_NOTE,
"travel vlogger": "Travel-vlogger presentation with upbeat personal immediacy: lightweight camera movement, lifestyle polish, sunlit color, enthusiastic visual curiosity, and framing that alternates between direct address and scenic show-and-tell. Keep the image accessible, glossy, and experience-forward without becoming luxury-commercial stiff." + H3_NOTE,
"cooking show": "Food-television treatment with appetizing clarity: warm flattering light, clean overheads or medium coverage, tactile ingredient detail, and a polished domestic-professional tone. Favor inviting color, crisp texture, steamy atmosphere, and visual readability that makes surfaces, tools, and food prep feel satisfying." + H3_NOTE,
"public access tv": "Low-budget public-access television look: flat lighting, basic cameras, earnest staging, local-studio color, and awkwardly sincere presentation. Keep the image slightly dated, mildly cheap, and charmingly unvarnished, with simple framing and a community-TV sense of limited means but real enthusiasm." + H3_NOTE,
"infomercial": "Direct-response infomercial style: bright high-key lighting, clear product-first framing, emphatic readability, friendly presentation, and a tone of practical persuasion. Favor obvious utility, clean set styling, smooth camera movement, and visually demonstrative simplicity over mood or subtle atmosphere." + H3_NOTE,
"courtroom drama": "Courtroom-drama treatment with institutional gravity: balanced coverage, wood-and-fabric texture, controlled camera moves, measured authority, and tension carried through testimony, reactions, and procedure. Keep the look sober, formal, and performance-attentive, with clean eyelines and serious architectural presence." + H3_NOTE,
"fantasy adventure": "Rousing fantasy-adventure language: scenic scale, adventurous clarity, tactile costume-and-prop detail, and camera movement that feels exploratory rather than oppressive. Favor storybook geography, weathered materials, golden or stormy atmosphere, and a tone of peril, wonder, and forward motion." + H3_NOTE,
};
function findWidget(node, name) {
return (node.widgets || []).find((widget) => widget?.name === name) || null;
}
app.registerExtension({
name: "Dumas.AnchorStyle",
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData?.name !== NODE_NAME) return;
const originalOnNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function onNodeCreated() {
const created = originalOnNodeCreated?.apply(this, arguments);
const styleWidget = findWidget(this, STYLE_INPUT);
const descriptionWidget = findWidget(this, DESCRIPTION_INPUT);
if (!styleWidget || !descriptionWidget) return created;
const originalCallback = styleWidget.callback;
styleWidget.callback = (...args) => {
const selected = String(styleWidget.value || "");
if (Object.hasOwn(PRESETS, selected)) {
descriptionWidget.value = PRESETS[selected];
descriptionWidget.inputEl?.dispatchEvent(new Event("input", { bubbles: true }));
}
this.setDirtyCanvas?.(true, true);
return originalCallback?.apply(styleWidget, args);
};
return created;
};
},
});
-634
View File
@@ -1,634 +0,0 @@
import { app } from "/scripts/app.js";
import { applyAdaptiveCanvasOnly } from "../shared/nodes2.mjs";
const COMFY_CLASS = "DumasH3BeatPrompt";
const HIDDEN_INPUT_NAME = "H3BeatPromptState";
const MIN_W = 420;
const DEFAULT_W = 520;
const DEFAULT_H = 340;
const DEFAULT_BEAT = "Describe this beat.";
const STATE_PROPERTY = "dumas_h3_beat_prompt_state";
const CONTINUITY_OPTIONS = ["", "soft carry", "hard cut", "keyframe carry", "handoff ref"];
const REF_MODE_OPTIONS = ["", "auto ref2v", "where tagged", "first shot", "every shot", "every shot + handoff ref"];
const MANAGED_DIRECTIVES = {
seconds: ["seconds", "duration"],
continuity: ["continuity"],
ref_mode: ["ref_mode"],
ref_noise_aug: ["ref_noise_aug"],
anchor_add: ["anchor_add"],
overall_soundscape: ["overall_soundscape", "soundscape"],
non_diegetic_music: ["non_diegetic_music", "music"],
};
const DIRECTIVE_EXAMPLES = [
["wardrobe set", "wardrobe: Maya = grey shorts, red jacket"],
["wardrobe add", "wardrobe: Maya += red jacket"],
["wardrobe remove", "wardrobe: Maya -= red jacket"],
["seconds", "seconds: 8"],
["exit", "exit: Maya"],
["enter", "enter: Jon"],
["continuity", "continuity: hard cut"],
["ref_mode", "ref_mode: every shot"],
["ref_noise_aug", "ref_noise_aug: 0.92"],
["anchor_add", "anchor_add: harsh sodium-vapor spill, wet pavement, long-lens compression"],
["overall_soundscape", "overall_soundscape: soft rain, distant traffic"],
["non_diegetic_music", "non_diegetic_music: tense analog synth pulse"],
["soundscape", "soundscape: fluorescent room tone, faint HVAC hum"],
["music", "music: low ominous cello and sparse percussion"],
];
function injectCSS() {
if (document.getElementById("dumas-h3-beat-prompt-css")) return;
const style = document.createElement("style");
style.id = "dumas-h3-beat-prompt-css";
style.textContent = `
.dh3bp-root {
box-sizing: border-box;
width: 100%;
pointer-events: auto;
color: #e8e8e8;
font: 12px/1.35 "Segoe UI", sans-serif;
padding: 8px 10px 10px;
}
.dh3bp-toolbar {
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
margin-bottom: 10px;
}
.dh3bp-title {
font-size: 12px;
font-weight: 600;
color: #f0f0f0;
}
.dh3bp-subtitle {
color: #9da3ae;
font-size: 11px;
}
.dh3bp-add {
background: #e66a2c;
color: #fff;
border: 1px solid #f28b57;
border-radius: 7px;
padding: 6px 10px;
cursor: pointer;
font-weight: 600;
}
.dh3bp-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.dh3bp-beat {
background: #1e2025;
border: 1px solid #363a42;
border-radius: 10px;
padding: 10px;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
}
.dh3bp-head {
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
.dh3bp-label {
color: #f3f4f6;
font-size: 12px;
font-weight: 600;
}
.dh3bp-remove {
background: transparent;
color: #f59a9a;
border: 1px solid #5a2c2c;
border-radius: 6px;
padding: 4px 8px;
cursor: pointer;
font-size: 11px;
}
.dh3bp-remove:disabled {
opacity: 0.45;
cursor: default;
}
.dh3bp-text {
width: 100%;
min-height: 96px;
resize: vertical;
box-sizing: border-box;
background: #121418;
color: #e8e8e8;
border: 1px solid #3c414a;
border-radius: 8px;
padding: 8px 10px;
font: 12px/1.4 "Consolas", "SFMono-Regular", monospace;
margin-bottom: 8px;
}
.dh3bp-directives {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.dh3bp-controls {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
margin-bottom: 10px;
}
.dh3bp-control {
display: flex;
flex-direction: column;
gap: 4px;
}
.dh3bp-control-wide {
grid-column: 1 / -1;
}
.dh3bp-control-label {
color: #b8bec8;
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.dh3bp-input,
.dh3bp-select {
width: 100%;
box-sizing: border-box;
background: #121418;
color: #e8e8e8;
border: 1px solid #3c414a;
border-radius: 8px;
padding: 7px 9px;
font: 12px/1.35 "Segoe UI", sans-serif;
}
.dh3bp-input::placeholder {
color: #7f8793;
}
.dh3bp-directive {
background: #252a33;
color: #d4d9e1;
border: 1px solid #414754;
border-radius: 999px;
padding: 4px 8px;
cursor: pointer;
font-size: 11px;
line-height: 1.2;
}
.dh3bp-directive:hover,
.dh3bp-remove:hover,
.dh3bp-add:hover {
filter: brightness(1.08);
}
`;
document.head.appendChild(style);
}
function defaultState() {
return { beats: [{ text: DEFAULT_BEAT }] };
}
function normalizeState(value) {
let parsed = value;
if (typeof parsed === "string") {
try {
parsed = JSON.parse(parsed);
} catch (_error) {
parsed = null;
}
}
if (!parsed || typeof parsed !== "object") return defaultState();
const beats = Array.isArray(parsed.beats) ? parsed.beats : [];
const normalized = beats.map((beat) => ({
text: typeof beat?.text === "string" ? beat.text : String(beat?.text || ""),
}));
return normalized.length ? { beats: normalized } : defaultState();
}
function readState(node) {
return normalizeState(
node.properties?.[STATE_PROPERTY]
|| findWidget(node, HIDDEN_INPUT_NAME)?.value
|| node._dh3bpState
|| ""
);
}
function findWidget(node, name) {
return (node.widgets || []).find((widget) => widget?.name === name);
}
function hideWidget(node, name) {
const widget = findWidget(node, name);
if (!widget) return;
widget.origType = widget.origType || widget.type;
widget.type = "hidden";
widget.computeSize = () => [0, 0];
widget.hidden = true;
}
function writeState(node, state) {
const normalized = normalizeState(state);
const serialized = JSON.stringify(normalized);
node._dh3bpState = serialized;
node.properties = node.properties || {};
node.properties[STATE_PROPERTY] = serialized;
const widget = findWidget(node, HIDDEN_INPUT_NAME);
if (widget) widget.value = serialized;
}
function syncStateFromNode(node) {
const propertyValue = node.properties?.[STATE_PROPERTY];
const widgetValue = findWidget(node, HIDDEN_INPUT_NAME)?.value;
const source = propertyValue || widgetValue || node._dh3bpState || "";
writeState(node, source);
}
function updateTextareaHeight(textarea) {
textarea.style.height = "auto";
textarea.style.height = `${Math.max(96, textarea.scrollHeight)}px`;
}
function appendDirectiveText(currentText, example) {
const trimmed = String(currentText || "").replace(/\s+$/, "");
if (!trimmed) return example;
if (trimmed.includes(example)) return trimmed;
return `${trimmed}\n${example}`;
}
function splitBeatLines(text) {
return String(text || "").split(/\n/);
}
function readDirectiveValue(text, directiveNames) {
let value = "";
for (const line of splitBeatLines(text)) {
const trimmed = line.trim();
for (const name of directiveNames) {
const lower = name.toLowerCase();
if (trimmed.toLowerCase().startsWith(`${lower}:`)) {
value = trimmed.slice(trimmed.indexOf(":") + 1).trim();
}
}
}
return value;
}
function stripDirectiveValues(text, directiveNames) {
const lowered = directiveNames.map((name) => name.toLowerCase());
const kept = splitBeatLines(text).filter((line) => {
const trimmed = line.trim().toLowerCase();
return !lowered.some((name) => trimmed.startsWith(`${name}:`));
});
return kept.join("\n").replace(/\n{3,}/g, "\n\n").trim();
}
function setDirectiveValue(text, canonicalName, directiveNames, value) {
const cleaned = stripDirectiveValues(text, directiveNames);
const trimmedValue = String(value || "").trim();
if (!trimmedValue) return cleaned;
const directiveLine = `${canonicalName}: ${trimmedValue}`;
return cleaned ? `${directiveLine}\n${cleaned}` : directiveLine;
}
function isInteractiveTarget(target) {
return !!target?.closest?.("textarea, input, select, button, label");
}
function stopCanvasEvent(event) {
if (isInteractiveTarget(event.target)) event.stopPropagation();
}
function stopCanvasKeyboard(event) {
if (isInteractiveTarget(event.target)) event.stopImmediatePropagation();
}
function fitNodeHeight(node) {
const root = node?._dh3bpUI?.root;
if (!root) return;
requestAnimationFrame(() => {
const contentHeight = Math.ceil(root.scrollHeight || 0);
const nextHeight = Math.max(DEFAULT_H, contentHeight + 6);
if (Math.abs((node.size?.[1] || 0) - nextHeight) < 2) return;
node.size[1] = nextHeight;
node.setDirtyCanvas?.(true, true);
});
}
function renderUI(node) {
const ui = node._dh3bpUI;
if (!ui) return;
const state = readState(node);
node._dh3bpRenderedState = JSON.stringify(state);
ui.list.innerHTML = "";
state.beats.forEach((beat, index) => {
const card = document.createElement("div");
card.className = "dh3bp-beat";
const head = document.createElement("div");
head.className = "dh3bp-head";
const label = document.createElement("div");
label.className = "dh3bp-label";
label.textContent = `Beat ${index + 1}`;
const remove = document.createElement("button");
remove.className = "dh3bp-remove";
remove.type = "button";
remove.textContent = "Remove";
remove.disabled = state.beats.length <= 1;
remove.addEventListener("click", () => {
const next = readState(node);
next.beats.splice(index, 1);
writeState(node, next);
renderUI(node);
});
head.append(label, remove);
const textarea = document.createElement("textarea");
textarea.className = "dh3bp-text";
textarea.placeholder = "Describe this beat...";
textarea.value = beat.text || "";
textarea.addEventListener("input", () => {
const next = readState(node);
next.beats[index].text = textarea.value;
writeState(node, next);
updateTextareaHeight(textarea);
});
textarea.addEventListener("keydown", stopCanvasKeyboard);
const applyTextUpdate = (nextText) => {
const next = readState(node);
next.beats[index].text = nextText;
writeState(node, next);
textarea.value = nextText;
updateTextareaHeight(textarea);
};
const controls = document.createElement("div");
controls.className = "dh3bp-controls";
const buildField = ({ labelText, className = "", input }) => {
const wrap = document.createElement("label");
wrap.className = `dh3bp-control ${className}`.trim();
const labelEl = document.createElement("div");
labelEl.className = "dh3bp-control-label";
labelEl.textContent = labelText;
wrap.append(labelEl, input);
return wrap;
};
const secondsInput = document.createElement("input");
secondsInput.className = "dh3bp-input";
secondsInput.type = "text";
secondsInput.placeholder = "8";
secondsInput.value = readDirectiveValue(beat.text, MANAGED_DIRECTIVES.seconds);
secondsInput.addEventListener("input", () => {
applyTextUpdate(setDirectiveValue(textarea.value, "seconds", MANAGED_DIRECTIVES.seconds, secondsInput.value));
});
const continuitySelect = document.createElement("select");
continuitySelect.className = "dh3bp-select";
CONTINUITY_OPTIONS.forEach((value) => {
const option = document.createElement("option");
option.value = value;
option.textContent = value || "Default";
continuitySelect.appendChild(option);
});
continuitySelect.value = readDirectiveValue(beat.text, MANAGED_DIRECTIVES.continuity);
continuitySelect.addEventListener("change", () => {
applyTextUpdate(setDirectiveValue(textarea.value, "continuity", MANAGED_DIRECTIVES.continuity, continuitySelect.value));
});
const refModeSelect = document.createElement("select");
refModeSelect.className = "dh3bp-select";
REF_MODE_OPTIONS.forEach((value) => {
const option = document.createElement("option");
option.value = value;
option.textContent = value || "Global";
refModeSelect.appendChild(option);
});
refModeSelect.value = readDirectiveValue(beat.text, MANAGED_DIRECTIVES.ref_mode);
refModeSelect.addEventListener("change", () => {
applyTextUpdate(setDirectiveValue(textarea.value, "ref_mode", MANAGED_DIRECTIVES.ref_mode, refModeSelect.value));
});
const refNoiseInput = document.createElement("input");
refNoiseInput.className = "dh3bp-input";
refNoiseInput.type = "text";
refNoiseInput.placeholder = "0.95";
refNoiseInput.value = readDirectiveValue(beat.text, MANAGED_DIRECTIVES.ref_noise_aug);
refNoiseInput.addEventListener("input", () => {
applyTextUpdate(setDirectiveValue(textarea.value, "ref_noise_aug", MANAGED_DIRECTIVES.ref_noise_aug, refNoiseInput.value));
});
const anchorInput = document.createElement("input");
anchorInput.className = "dh3bp-input";
anchorInput.type = "text";
anchorInput.placeholder = "extra per-shot style treatment";
anchorInput.value = readDirectiveValue(beat.text, MANAGED_DIRECTIVES.anchor_add);
anchorInput.addEventListener("input", () => {
applyTextUpdate(setDirectiveValue(textarea.value, "anchor_add", MANAGED_DIRECTIVES.anchor_add, anchorInput.value));
});
const soundscapeInput = document.createElement("input");
soundscapeInput.className = "dh3bp-input";
soundscapeInput.type = "text";
soundscapeInput.placeholder = "faint traffic, loose sign rattle";
soundscapeInput.value = readDirectiveValue(beat.text, MANAGED_DIRECTIVES.overall_soundscape);
soundscapeInput.addEventListener("input", () => {
applyTextUpdate(setDirectiveValue(textarea.value, "overall_soundscape", MANAGED_DIRECTIVES.overall_soundscape, soundscapeInput.value));
});
const musicInput = document.createElement("input");
musicInput.className = "dh3bp-input";
musicInput.type = "text";
musicInput.placeholder = "low pulsing synth tension";
musicInput.value = readDirectiveValue(beat.text, MANAGED_DIRECTIVES.non_diegetic_music);
musicInput.addEventListener("input", () => {
applyTextUpdate(setDirectiveValue(textarea.value, "non_diegetic_music", MANAGED_DIRECTIVES.non_diegetic_music, musicInput.value));
});
controls.append(
buildField({ labelText: "Seconds", input: secondsInput }),
buildField({ labelText: "Continuity", input: continuitySelect }),
buildField({ labelText: "Ref Mode", input: refModeSelect }),
buildField({ labelText: "Ref Noise Aug", input: refNoiseInput }),
buildField({ labelText: "Anchor Add", className: "dh3bp-control-wide", input: anchorInput }),
buildField({ labelText: "Shot Soundscape", className: "dh3bp-control-wide", input: soundscapeInput }),
buildField({ labelText: "Shot Music", className: "dh3bp-control-wide", input: musicInput }),
);
const directives = document.createElement("div");
directives.className = "dh3bp-directives";
DIRECTIVE_EXAMPLES.forEach(([labelText, example]) => {
const button = document.createElement("button");
button.className = "dh3bp-directive";
button.type = "button";
button.textContent = labelText;
button.title = example;
button.addEventListener("click", () => {
applyTextUpdate(appendDirectiveText(textarea.value, example));
renderUI(node);
});
directives.appendChild(button);
});
card.append(head, textarea, controls, directives);
ui.list.appendChild(card);
updateTextareaHeight(textarea);
});
fitNodeHeight(node);
node.setDirtyCanvas?.(true, true);
}
function setupNode(node) {
injectCSS();
hideWidget(node, HIDDEN_INPUT_NAME);
const root = document.createElement("div");
root.className = "dh3bp-root";
const toolbar = document.createElement("div");
toolbar.className = "dh3bp-toolbar";
const titleWrap = document.createElement("div");
const title = document.createElement("div");
title.className = "dh3bp-title";
title.textContent = "Beat Prompt Builder";
const subtitle = document.createElement("div");
subtitle.className = "dh3bp-subtitle";
subtitle.textContent = "One textbox per H3 beat, plus per-shot controls for timing, ref behavior, continuity, anchor adds, and audio directives.";
titleWrap.append(title, subtitle);
const addButton = document.createElement("button");
addButton.className = "dh3bp-add";
addButton.type = "button";
addButton.textContent = "+ Add Beat";
addButton.addEventListener("click", () => {
const next = readState(node);
next.beats.push({ text: "" });
writeState(node, next);
renderUI(node);
});
toolbar.append(titleWrap, addButton);
const list = document.createElement("div");
list.className = "dh3bp-list";
root.append(toolbar, list);
root.addEventListener("pointerdown", stopCanvasEvent);
root.addEventListener("mousedown", stopCanvasEvent);
root.addEventListener("click", stopCanvasEvent);
root.addEventListener("dblclick", stopCanvasEvent);
root.addEventListener("keydown", stopCanvasKeyboard, true);
node._dh3bpUI = { root, list };
const widget = node.addDOMWidget("dumas_h3_beat_prompt", "custom", root, {
getValue: () => null,
setValue: () => {},
serialize: false,
getMinHeight: () => 180,
hideOnZoom: false,
});
widget.computeLayoutSize = () => ({ minHeight: DEFAULT_H, minWidth: DEFAULT_W });
applyAdaptiveCanvasOnly(widget);
node.size[0] = Math.max(node.size[0] || 0, DEFAULT_W);
node.size[1] = Math.max(node.size[1] || 0, DEFAULT_H);
syncStateFromNode(node);
renderUI(node);
}
function collectNodes(graph, out) {
if (!graph) return;
const nodes = graph._nodes || graph.nodes || [];
for (const node of nodes) {
if (node?.comfyClass === COMFY_CLASS) out.push(node);
const inner = node?.subgraph || node?.graph || node?._graph;
if (inner && inner !== graph) collectNodes(inner, out);
}
}
function matchNode(nodes, promptId) {
let node = nodes.find((entry) => String(entry.id) === String(promptId));
if (node) return node;
const tail = String(promptId).split(":").pop();
return nodes.find((entry) => String(entry.id) === tail) || null;
}
function injectState(result) {
const output = result?.output;
if (!output) return;
const nodes = [];
collectNodes(app.graph, nodes);
for (const id in output) {
const entry = output[id];
if (!entry || entry.class_type !== COMFY_CLASS) continue;
const node = matchNode(nodes, id);
if (!node) continue;
if (!entry.inputs) entry.inputs = {};
entry.inputs[HIDDEN_INPUT_NAME] = node._dh3bpState || JSON.stringify(defaultState());
}
}
function installGraphToPromptHook() {
if (app._dh3bpGraphPatched) return;
app._dh3bpGraphPatched = true;
const original = app.graphToPrompt.bind(app);
app.graphToPrompt = async function graphToPromptPatched(...args) {
const result = await original(...args);
injectState(result);
return result;
};
}
app.registerExtension({
name: "Dumas.H3BeatPrompt",
setup() {
installGraphToPromptHook();
},
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData?.name !== COMFY_CLASS) return;
const originalNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function onNodeCreated() {
const result = originalNodeCreated?.apply(this, arguments);
setupNode(this);
return result;
};
const originalConfigure = nodeType.prototype.onConfigure;
nodeType.prototype.onConfigure = function onConfigure() {
const result = originalConfigure?.apply(this, arguments);
syncStateFromNode(this);
if (this._dh3bpUI && this._dh3bpRenderedState !== this._dh3bpState) {
queueMicrotask(() => renderUI(this));
}
return result;
};
const originalSerialize = nodeType.prototype.onSerialize;
nodeType.prototype.onSerialize = function onSerialize(o) {
syncStateFromNode(this);
const result = originalSerialize?.apply(this, arguments);
if (o && this.properties?.[STATE_PROPERTY]) {
o.properties = o.properties || {};
o.properties[STATE_PROPERTY] = this.properties[STATE_PROPERTY];
}
return result;
};
const originalDrawForeground = nodeType.prototype.onDrawForeground;
nodeType.prototype.onDrawForeground = function onDrawForeground(ctx) {
const result = originalDrawForeground?.call(this, ctx);
this.size[0] = Math.max(this.size[0], MIN_W);
return result;
};
},
});
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "dumasnodes"
description = "Dumas-branded generic utility nodes for ComfyUI, starting with JSON helpers."
version = "0.1.0"
version = "0.2.0"
license = { file = "LICENSE" }
[project.urls]
-46
View File
@@ -1,46 +0,0 @@
import importlib
import unittest
class DumasH3BeatPromptTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.module = importlib.import_module("dumas_h3_beat_prompt")
def test_parse_state_falls_back_to_default(self):
state = self.module._parse_beat_prompt_state("not json")
self.assertEqual(
state,
{"beats": [{"text": "Describe this beat."}]},
)
def test_assemble_prompt_joins_beats_with_blank_lines(self):
prompt = self.module._assemble_beat_prompt(
{
"beats": [
{"text": "A woman enters the room."},
{"text": "wardrobe: Maya = red jacket\nShe sits at the table."},
{"text": " "},
{"text": "music: low synth pulse"},
]
}
)
self.assertEqual(
prompt,
(
"A woman enters the room.\n\n"
"wardrobe: Maya = red jacket\nShe sits at the table.\n\n"
"music: low synth pulse"
),
)
def test_node_build_prompt_uses_hidden_state(self):
node = self.module.DumasH3BeatPromptNode()
result = node.build_prompt(
'{"beats":[{"text":"Beat one"},{"text":"Beat two"}]}'
)
self.assertEqual(result, ("Beat one\n\nBeat two",))
if __name__ == "__main__":
unittest.main()
-825
View File
@@ -1,825 +0,0 @@
import importlib
import inspect
import sys
import types
import unittest
class DumasH3LongVideosHelperTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._saved_modules = {
name: sys.modules.get(name)
for name in (
"torch",
"nodes",
"comfy",
"comfy.utils",
"comfy.samplers",
"comfy.nested_tensor",
"comfy.model_management",
"node_helpers",
"numpy",
"PIL",
"PIL.Image",
"folder_paths",
"dumas_image_nodes",
"dumas_h3_longvideos",
)
}
fake_torch = types.SimpleNamespace(
cuda=types.SimpleNamespace(OutOfMemoryError=RuntimeError),
float32="float32",
)
fake_numpy = types.SimpleNamespace(
clip=lambda array, _low, _high: array,
uint8="uint8",
)
fake_pil_image_module = types.SimpleNamespace(fromarray=lambda _array: None)
fake_pil_module = types.SimpleNamespace(Image=fake_pil_image_module)
fake_folder_paths = types.SimpleNamespace(
get_temp_directory=lambda: "/tmp",
get_output_directory=lambda: "/tmp",
get_save_image_path=lambda prefix, _out, _width, _height: ("/tmp", prefix, 1, "", prefix),
)
fake_nodes = types.SimpleNamespace(common_ksampler=lambda *args, **kwargs: ({},))
fake_comfy_samplers = types.SimpleNamespace(
KSampler=types.SimpleNamespace(SAMPLERS=("res_multistep",), SCHEDULERS=("simple",))
)
fake_comfy_utils = types.SimpleNamespace(ProgressBar=lambda total: None)
fake_mm = types.SimpleNamespace(
current_loaded_models=[],
free_memory=lambda *args, **kwargs: None,
get_torch_device=lambda: "cpu",
soft_empty_cache=lambda *args, **kwargs: None,
unload_all_models=lambda *args, **kwargs: None,
get_free_memory=lambda *args, **kwargs: 0,
get_total_memory=lambda *args, **kwargs: 0,
)
fake_comfy = types.SimpleNamespace(
utils=fake_comfy_utils,
samplers=fake_comfy_samplers,
nested_tensor=types.SimpleNamespace(),
model_management=fake_mm,
)
sys.modules["torch"] = fake_torch
sys.modules["numpy"] = fake_numpy
sys.modules["PIL"] = fake_pil_module
sys.modules["PIL.Image"] = fake_pil_image_module
sys.modules["folder_paths"] = fake_folder_paths
sys.modules["nodes"] = fake_nodes
sys.modules["comfy"] = fake_comfy
sys.modules["comfy.utils"] = fake_comfy_utils
sys.modules["comfy.samplers"] = fake_comfy_samplers
sys.modules["comfy.nested_tensor"] = fake_comfy.nested_tensor
sys.modules["comfy.model_management"] = fake_mm
sys.modules["node_helpers"] = types.SimpleNamespace()
cls.image_module = importlib.import_module("dumas_image_nodes")
cls.module = importlib.import_module("dumas_h3_longvideos")
@classmethod
def tearDownClass(cls):
for name, module in cls._saved_modules.items():
if module is None:
sys.modules.pop(name, None)
else:
sys.modules[name] = module
def test_extract_wardrobe_is_cached(self):
fn = self.module.extract_wardrobe
fn.cache_clear()
beat = "walks forward\nwardrobe: red jacket, grey shorts\nlooks back"
self.assertEqual(fn(beat), ("walks forward\nlooks back", "red jacket, grey shorts"))
self.assertEqual(fn(beat), ("walks forward\nlooks back", "red jacket, grey shorts"))
self.assertGreater(fn.cache_info().hits, 0)
def test_dialogue_helpers_keep_existing_outputs_and_cache(self):
spans_cache = self.module._dialogue_spans_cached
sec_fn = self.module.dialogue_seconds
words_fn = self.module.dialogue_words
spans_cache.cache_clear()
sec_fn.cache_clear()
words_fn.cache_clear()
beat = 'Mara says, "Open it now." Jon replies, "Do it."'
self.assertEqual(self.module.dialogue_spans(beat), [3, 2])
self.assertEqual(words_fn(beat), 5)
self.assertAlmostEqual(sec_fn(beat), 3.5)
self.assertAlmostEqual(sec_fn(beat, pad=False), 2.5)
self.module.dialogue_spans(beat)
sec_fn(beat)
words_fn(beat)
self.assertGreater(spans_cache.cache_info().hits, 0)
self.assertGreater(sec_fn.cache_info().hits, 0)
self.assertGreater(words_fn.cache_info().hits, 0)
def test_directive_and_estimate_helpers_are_cached(self):
directive_fn = self.module.beat_seconds_directive
estimate_fn = self.module.estimate_beat_seconds
action_fn = self.module.action_clauses
directive_fn.cache_clear()
estimate_fn.cache_clear()
action_fn.cache_clear()
beat = 'seconds: 7.5\nShe opens the hatch and climbs inside.'
self.assertEqual(directive_fn(beat), 7.5)
self.assertEqual(action_fn(beat), 2)
self.assertAlmostEqual(estimate_fn(beat), 7.0)
directive_fn(beat)
action_fn(beat)
estimate_fn(beat)
self.assertGreater(directive_fn.cache_info().hits, 0)
self.assertGreater(action_fn.cache_info().hits, 0)
self.assertGreater(estimate_fn.cache_info().hits, 0)
def test_per_shot_directive_helpers_parse_new_controls(self):
beat = (
"ref_mode: every shot + handoff ref\n"
"ref_noise_aug: 0.87\n"
"continuity: keyframe carry\n"
"The courier waits under the sign."
)
self.assertEqual(
self.module.beat_ref_mode_directive(beat),
"every shot + handoff ref",
)
self.assertEqual(self.module.beat_ref_noise_aug_directive(beat), 0.87)
self.assertEqual(
self.module.beat_continuity_directive(beat),
"keyframe carry",
)
def test_detail_pass_refines_video_but_preserves_audio(self):
class FakeTensor:
def __init__(self, name):
self.name = name
def detach(self):
return self
def to(self, *args, **kwargs):
return self
class FakeNestedTensor:
def __init__(self, parts):
self._parts = tuple(parts)
self.is_nested = True
def unbind(self):
return self._parts
calls = []
first_out = {"samples": FakeNestedTensor((FakeTensor("v1"), FakeTensor("a1")))}
second_out = {"samples": FakeNestedTensor((FakeTensor("v2"), FakeTensor("a2")))}
original_common_ksampler = self.module.nodes.common_ksampler
original_build = self.module._build_shot_conditioning
original_evict = self.module._evict_all_but
original_decode_video = self.module._decode_video
original_decode_audio = self.module._decode_audio
original_cleanup = self.module._deep_cleanup
original_nested = getattr(self.module.comfy.nested_tensor, "NestedTensor", None)
try:
self.module.comfy.nested_tensor.NestedTensor = FakeNestedTensor
def common_ksampler(*args, **kwargs):
calls.append((args, kwargs))
return (first_out if len(calls) == 1 else second_out,)
self.module.nodes.common_ksampler = common_ksampler
self.module._build_shot_conditioning = lambda *_args, **_kwargs: (
"cond",
{"samples": FakeNestedTensor((FakeTensor("basev"), FakeTensor("basea")))},
)
self.module._evict_all_but = lambda *_args, **_kwargs: None
self.module._decode_video = lambda _vae, out_latent, *_args, **_kwargs: out_latent
self.module._decode_audio = lambda _vae, out_latent: out_latent
self.module._deep_cleanup = lambda: None
result = self.module.H3LongVideos()._render(
model=object(),
clip=types.SimpleNamespace(
tokenize=lambda text, **kwargs: text,
encode_from_tokens_scheduled=lambda tokens: tokens,
),
vae=object(),
audio_vae=object(),
negative="negative",
prompt="beat",
w=128,
h=64,
ln=24,
fps=24,
tiled=False,
sa=(123, 20, 1.0, "res_multistep", "simple", 1.0),
handoff=None,
detail_pass=True,
detail_sampler_name="euler",
detail_scheduler="beta",
detail_steps=5,
detail_denoise=0.4,
)
self.assertEqual(len(calls), 2)
self.assertIsNot(calls[1][0][8], first_out)
self.assertIs(calls[1][0][8]["samples"], first_out["samples"])
self.assertEqual(calls[1][0][4], "euler")
self.assertEqual(calls[1][0][5], "beta")
self.assertAlmostEqual(calls[1][1]["denoise"], 0.4)
self.assertEqual(result[1], first_out)
self.assertEqual(result[2][0].name, "v2")
self.assertEqual(result[2][1].name, "a1")
self.assertEqual(result[0]["samples"].unbind()[0].name, "v2")
self.assertEqual(result[0]["samples"].unbind()[-1].name, "a1")
finally:
self.module.nodes.common_ksampler = original_common_ksampler
self.module._build_shot_conditioning = original_build
self.module._evict_all_but = original_evict
self.module._decode_video = original_decode_video
self.module._decode_audio = original_decode_audio
self.module._deep_cleanup = original_cleanup
if original_nested is None:
delattr(self.module.comfy.nested_tensor, "NestedTensor")
else:
self.module.comfy.nested_tensor.NestedTensor = original_nested
def test_detail_pass_treats_falsey_strings_as_disabled(self):
calls = []
original_common_ksampler = self.module.nodes.common_ksampler
original_build = self.module._build_shot_conditioning
original_evict = self.module._evict_all_but
original_decode_video = self.module._decode_video
original_decode_audio = self.module._decode_audio
original_cleanup = self.module._deep_cleanup
try:
self.module.nodes.common_ksampler = lambda *args, **kwargs: (calls.append((args, kwargs)) or {"samples": "latent"},)
self.module._build_shot_conditioning = lambda *_args, **_kwargs: ("cond", {"samples": "base"})
self.module._evict_all_but = lambda *_args, **_kwargs: None
self.module._decode_video = lambda _vae, out_latent, *_args, **_kwargs: out_latent
self.module._decode_audio = lambda _vae, out_latent: out_latent
self.module._deep_cleanup = lambda: None
self.module.H3LongVideos()._render(
model=object(),
clip=object(),
vae=object(),
audio_vae=object(),
negative="negative",
prompt="beat",
w=128,
h=64,
ln=24,
fps=24,
tiled=False,
sa=(123, 20, 1.0, "res_multistep", "simple", 1.0),
handoff=None,
detail_pass="false",
)
self.assertEqual(len(calls), 1)
finally:
self.module.nodes.common_ksampler = original_common_ksampler
self.module._build_shot_conditioning = original_build
self.module._evict_all_but = original_evict
self.module._decode_video = original_decode_video
self.module._decode_audio = original_decode_audio
self.module._deep_cleanup = original_cleanup
def test_distribute_generations_canonicalizes_per_shot_audio_and_anchor_directives(self):
generations = self.module.distribute_generations(
"",
[
"anchor_add: harsh sodium spill, wet asphalt reflections\n"
"soundscape: distant traffic hiss, loose sign rattle\n"
"music: low pulsing synth tension\n"
"continuity: hard cut\n"
"ref_mode: every shot\n"
"ref_noise_aug: 0.88\n"
"A courier waits under the streetlight."
],
"global rain",
"global score",
)
block = generations[0]
self.assertIn("harsh sodium spill, wet asphalt reflections", block)
self.assertIn("overall_soundscape: distant traffic hiss, loose sign rattle", block)
self.assertIn("non_diegetic_music: low pulsing synth tension", block)
self.assertNotIn("\nsoundscape:", block)
self.assertNotIn("\nmusic:", block)
self.assertNotIn("\ncontinuity:", block)
self.assertNotIn("\nref_mode:", block)
self.assertNotIn("\nref_noise_aug:", block)
self.assertNotIn("\nanchor_add:", block)
def test_has_speech_cache_respects_written_text_filter(self):
fn = self.module.has_speech
fn.cache_clear()
written = 'She reads the sign marked "EXIT" and keeps walking.'
spoken = 'She says, "Exit now." and points to the door.'
self.assertFalse(fn(written))
self.assertTrue(fn(spoken))
fn(written)
fn(spoken)
self.assertGreaterEqual(fn.cache_info().hits, 2)
def test_resolve_tagged_refs_preserves_sparse_socket_numbers(self):
refs = [
None,
{"kind": "character", "image": "img2", "name": "Jon"},
None,
None,
None,
None,
{"kind": "character", "image": "img7", "name": "Mara"},
None,
{"kind": "location", "image": "img9", "name": "Watchtower"},
]
text, references, dropped = self.module.resolve_tagged_refs(
"Mara <Picture 7> turns toward Jon <Picture 2> while <Picture 9> watches.",
refs,
)
self.assertEqual(
text,
"Mara <Picture 2> turns toward Jon <Picture 1> while <Picture 3> watches.",
)
self.assertEqual(
[self.module._reference_image(ref) for ref in references],
["img2", "img7", "img9"],
)
self.assertEqual(dropped, [])
def test_resolve_tagged_refs_drops_unconnected_sparse_slots(self):
refs = [
None,
{"kind": "character", "image": "img2", "name": "Jon"},
None,
None,
None,
None,
{"kind": "character", "image": "img7", "name": "Mara"},
None,
None,
]
text, references, dropped = self.module.resolve_tagged_refs(
"Use <Picture 7>, skip <Picture 4>, keep <Picture 2>.",
refs,
)
self.assertEqual(text, "Use <Picture 2>, skip, keep <Picture 1>.")
self.assertEqual(
[self.module._reference_image(ref) for ref in references],
["img2", "img7"],
)
self.assertEqual(dropped, [4])
def test_resolve_prompt_refs_keeps_named_character_images_alongside_tagged_location(self):
refs = [
{"kind": "character", "image": "img1", "name": "Mara"},
{"kind": "character", "image": "img2", "name": "Jon"},
{"kind": "location", "image": "img3", "name": "Hangar"},
]
text, references, dropped = self.module.resolve_prompt_refs(
"Mara and Jon argue inside <Picture 3>.",
refs,
)
self.assertEqual(text, "Mara and Jon argue inside <Picture 1>.")
self.assertEqual(
[self.module._reference_image(ref) for ref in references],
["img3", "img1", "img2"],
)
self.assertEqual(dropped, [])
def test_shot_references_uses_all_connected_sparse_slots(self):
refs = [
None,
{"kind": "character", "image": "img2"},
None,
{"kind": "character", "image": "img4"},
None,
None,
{"kind": "location", "image": "img7"},
None,
None,
]
for mode, shot_index in (("auto ref2v", 0), ("first shot", 0), ("every shot", 3)):
self.assertEqual(
[self.module._reference_image(ref) for ref in self.module.shot_references(refs, mode, shot_index, None)],
["img2", "img4", "img7"],
)
def test_input_types_expose_nine_ref_slots(self):
optional = self.module.H3LongVideos.INPUT_TYPES()["optional"]
for index in range(1, 10):
self.assertIn(f"ref_{index}", optional)
def test_input_types_keep_legacy_ref_image_aliases(self):
optional = self.module.H3LongVideos.INPUT_TYPES()["optional"]
for index in range(1, 10):
self.assertIn(f"ref_image_{index}", optional)
def test_run_defaults_match_declared_ref_widget_defaults(self):
node = self.module.H3LongVideos()
optional = node.INPUT_TYPES()["optional"]
params = inspect.signature(node.run).parameters
self.assertEqual(params["ref_mode"].default, optional["ref_mode"][1]["default"])
self.assertEqual(params["ref_image_size"].default, optional["ref_image_size"][1]["default"])
self.assertEqual(params["ref_noise_aug"].default, optional["ref_noise_aug"][1]["default"])
def test_node_appends_per_beat_list_outputs_without_reordering_existing_slots(self):
self.assertEqual(
self.module.H3LongVideos.RETURN_NAMES[-2:],
("beat_images", "beat_audio"),
)
self.assertEqual(
self.module.H3LongVideos.OUTPUT_IS_LIST[-2:],
(True, True),
)
def test_reference_context_matches_character_names_and_location_tags(self):
refs = [
{
"kind": "character",
"image": "img1",
"name": "Mara",
"aliases": ["Xtina"],
"description": "silver hair",
"wardrobe": "red jacket",
"general": "wears a long grey coat",
"facts": {
"gender": "female",
"age": "41",
"nationality": "English",
"occupation": "a detective",
"height_feet": "6",
"height_inches": "2",
"accent": "English",
},
},
{"kind": "location", "image": "img2", "name": "Hangar", "description": "wet concrete floor"},
]
context = self.module._reference_context_for_text(
"[Generation 1] Mara crosses the room toward <Picture 2>.",
refs,
)
self.assertIn("Character facts for Mara:", context)
self.assertIn("also known as Xtina", context)
self.assertIn("female", context)
self.assertIn("41 years old", context)
self.assertIn("English", context)
self.assertIn("works as a detective", context)
self.assertIn("6 foot 2 tall", context)
self.assertIn("speaks with a English accent", context)
self.assertIn("Persistent appearance for Mara: silver hair.", context)
self.assertIn("Persistent wardrobe/style for Mara: red jacket.", context)
self.assertIn("Character notes for Mara: wears a long grey coat.", context)
def test_run_uses_legacy_ref_image_inputs_when_new_slots_are_empty(self):
calls = {}
original_parse_resolution = self.module.parse_resolution
original_connected_refs = self.module._connected_refs
original_reference_character_memory = self.module._reference_character_memory
original_vram_gb = self.module.vram_gb
original_dit_resident_gb = self.module.dit_resident_gb
original_lora_overhead_gb = self.module.lora_overhead_gb
original_resolve_shot_frames = self.module.resolve_shot_frames
original_lora_active = self.module.lora_active
original_sla_pairing = self.module.sla_pairing
original_apply_h3_model_sampling = self.module.apply_h3_model_sampling
original_split_paragraphs = self.module.split_paragraphs
original_expand_beats = self.module.expand_beats
original_anchor_warnings = self.module.anchor_warnings
original_anchor_contributes_nothing = self.module.anchor_contributes_nothing
original_anchor_is_action_beat = self.module.anchor_is_action_beat
original_distribute_generations = self.module.distribute_generations
original_continuity_warnings = self.module.continuity_warnings
original_speech_flags = self.module.speech_flags
original_annotate_script_debug = self.module.annotate_script_debug
original_empty_av_latent = self.module._empty_av_latent
original_torch_zeros = getattr(self.module.torch, "zeros", None)
try:
self.module.torch.zeros = lambda shape: shape
self.module.parse_resolution = lambda _resolution: (640, 360)
self.module._connected_refs = lambda refs: [ref for ref in refs if ref is not None]
self.module._reference_character_memory = lambda refs: (calls.setdefault("refs", tuple(refs)), "")[1]
self.module.vram_gb = lambda: (0, 0)
self.module.dit_resident_gb = lambda _model: 0
self.module.lora_overhead_gb = lambda _model: 0
self.module.resolve_shot_frames = lambda *args, **kwargs: (53, "")
self.module.lora_active = lambda _model: False
self.module.sla_pairing = lambda *_args, **_kwargs: ("", False, "")
self.module.apply_h3_model_sampling = lambda model, *_args: (model, "")
self.module.split_paragraphs = lambda _prompt, _sep: ["Anchor.", "Beat."]
self.module.expand_beats = lambda beat_paras, _split: (list(beat_paras), "")
self.module.anchor_warnings = lambda _anchor: []
self.module.anchor_contributes_nothing = lambda *_args, **_kwargs: False
self.module.anchor_is_action_beat = lambda *_args, **_kwargs: False
self.module.distribute_generations = lambda _anchor, beats, *_args, **_kwargs: list(beats)
self.module.continuity_warnings = lambda _gens: []
self.module.speech_flags = lambda _beats: []
self.module.annotate_script_debug = lambda *_args, **_kwargs: "script"
self.module._empty_av_latent = lambda *_args, **_kwargs: ({"samples": "latent"}, 5)
clip = types.SimpleNamespace(
tokenize=lambda text, **kwargs: text,
encode_from_tokens_scheduled=lambda tokens: tokens,
)
result = self.module.H3LongVideos().run(
model=object(),
clip=clip,
vae=object(),
audio_vae=object(),
prompt="Anchor only.",
resolution="16:9",
steps=6,
cfg=1,
sampler_name="res_multistep",
scheduler="simple",
seed=1,
plan_only=True,
ref_image_1={"image": "legacy-1"},
ref_image_3={"image": "legacy-3"},
)
self.assertEqual(calls["refs"][0]["image"], "legacy-1")
self.assertIsNone(calls["refs"][1])
self.assertEqual(calls["refs"][2]["image"], "legacy-3")
self.assertEqual(result[2].count("ref2va: 2 reference image(s)"), 1)
finally:
self.module.parse_resolution = original_parse_resolution
self.module._connected_refs = original_connected_refs
self.module._reference_character_memory = original_reference_character_memory
self.module.vram_gb = original_vram_gb
self.module.dit_resident_gb = original_dit_resident_gb
self.module.lora_overhead_gb = original_lora_overhead_gb
self.module.resolve_shot_frames = original_resolve_shot_frames
self.module.lora_active = original_lora_active
self.module.sla_pairing = original_sla_pairing
self.module.apply_h3_model_sampling = original_apply_h3_model_sampling
self.module.split_paragraphs = original_split_paragraphs
self.module.expand_beats = original_expand_beats
self.module.anchor_warnings = original_anchor_warnings
self.module.anchor_contributes_nothing = original_anchor_contributes_nothing
self.module.anchor_is_action_beat = original_anchor_is_action_beat
self.module.distribute_generations = original_distribute_generations
self.module.continuity_warnings = original_continuity_warnings
self.module.speech_flags = original_speech_flags
self.module.annotate_script_debug = original_annotate_script_debug
self.module._empty_av_latent = original_empty_av_latent
if original_torch_zeros is None:
delattr(self.module.torch, "zeros")
else:
self.module.torch.zeros = original_torch_zeros
def test_reference_context_matches_tagged_character_without_name_in_text(self):
refs = [
{"kind": "character", "image": "img1", "name": "Mara", "description": "silver hair", "wardrobe": "red jacket"},
]
context = self.module._reference_context_for_text(
"[Generation 1] <Picture 1> walks into the room.",
refs,
)
self.assertIn("Persistent appearance for Mara: silver hair.", context)
self.assertIn("Persistent wardrobe/style for Mara: red jacket.", context)
def test_reference_context_injects_immediately_after_generation_label(self):
block = (
"[Generation 1] Classic sitcom lighting and staging. "
"Duke walks into the room."
)
context = "Character facts for Duke: female, 25 years old."
result = self.module._inject_reference_context(block, context)
self.assertEqual(
result,
"[Generation 1] Character facts for Duke: female, 25 years old. "
"Classic sitcom lighting and staging. "
"Duke walks into the room.",
)
def test_reference_character_memory_uses_character_wardrobe_only(self):
refs = [
{"kind": "character", "image": "img1", "name": "Mara", "wardrobe": "red jacket, black boots"},
{"kind": "location", "image": "img2", "name": "Hangar", "description": "wet concrete floor", "wardrobe": "should be ignored"},
]
self.assertEqual(
self.module._reference_character_memory(refs),
"Mara = red jacket, black boots",
)
def test_ref_mode_defaults_are_ref2v_biased(self):
optional = self.module.H3LongVideos.INPUT_TYPES()["optional"]
self.assertEqual(optional["ref_mode"][1]["default"], "auto ref2v")
self.assertEqual(optional["ref_noise_aug"][1]["default"], 0.95)
def test_only_canonical_h3_long_videos_node_is_exposed(self):
self.assertEqual(
self.module.NODE_CLASS_MAPPINGS,
{"DumasH3LongVideos": self.module.H3LongVideos},
)
self.assertEqual(
self.module.NODE_DISPLAY_NAME_MAPPINGS,
{"DumasH3LongVideos": "Dumas H3 Long Videos (FL2VA + REF2VA)"},
)
def test_compose_persistent_does_not_expand_ambiguous_plural_to_full_cast(self):
active = self.module.parse_wardrobe(
"Maya = she, red jacket\n"
"Jon = he, navy overalls\n"
"Becca = she, green coat"
)
shot = self.module.compose_persistent(
"Both of them walk to the door.",
active,
"",
speaking=False,
)
self.assertEqual(shot, "Both of them walk to the door.")
def test_compose_persistent_keeps_two_person_plural_binding(self):
active = self.module.parse_wardrobe(
"Maya = she, red jacket\n"
"Jon = he, navy overalls"
)
shot = self.module.compose_persistent(
"They walk to the door.",
active,
"",
speaking=False,
)
self.assertIn("Maya (red jacket)", shot)
self.assertIn("Jon (navy overalls)", shot)
self.assertIn("They walk to the door.", shot)
def test_compose_persistent_all_three_characters_binds_full_cast(self):
active = self.module.parse_wardrobe(
"Maya = she, red jacket\n"
"Jon = he, navy overalls\n"
"Becca = she, green coat"
)
shot = self.module.compose_persistent(
"The three characters walk to the door.",
active,
"",
speaking=False,
)
self.assertIn("Maya (red jacket)", shot)
self.assertIn("Jon (navy overalls)", shot)
self.assertIn("Becca (green coat)", shot)
def test_plan_only_returns_joined_generations_on_script_socket_with_anchor_override(self):
module = self.module
node = module.H3LongVideos()
class _Clip:
def tokenize(self, text):
return text
def encode_from_tokens_scheduled(self, tokens):
return tokens
class _TorchStub:
@staticmethod
def zeros(shape):
return ("zeros", shape)
original_torch = module.torch
original_vram_gb = module.vram_gb
original_dit_resident_gb = module.dit_resident_gb
original_lora_overhead_gb = module.lora_overhead_gb
original_check_vae_wiring = module.check_vae_wiring
original_check_text_encoder = module.check_text_encoder
original_apply_h3_model_sampling = module.apply_h3_model_sampling
original_sla_pairing = module.sla_pairing
original_lora_hint_notes = module.lora_hint_notes
original_schedule_balance_note = module.schedule_balance_note
original_kernel_backend_note = module.kernel_backend_note
original_audio_scale_note = module.audio_scale_note
original_quant_accel_note = module.quant_accel_note
original_lora_active = module.lora_active
original_resolve_shot_frames = module.resolve_shot_frames
original_plan_beat_frames = module.plan_beat_frames
original_dialogue_fit_warnings = module.dialogue_fit_warnings
original_dialogue_filler_warnings = module.dialogue_filler_warnings
original_distribute_generations = module.distribute_generations
original_continuity_warnings = module.continuity_warnings
original_empty_av_latent = module._empty_av_latent
try:
module.torch = _TorchStub()
module.vram_gb = lambda: (0.0, 0.0)
module.dit_resident_gb = lambda _model: 0.0
module.lora_overhead_gb = lambda _model: 0.0
module.check_vae_wiring = lambda *_args, **_kwargs: None
module.check_text_encoder = lambda *_args, **_kwargs: None
module.apply_h3_model_sampling = lambda model, *_args, **_kwargs: (model, "")
module.sla_pairing = lambda *_args, **_kwargs: ("", False, "")
module.lora_hint_notes = lambda *_args, **_kwargs: []
module.schedule_balance_note = lambda *_args, **_kwargs: ""
module.kernel_backend_note = lambda *_args, **_kwargs: ""
module.audio_scale_note = lambda *_args, **_kwargs: ""
module.quant_accel_note = lambda *_args, **_kwargs: ""
module.lora_active = lambda _model: False
module.resolve_shot_frames = lambda *_args, **_kwargs: (73, "")
module.plan_beat_frames = lambda beats, fps, budget, per_beat=True: ([73] * len(beats), [])
module.dialogue_fit_warnings = lambda *_args, **_kwargs: []
module.dialogue_filler_warnings = lambda *_args, **_kwargs: []
module.distribute_generations = lambda anchor, beats, *_args, **_kwargs: [
f"[Generation 1] {anchor}. {beats[0]}",
f"[Generation 2] {anchor}. {beats[1]}{module.ANATOMY_STATE}",
]
module.continuity_warnings = lambda _gens: []
module._empty_av_latent = lambda *_args, **_kwargs: ({"samples": "latent"},)
result = node.run(
model=object(),
clip=_Clip(),
vae=object(),
audio_vae=object(),
prompt="Francine stands alone.\n\nFrancine and Frankie walk together.",
resolution="16:9",
steps=20,
cfg=1.0,
sampler_name="res_multistep",
scheduler="simple",
seed=1,
anchor_override="editorial room, soft practical lighting",
character_memory="Francine = white top\nFrankie = black jacket",
plan_only=True,
)
self.assertIn("# anatomy_guard: injected on shot(s) 2", result[3])
self.assertIn("# shot 1 refs: none", result[3])
self.assertIn("# shot 2 refs: none", result[3])
self.assertIn(
"[Generation 1] editorial room, soft practical lighting. Francine stands alone.",
result[3],
)
self.assertIn(
"[Generation 2] editorial room, soft practical lighting. Francine and Frankie walk together.",
result[3],
)
self.assertIn("2 beat(s)", result[2])
self.assertIn("2 shot(s)", result[2])
self.assertIn("ANATOMY -- guard injected on shot(s) 2", result[2])
self.assertEqual(result[-2:], ([], []))
finally:
module.torch = original_torch
module.vram_gb = original_vram_gb
module.dit_resident_gb = original_dit_resident_gb
module.lora_overhead_gb = original_lora_overhead_gb
module.check_vae_wiring = original_check_vae_wiring
module.check_text_encoder = original_check_text_encoder
module.apply_h3_model_sampling = original_apply_h3_model_sampling
module.sla_pairing = original_sla_pairing
module.lora_hint_notes = original_lora_hint_notes
module.schedule_balance_note = original_schedule_balance_note
module.kernel_backend_note = original_kernel_backend_note
module.audio_scale_note = original_audio_scale_note
module.quant_accel_note = original_quant_accel_note
module.lora_active = original_lora_active
module.resolve_shot_frames = original_resolve_shot_frames
module.plan_beat_frames = original_plan_beat_frames
module.dialogue_fit_warnings = original_dialogue_fit_warnings
module.dialogue_filler_warnings = original_dialogue_filler_warnings
module.distribute_generations = original_distribute_generations
module.continuity_warnings = original_continuity_warnings
module._empty_av_latent = original_empty_av_latent
if __name__ == "__main__":
unittest.main()
+28 -655
View File
@@ -1,50 +1,12 @@
import importlib
import json
import os
import sys
import tempfile
import time
import types
import unittest
from unittest import mock
class FakeImageArray:
def __init__(self, width=8, height=6):
self.shape = (height, width, 3)
def cpu(self):
return self
def numpy(self):
return self
def astype(self, _dtype):
return self
def __rmul__(self, _value):
return self
class FakeTensorBatch:
def __init__(self, width=8, height=6, count=1):
self.image = FakeImageArray(width=width, height=height)
self.shape = (count, height, width, 3)
self.count = count
def __getitem__(self, index):
if isinstance(index, slice):
return FakeTensorBatch(
width=self.shape[2],
height=self.shape[1],
count=len(range(*index.indices(self.count))),
)
if index != 0:
raise IndexError(index)
return self.image
class FakePILImage:
class FakeImage:
saved_paths = []
def save(self, path, *args, **kwargs):
@@ -54,646 +16,57 @@ class FakePILImage:
return self
class FakeBatch:
shape = (1, 6, 8, 3)
def __getitem__(self, _index):
return types.SimpleNamespace(cpu=lambda: self, numpy=lambda: self, astype=lambda _dtype: self)
class DumasImageNodeTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.temp_dir = tempfile.mkdtemp(prefix="dumas-image-node-")
fake_numpy = types.SimpleNamespace(
clip=lambda array, _low, _high: array,
uint8="uint8",
)
fake_pil_image_module = types.SimpleNamespace(fromarray=lambda _array: FakePILImage())
fake_pil_module = types.SimpleNamespace(Image=fake_pil_image_module)
fake_numpy = types.SimpleNamespace(clip=lambda array, _low, _high: array, uint8="uint8")
fake_pil_image = types.SimpleNamespace(fromarray=lambda _array: FakeImage())
fake_pil = types.SimpleNamespace(Image=fake_pil_image)
fake_folder_paths = types.SimpleNamespace(
get_temp_directory=lambda: cls.temp_dir,
get_output_directory=lambda: cls.temp_dir,
get_save_image_path=lambda prefix, _out, _width, _height: (
cls.temp_dir,
prefix,
1,
"",
prefix,
),
get_save_image_path=lambda prefix, _out, _width, _height: (cls.temp_dir, prefix, 1, "", prefix),
)
cls._saved_modules = {
name: sys.modules.get(name)
for name in ("numpy", "PIL", "PIL.Image", "folder_paths")
}
cls.saved = {name: sys.modules.get(name) for name in ("numpy", "PIL", "PIL.Image", "folder_paths")}
sys.modules["numpy"] = fake_numpy
sys.modules["PIL"] = fake_pil_module
sys.modules["PIL.Image"] = fake_pil_image_module
sys.modules["PIL"] = fake_pil
sys.modules["PIL.Image"] = fake_pil_image
sys.modules["folder_paths"] = fake_folder_paths
cls.image_nodes = importlib.import_module("dumas_image_nodes")
cls.nodes = importlib.import_module("dumas_image_nodes")
@classmethod
def tearDownClass(cls):
for name, module in cls._saved_modules.items():
for name, module in cls.saved.items():
if module is None:
sys.modules.pop(name, None)
else:
sys.modules[name] = module
def setUp(self):
FakePILImage.saved_paths = []
def test_compare_images_returns_second_input_as_new_image(self):
node = self.image_nodes.DumasImageCompareNode()
image1 = FakeTensorBatch()
image2 = FakeTensorBatch()
result = node.compare_images(image1=image1, image2=image2)
self.assertIs(result["result"][0], image2)
self.assertEqual([item["slot"] for item in result["ui"]["images"]], [1, 2])
self.assertEqual(len(FakePILImage.saved_paths), 2)
def test_compare_images_falls_back_to_first_image(self):
node = self.image_nodes.DumasImageCompareNode()
image1 = FakeTensorBatch()
result = node.compare_images(image1=image1)
self.assertIs(result["result"][0], image1)
self.assertEqual([item["slot"] for item in result["ui"]["images"]], [1])
def test_compare_images_handles_missing_inputs(self):
node = self.image_nodes.DumasImageCompareNode()
result = node.compare_images()
def test_generic_image_nodes_are_registered(self):
self.assertEqual(
set(self.nodes.NODE_CLASS_MAPPINGS),
{"DumasImageCompare", "DumasSaveImage", "DumasLoadImagesFolder"},
)
def test_compare_without_inputs_returns_empty_result(self):
result = self.nodes.DumasImageCompareNode().compare_images()
self.assertEqual(result["ui"]["images"], [])
self.assertIsNone(result["result"][0])
self.assertEqual(result["ui"]["images"], [])
def test_saved_filenames_use_dumas_prefix(self):
node = self.image_nodes.DumasImageCompareNode()
image1 = FakeTensorBatch()
result = node.compare_images(image1=image1)
self.assertTrue(result["ui"]["images"][0]["filename"].startswith("dumas_compare"))
self.assertTrue(os.path.basename(FakePILImage.saved_paths[0][0]).startswith("dumas_compare"))
def test_save_image_uses_second_input_token(self):
node = self.image_nodes.DumasSaveImageNode()
image = FakeTensorBatch(width=10, height=12)
node.save_images(
images=image,
folder=self.temp_dir,
pattern="shot_%input%_%input2%_%counter%",
format="png",
quality=100,
embed_workflow=False,
save_on_run=True,
name="alpha.png",
name_2="beta/final",
)
saved_name = os.path.basename(FakePILImage.saved_paths[0][0])
self.assertEqual(saved_name, "shot_alpha_beta_final_001.png")
def test_save_image_resolves_date_size_and_batch_tokens(self):
node = self.image_nodes.DumasSaveImageNode()
image = FakeTensorBatch(width=10, height=12, count=2)
fake_now = time.struct_time((2026, 8, 5, 13, 7, 9, 2, 217, -1))
with mock.patch.object(self.image_nodes.time, "localtime", return_value=fake_now):
node.save_images(
images=image,
folder=self.temp_dir,
pattern="asset_%date:yyyy-MM-dd%_%date:hh-mm-ss%_%width%x%height%_%batch_num%_%counter%",
format="png",
quality=100,
embed_workflow=False,
save_on_run=True,
)
saved_names = [os.path.basename(path) for path, _args, _kwargs in FakePILImage.saved_paths]
def test_load_folder_node_has_expected_outputs(self):
self.assertEqual(
saved_names,
[
"asset_2026-08-05_13-07-09_10x12_0_001.png",
"asset_2026-08-05_13-07-09_10x12_1_001.png",
],
self.nodes.DumasLoadImagesFolderNode.RETURN_NAMES,
("image", "mask", "width", "height", "filename", "index", "total"),
)
def test_save_image_counter_increments_for_existing_files(self):
node = self.image_nodes.DumasSaveImageNode()
image = FakeTensorBatch()
node.save_images(
images=image,
folder=self.temp_dir,
pattern="counter_%counter%",
format="png",
quality=100,
embed_workflow=False,
save_on_run=True,
)
open(FakePILImage.saved_paths[0][0], "a", encoding="utf-8").close()
node.save_images(
images=image,
folder=self.temp_dir,
pattern="counter_%counter%",
format="png",
quality=100,
embed_workflow=False,
save_on_run=True,
)
saved_names = [os.path.basename(path) for path, _args, _kwargs in FakePILImage.saved_paths]
self.assertEqual(saved_names, ["counter_001.png", "counter_002.png"])
def test_save_image_uses_same_counter_for_folder_and_filename(self):
node = self.image_nodes.DumasSaveImageNode()
image = FakeTensorBatch()
node.save_images(
images=image,
folder=self.temp_dir,
pattern="Char%counter%/Char%counter%",
format="png",
quality=100,
embed_workflow=False,
save_on_run=True,
)
saved_path = FakePILImage.saved_paths[0][0].replace("\\", "/")
self.assertTrue(saved_path.endswith("/Char001/Char001.png"))
def test_save_image_creates_nested_directories_before_saving(self):
node = self.image_nodes.DumasSaveImageNode()
image = FakeTensorBatch()
node.save_images(
images=image,
folder=self.temp_dir,
pattern="Char_%counter%/Base",
format="png",
quality=100,
embed_workflow=False,
save_on_run=True,
)
saved_path = FakePILImage.saved_paths[0][0]
self.assertTrue(os.path.isdir(os.path.dirname(saved_path)))
def test_character_reference_builds_structured_reference(self):
node = self.image_nodes.DumasCharacterReferenceNode()
image = FakeTensorBatch()
result = node.build_reference(
image=image,
picture_id="2",
character_id="char_dave",
name="Dave",
alias="The Locksmith",
gender="male",
age="41",
nationality="English",
occupation="a detective",
height_feet="6",
height_inches="2",
accent="English",
description="Square jaw, tired eyes, cropped brown hair.",
general="wears a long grey coat",
wardrobe="weathered red flight jacket, grey cargo shorts, black boots",
)
reference = result[0]
self.assertIs(reference["image"], image)
self.assertEqual(
reference,
{
"kind": "character",
"id": "char-dave",
"name": "Dave",
"aliases": ["The Locksmith"],
"picture_id": 2,
"picture_label": "<Picture 2>",
"image": image,
"summary": "Dave shown in <Picture 2>.",
"description": "Square jaw, tired eyes, cropped brown hair.",
"wardrobe": "weathered red flight jacket, grey cargo shorts, black boots",
"general": "wears a long grey coat",
"facts": {
"gender": "male",
"age": "41",
"nationality": "English",
"occupation": "a detective",
"height_feet": "6",
"height_inches": "2",
"accent": "English",
},
},
)
def test_character_reference_handles_missing_optional_fields(self):
node = self.image_nodes.DumasCharacterReferenceNode()
image = FakeTensorBatch()
result = node.build_reference(
image=image,
picture_id="4",
character_id="",
name="",
alias="",
gender="",
age="unknown",
nationality="",
occupation="",
height_feet="",
height_inches="",
accent="",
description="",
general="",
wardrobe="",
)
reference = result[0]
self.assertEqual(reference["kind"], "character")
self.assertEqual(reference["picture_id"], 4)
self.assertEqual(reference["picture_label"], "<Picture 4>")
self.assertEqual(reference["wardrobe"], "")
self.assertEqual(reference["general"], "")
self.assertEqual(reference["facts"]["age"], "")
def test_location_reference_builds_structured_reference(self):
node = self.image_nodes.DumasLocationReferenceNode()
image = FakeTensorBatch()
result = node.build_reference(
image=image,
picture_id="9",
location_id="coffee-shop-01",
name="Coffee Shop",
alias="Cafe Interior",
description="Warm tungsten lighting, narrow counter, rainy front window.",
general="Evening ambience, cramped but cozy.",
)
self.assertEqual(
result[0],
{
"kind": "location",
"id": "coffee-shop-01",
"name": "Coffee Shop",
"aliases": ["Cafe Interior"],
"picture_id": 9,
"picture_label": "<Picture 9>",
"image": image,
"summary": "Coffee Shop shown in <Picture 9>.",
"description": "Warm tungsten lighting, narrow counter, rainy front window.",
"wardrobe": "",
"general": "Evening ambience, cramped but cozy.",
"facts": {},
},
)
def test_anchor_style_node_exposes_requested_presets(self):
input_types = self.image_nodes.DumasAnchorStyleNode.INPUT_TYPES()
options = input_types["required"]["anchor_style"][0]
self.assertGreaterEqual(len(options), 40)
self.assertIn("cinematic action movie", options)
self.assertIn("comedy", options)
self.assertIn("found footage", options)
self.assertIn("90s sitcom", options)
self.assertIn("mobile/cell phone captured", options)
self.assertIn("news broadcast", options)
self.assertIn("mockumentary", options)
self.assertIn("heist thriller", options)
self.assertIn("cyberpunk neon", options)
self.assertIn("nature documentary", options)
self.assertIn("courtroom drama", options)
def test_anchor_style_node_defaults_to_selected_preset_description(self):
node = self.image_nodes.DumasAnchorStyleNode()
result = node.build_anchor("found footage", "")
self.assertIn("found-footage", result[0])
self.assertIn("real time", result[0])
self.assertIn("persistent camera language", result[0])
def test_anchor_style_node_prefers_manual_description_edits(self):
node = self.image_nodes.DumasAnchorStyleNode()
custom = "Lo-fi pirate broadcast with smeared highlights and anxious zoom corrections."
result = node.build_anchor("news broadcast", custom)
self.assertEqual(result[0], custom)
def test_save_image_returns_ui_entries_for_output_folder(self):
node = self.image_nodes.DumasSaveImageNode()
image = FakeTensorBatch()
result = node.save_images(
images=image,
folder="",
pattern="result_%counter%",
format="jpg",
quality=90,
embed_workflow=False,
save_on_run=True,
)
self.assertEqual(result["ui"]["images"][0]["type"], "output")
self.assertTrue(result["ui"]["images"][0]["filename"].endswith(".jpg"))
def test_save_image_returns_ui_entries_for_external_folder(self):
node = self.image_nodes.DumasSaveImageNode()
image = FakeTensorBatch()
external_dir = tempfile.mkdtemp(prefix="dumas-image-node-external-")
result = node.save_images(
images=image,
folder=external_dir,
pattern="external_%counter%",
format="png",
quality=100,
embed_workflow=False,
save_on_run=True,
)
self.assertEqual(result["ui"]["images"][0]["type"], "external")
self.assertEqual(result["ui"]["images"][0]["subfolder"], external_dir.replace("\\", "/"))
self.assertTrue(result["ui"]["images"][0]["token"])
def test_save_image_handles_windows_different_drive_paths(self):
node = self.image_nodes.DumasSaveImageNode()
image = FakeTensorBatch()
with mock.patch.object(
self.image_nodes.folder_paths,
"get_output_directory",
return_value="C:\\ComfyUI\\output",
), mock.patch.object(
self.image_nodes.os.path,
"abspath",
return_value="D:\\renders",
):
result = node.save_images(
images=image,
folder="D:\\renders",
pattern="drive_%counter%",
format="png",
quality=100,
embed_workflow=False,
save_on_run=True,
)
self.assertEqual(result["ui"]["images"][0]["type"], "external")
self.assertEqual(result["ui"]["images"][0]["subfolder"], "D:/renders")
self.assertTrue(result["ui"]["images"][0]["token"])
def test_save_image_skips_when_save_is_disabled(self):
node = self.image_nodes.DumasSaveImageNode()
image = FakeTensorBatch()
result = node.save_images(
images=image,
folder=self.temp_dir,
pattern="ignored_%counter%",
format="png",
quality=100,
embed_workflow=False,
save_on_run=False,
)
self.assertEqual(result["ui"]["images"], [])
self.assertEqual(FakePILImage.saved_paths, [])
def test_load_images_folder_uses_manual_selected_files(self):
node = self.image_nodes.DumasLoadImagesFolderNode()
folder = tempfile.mkdtemp(prefix="dumas-load-folder-manual-")
for name in ("b.png", "a.png", "notes.txt"):
open(os.path.join(folder, name), "a", encoding="utf-8").close()
state = json.dumps(
{
"folder": folder,
"recursive": False,
"sort": "name",
"sort_dir": "asc",
"selection_mode": "selected",
"selected": ["b.png", "a.png"],
}
)
with mock.patch.object(
self.image_nodes,
"_load_folder_image",
side_effect=lambda path: (f"image:{os.path.basename(path)}", f"mask:{os.path.basename(path)}", 32, 24),
):
result = node.load(state)
self.assertEqual(result[0], ["image:b.png", "image:a.png"])
self.assertEqual(result[1], ["mask:b.png", "mask:a.png"])
self.assertEqual(result[4], ["b", "a"])
self.assertEqual(result[5], [1, 2])
self.assertEqual(result[6], [2, 2])
def test_load_images_folder_first_n_uses_sorted_files(self):
node = self.image_nodes.DumasLoadImagesFolderNode()
folder = tempfile.mkdtemp(prefix="dumas-load-folder-first-")
for name in ("c.png", "a.png", "b.png"):
open(os.path.join(folder, name), "a", encoding="utf-8").close()
state = json.dumps(
{
"folder": folder,
"recursive": False,
"sort": "name",
"sort_dir": "asc",
"selection_mode": "first_n",
"first_n": 2,
}
)
with mock.patch.object(
self.image_nodes,
"_load_folder_image",
side_effect=lambda path: (f"image:{os.path.basename(path)}", f"mask:{os.path.basename(path)}", 64, 48),
):
result = node.load(state)
self.assertEqual(result[0], ["image:a.png", "image:b.png"])
self.assertEqual(result[4], ["a", "b"])
self.assertEqual(result[6], [2, 2])
def test_load_images_folder_random_selects_one_visible_image(self):
node = self.image_nodes.DumasLoadImagesFolderNode()
folder = tempfile.mkdtemp(prefix="dumas-load-folder-random-")
for name in ("a.png", "b.png", "c.png"):
open(os.path.join(folder, name), "a", encoding="utf-8").close()
state = json.dumps(
{
"folder": folder,
"recursive": False,
"sort": "name",
"sort_dir": "asc",
"selection_mode": "random",
}
)
with mock.patch.object(
self.image_nodes.random,
"choice",
side_effect=lambda files: files[1],
), mock.patch.object(
self.image_nodes,
"_load_folder_image",
side_effect=lambda path: (f"image:{os.path.basename(path)}", f"mask:{os.path.basename(path)}", 80, 60),
):
result = node.load(state)
self.assertEqual(result[0], ["image:b.png"])
self.assertEqual(result[4], ["b"])
self.assertEqual(result[5], [1])
self.assertEqual(result[6], [1])
def test_load_images_folder_random_is_changed_changes_each_run(self):
node = self.image_nodes.DumasLoadImagesFolderNode()
folder = tempfile.mkdtemp(prefix="dumas-load-folder-changed-")
open(os.path.join(folder, "a.png"), "a", encoding="utf-8").close()
state = json.dumps(
{
"folder": folder,
"recursive": False,
"sort": "name",
"sort_dir": "asc",
"selection_mode": "random",
}
)
with mock.patch.object(self.image_nodes.time, "time_ns", side_effect=[1, 2]):
changed_1 = node.IS_CHANGED(state)
changed_2 = node.IS_CHANGED(state)
self.assertNotEqual(changed_1, changed_2)
def test_h3_plan_scene_images_attach_and_extract(self):
attach_node = self.image_nodes.DumasH3PlanAttachSceneImagesNode()
extract_node = self.image_nodes.DumasH3PlanExtractSceneImagesNode()
plan = {"shots": [{"id": "intro"}, {"id": "middle"}]}
image_a = FakeTensorBatch()
image_b = FakeTensorBatch(width=10, height=10)
attached_plan, connected = attach_node.attach(
plan=plan,
scene_index=2,
image1=image_a,
image3=image_b,
)
extracted = extract_node.extract(attached_plan, 2)
self.assertEqual(connected, 2)
self.assertEqual(attached_plan["_dumas_scene_image_bindings"]["scene_counts"], {"2": 2})
self.assertIs(extracted[1], image_a)
self.assertIsNone(extracted[2])
self.assertIs(extracted[3], image_b)
self.assertEqual(extracted[-1], 2)
self.assertNotIn("_dumas_scene_image_bindings", plan)
def test_h3_plan_scene_images_support_multiple_scenes(self):
attach_node = self.image_nodes.DumasH3PlanAttachSceneImagesNode()
extract_node = self.image_nodes.DumasH3PlanExtractSceneImagesNode()
plan = {"shots": [{"id": "one"}, {"id": "two"}]}
image_1 = FakeTensorBatch()
image_2 = FakeTensorBatch(width=12, height=9)
image_3 = FakeTensorBatch(width=8, height=8)
image_4 = FakeTensorBatch(width=16, height=16)
image_5 = FakeTensorBatch(width=20, height=12)
plan_after_first, _connected = attach_node.attach(plan=plan, scene_index=1, image2=image_1)
plan_after_second, _connected = attach_node.attach(
plan=plan_after_first,
scene_index=2,
image6=image_2,
image7=image_3,
image8=image_4,
image9=image_5,
)
scene1 = extract_node.extract(plan_after_second, 1)
scene2 = extract_node.extract(plan_after_second, 2)
self.assertIs(scene1[2], image_1)
self.assertEqual(scene1[-1], 1)
self.assertIs(scene2[6], image_2)
self.assertIs(scene2[7], image_3)
self.assertIs(scene2[8], image_4)
self.assertIs(scene2[9], image_5)
self.assertEqual(scene2[-1], 4)
self.assertEqual(
plan_after_second["_dumas_scene_image_bindings"]["scene_counts"],
{"1": 1, "2": 4},
)
def test_h3_plan_scene_images_metadata_is_json_serializable(self):
attach_node = self.image_nodes.DumasH3PlanAttachSceneImagesNode()
plan = {"shots": [{"id": "one"}]}
attached_plan, connected = attach_node.attach(
plan=plan,
scene_index=1,
image4=FakeTensorBatch(),
)
self.assertEqual(connected, 1)
json.dumps(attached_plan)
def test_h3_plan_scene_images_support_nine_slots(self):
attach_node = self.image_nodes.DumasH3PlanAttachSceneImagesNode()
extract_node = self.image_nodes.DumasH3PlanExtractSceneImagesNode()
plan = {"shots": [{"id": "one"}]}
images = [FakeTensorBatch(width=8 + index, height=8 + index) for index in range(9)]
attached_plan, connected = attach_node.attach(
plan=plan,
scene_index=1,
image1=images[0],
image2=images[1],
image3=images[2],
image4=images[3],
image5=images[4],
image6=images[5],
image7=images[6],
image8=images[7],
image9=images[8],
)
extracted = extract_node.extract(attached_plan, 1)
self.assertEqual(connected, 9)
for index, image in enumerate(images, start=1):
self.assertIs(extracted[index], image)
self.assertEqual(extracted[-1], 9)
def test_h3_plan_scene_images_can_clear_a_scene_binding(self):
attach_node = self.image_nodes.DumasH3PlanAttachSceneImagesNode()
extract_node = self.image_nodes.DumasH3PlanExtractSceneImagesNode()
plan = {"shots": [{"id": "one"}]}
attached_plan, connected = attach_node.attach(
plan=plan,
scene_index=1,
image1=FakeTensorBatch(),
)
cleared_plan, cleared = attach_node.attach(plan=attached_plan, scene_index=1)
extracted = extract_node.extract(cleared_plan, 1)
self.assertEqual(connected, 1)
self.assertEqual(cleared, 0)
self.assertNotIn("_dumas_scene_image_bindings", cleared_plan)
self.assertEqual(extracted[-1], 0)
def test_h3_plan_scene_images_reject_invalid_scene_index(self):
attach_node = self.image_nodes.DumasH3PlanAttachSceneImagesNode()
plan = {"shots": [{"id": "one"}]}
with self.assertRaises(ValueError):
attach_node.attach(plan=plan, scene_index=2, image1=FakeTensorBatch())
if __name__ == "__main__":
unittest.main()
+45
View File
@@ -0,0 +1,45 @@
import importlib.util
import sys
import types
import unittest
class DumasVideoNodeTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
folder_paths = types.ModuleType("folder_paths")
folder_paths.get_output_directory = lambda: "/tmp"
sys.modules.setdefault("folder_paths", folder_paths)
spec = importlib.util.spec_from_file_location("dumas_video_nodes", "dumas_video_nodes.py")
cls.module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(cls.module)
def test_registers_two_generic_video_nodes(self):
self.assertEqual(
set(self.module.NODE_CLASS_MAPPINGS),
{"DumasStandaloneVideo", "DumasJoinVideoClips"},
)
def test_standalone_node_exposes_full_and_complete_outputs(self):
node = self.module.DumasStandaloneVideoNode
self.assertEqual(node.RETURN_NAMES, ("full_clip", "complete_clip", "complete_frames", "duration"))
self.assertIn("overlap_frames", node.INPUT_TYPES()["required"])
def test_join_signature_contains_stream_compatibility_fields(self):
signature = self.module._join_signature(
{
"streams": [
{"codec_type": "video", "codec_name": "h264", "width": 1920, "height": 1088, "pix_fmt": "yuv420p", "r_frame_rate": "24/1"},
{"codec_type": "audio", "codec_name": "aac", "sample_rate": "48000", "channels": 2},
]
}
)
self.assertEqual(signature, ("h264", 1920, 1088, "yuv420p", "24/1", "aac", "48000", 2))
def test_join_requires_a_clip(self):
with self.assertRaises(ValueError):
self.module.DumasJoinVideoClipsNode().join("")
if __name__ == "__main__":
unittest.main()