Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4063ef60a | ||
|
|
b5eb941c4b | ||
|
|
bfaa5fa733 | ||
|
|
9923a3e417 | ||
|
|
ea6fae7e56 | ||
|
|
72f9b07ed8 | ||
|
|
8d4232a142 | ||
|
|
d68d04254f | ||
|
|
22398c5213 | ||
|
|
1a4cfbfd7e | ||
|
|
eac4e73b47 | ||
|
|
e973a0d785 | ||
|
|
388de1d837 | ||
|
|
338150648b | ||
|
|
7de62226f2 | ||
|
|
a51141cb26 | ||
|
|
dd8ef84379 | ||
|
|
d20b257134 |
File diff suppressed because it is too large
Load Diff
@@ -1,276 +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.
|
||||
- Full user guide: [`H3_LONG_VIDEOS_GUIDE.md`](./H3_LONG_VIDEOS_GUIDE.md)
|
||||
- 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`.
|
||||
- `Dumas H3 Latent Upscale Params` provides the optional pre-decode latent refinement stage for the long-video node.
|
||||
- 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 Latent Upscale Params`
|
||||
- Inputs: `mode`, `model_name`, `method`, `width`, `height`, `device`, `precision`, `sampler_name`, `scheduler`, `steps`, `denoise`, `megapixels`, `tile_width`, `tile_height`, `overlap`, `fade_width`, `fade_height`, `overlap_mode`, `overlap_blend`, `tile_size_mode`, `grid_rows`, `grid_cols`, `spatial_w_overlap`, `spatial_h_overlap`, `min_tile_size`, `masked_area_noise`, `brightness_match`, `dynamic_fade`, `dynamic_fade_min`, `chunk_length`, `temporal_overlap`, `resize_conditioning`, `anchor_strength`
|
||||
- Output: `latent_upscale_param`
|
||||
- Bundles the optional latent-space upscaler settings used by `Dumas H3 Long Videos` before decode, so the main node can rebuild conditioning at the target size and run a short refinement pass with your chosen sampler, scheduler, step count, denoise, and the full upstream spatial split controls.
|
||||
## Other nodes
|
||||
|
||||
- `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.
|
||||
|
||||
- `Dumas H3 Prompt Curator`
|
||||
- Inputs: `action_prompt`, `anatomy_guard`, optional `anchor`, optional `soundscape`, optional `ref_1` through `ref_9`
|
||||
- Outputs: `prompt`, `ref_image_1` through `ref_image_9`, `reference_count`, `debug`
|
||||
- Builds one standalone MiniMax H3 prompt from your final action text plus structured character/location references.
|
||||
- The action text can mention references by character/location name, alias, `<Picture N>`, or `<refN>`. Only mentioned references are emitted, and the output images are compacted/renumbered so skipped inputs do not leave gaps.
|
||||
- Adds curated reference context, optional anatomy guard text, anchor/style text, and `overall_soundscape:` text while respecting MiniMax H3's reference-generation shape: one prompt plus up to nine reference images.
|
||||
|
||||
- `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`, `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`, `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 Character Helper`
|
||||
- Inputs: `image1`, `image2`, picture IDs, character identity fields, `general`, `wardrobe`
|
||||
- Outputs: `image1`, `image2`, `reference_prompt`, `wardrobe`
|
||||
- Restores the original general-purpose helper shape: pass two images through unchanged and emit prompt text/wardrobe text for manual wiring.
|
||||
|
||||
- `Dumas Location Helper`
|
||||
- Inputs: `image1`, `image2`, picture IDs, `location_id`, `name`, `alias`, `description`, `general`
|
||||
- Outputs: `image1`, `image2`, `reference_prompt`
|
||||
- Matching general-purpose helper for environments/locations: pass two images through unchanged and emit location reference prompt text.
|
||||
|
||||
- `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 Soundscape Helper`
|
||||
- Inputs: `soundscape`, `soundscape_description`
|
||||
- Output: `soundscape`
|
||||
- Matching soundscape helper for standalone H3 prompts. Pick a preset such as quiet interior, rainy street, cafe, city night, forest, industrial, or silent, then edit the text that flows into `Dumas H3 Prompt Curator`.
|
||||
|
||||
- `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 Helper` is the restored two-image/text helper for general H3 workflows, and `Dumas Location Helper` mirrors it for scene/environment references. The structured `Dumas Character Reference` and `Dumas Location Reference` nodes remain available separately for workflows that want a single `REFERENCE` socket. `Dumas H3 Prompt Curator` consumes those structured references, assigns the final `<Picture N>` numbering, and outputs only the compacted images the prompt actually mentions.
|
||||
|
||||
`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.
|
||||
|
||||
@@ -1,385 +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 effective `<Picture N>` identity.
|
||||
- It is inferred by consumer nodes such as `Dumas H3 Long Videos` from the
|
||||
connected socket position when that position is known.
|
||||
- Producer nodes do not need a manual `picture_id` input.
|
||||
|
||||
- `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`
|
||||
- `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`
|
||||
- `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
-29
@@ -10,44 +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_latent_upscale import (
|
||||
NODE_CLASS_MAPPINGS as H3_LATENT_UPSCALE_NODE_CLASS_MAPPINGS,
|
||||
NODE_DISPLAY_NAME_MAPPINGS as H3_LATENT_UPSCALE_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_LATENT_UPSCALE_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_LATENT_UPSCALE_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"
|
||||
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
@@ -1,186 +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",
|
||||
{
|
||||
"tooltip": "MiniMax / H3 model to inspect for quantization and tensor format."
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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
File diff suppressed because it is too large
Load Diff
@@ -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)
|
||||
@@ -1,67 +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": 3.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. Default 3s matches the common one-beat H3 test shot. Max ~15s (362 frames)."}),
|
||||
"fps": ("INT", {"default": 24, "min": 1, "max": 60,
|
||||
"tooltip": "Frame rate used for the seconds->frames conversion. H3 itself renders at 24fps, so 24 is the realistic default."}),
|
||||
},
|
||||
"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
-2572
File diff suppressed because it is too large
Load Diff
@@ -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)",
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -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,375 +0,0 @@
|
||||
import { app } from "/scripts/app.js";
|
||||
import { applyAdaptiveCanvasOnly } from "../shared/nodes2.mjs";
|
||||
|
||||
const COMFY_CLASS = "DumasH3LongVideos";
|
||||
const STATE_PROPERTY = "dumas_h3_longvideos_section_state";
|
||||
const DOM_WIDGET_NAME = "dumas_h3_longvideos_sections";
|
||||
const MIN_WIDTH = 520;
|
||||
const MIN_HEIGHT = 280;
|
||||
|
||||
const GROUPS = [
|
||||
{
|
||||
id: "prompt",
|
||||
label: "Prompt",
|
||||
defaultCollapsed: false,
|
||||
widgets: ["prompt", "resolution", "megapixels", "beat_split", "anchor_override", "shot_seconds", "plan_only", "fps"],
|
||||
},
|
||||
{
|
||||
id: "refs",
|
||||
label: "Refs",
|
||||
defaultCollapsed: true,
|
||||
widgets: ["ref_mode", "ref_image_size", "ref_noise_aug", "character_memory", "trim_seam", "vary_seed_per_shot", "handoff_offset"],
|
||||
},
|
||||
{
|
||||
id: "sampling",
|
||||
label: "Sampling",
|
||||
defaultCollapsed: true,
|
||||
widgets: [
|
||||
"steps", "cfg", "sampler_name", "scheduler", "seed",
|
||||
"apply_model_sampling", "shift_video", "shift_audio",
|
||||
"vram_headroom_gb", "allow_res_backoff",
|
||||
"decode_tile_frames", "decode_tile_size",
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "audio",
|
||||
label: "Audio",
|
||||
defaultCollapsed: true,
|
||||
widgets: [
|
||||
"global_soundscape", "non_diegetic_music", "auto_soundscape",
|
||||
"auto_silence_nonspeech", "allow_nonspeech_vocals",
|
||||
"mute_nonspeech_audio", "mute_fade_ms",
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "scene",
|
||||
label: "Scene Logic",
|
||||
defaultCollapsed: true,
|
||||
widgets: [
|
||||
"auto_wardrobe", "auto_props", "prevent_nudity", "exposed_terms",
|
||||
"anatomy_guard", "subject_count_guard", "lock_restraints",
|
||||
"contact_guard", "motion_guard", "solidity_guard",
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "finish",
|
||||
label: "Upscale",
|
||||
defaultCollapsed: true,
|
||||
widgets: [
|
||||
"upscale", "upscale_model", "upscale_target_short_edge", "upscale_batch",
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "overlay",
|
||||
label: "Overlays",
|
||||
defaultCollapsed: true,
|
||||
widgets: [
|
||||
"watermark_text", "watermark_position", "watermark_size", "watermark_opacity", "watermark_margin",
|
||||
"intro_text", "intro_position", "intro_seconds", "intro_fade", "intro_size",
|
||||
"overlay_font", "overlay_stroke",
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
function injectCSS() {
|
||||
if (document.getElementById("dumas-h3lv-sections-css")) return;
|
||||
const style = document.createElement("style");
|
||||
style.id = "dumas-h3lv-sections-css";
|
||||
style.textContent = `
|
||||
.dh3lv-sections {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
padding: 8px 10px 6px;
|
||||
color: #e6e7eb;
|
||||
font: 12px/1.35 "Segoe UI", sans-serif;
|
||||
pointer-events: auto;
|
||||
background: linear-gradient(180deg, rgba(33, 36, 42, 0.96), rgba(22, 24, 29, 0.96));
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
.dh3lv-sections-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.dh3lv-sections-title {
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
color: #9da5b1;
|
||||
}
|
||||
.dh3lv-sections-actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
}
|
||||
.dh3lv-sections-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
.dh3lv-chip,
|
||||
.dh3lv-action {
|
||||
appearance: none;
|
||||
border: 1px solid #464d59;
|
||||
background: #262c35;
|
||||
color: #d7dce3;
|
||||
border-radius: 999px;
|
||||
padding: 5px 9px;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
line-height: 1.1;
|
||||
}
|
||||
.dh3lv-chip[data-open="true"] {
|
||||
background: #d96f2b;
|
||||
border-color: #f09358;
|
||||
color: #fff7f0;
|
||||
}
|
||||
.dh3lv-chip:hover,
|
||||
.dh3lv-action:hover {
|
||||
filter: brightness(1.06);
|
||||
}
|
||||
.dh3lv-count {
|
||||
opacity: 0.78;
|
||||
margin-left: 4px;
|
||||
font-size: 11px;
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
|
||||
function defaultState() {
|
||||
const state = {};
|
||||
for (const group of GROUPS) state[group.id] = !group.defaultCollapsed;
|
||||
return state;
|
||||
}
|
||||
|
||||
function parseState(value) {
|
||||
let parsed = value;
|
||||
if (typeof parsed === "string") {
|
||||
try {
|
||||
parsed = JSON.parse(parsed);
|
||||
} catch (_error) {
|
||||
parsed = null;
|
||||
}
|
||||
}
|
||||
const base = defaultState();
|
||||
if (!parsed || typeof parsed !== "object") return base;
|
||||
for (const group of GROUPS) {
|
||||
if (typeof parsed[group.id] === "boolean") base[group.id] = parsed[group.id];
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
function readState(node) {
|
||||
return parseState(node.properties?.[STATE_PROPERTY] || node._dh3lvSectionState || "");
|
||||
}
|
||||
|
||||
function writeState(node, state) {
|
||||
const normalized = parseState(state);
|
||||
const serialized = JSON.stringify(normalized);
|
||||
node._dh3lvSectionState = serialized;
|
||||
node.properties = node.properties || {};
|
||||
node.properties[STATE_PROPERTY] = serialized;
|
||||
}
|
||||
|
||||
function findWidget(node, name) {
|
||||
return (node.widgets || []).find((widget) => widget?.name === name) || null;
|
||||
}
|
||||
|
||||
function isInteractiveTarget(target) {
|
||||
return !!target?.closest?.("button, input, textarea, select, label");
|
||||
}
|
||||
|
||||
function stopCanvasEvent(event) {
|
||||
if (isInteractiveTarget(event.target)) event.stopPropagation();
|
||||
}
|
||||
|
||||
function stopCanvasKeyboard(event) {
|
||||
if (isInteractiveTarget(event.target)) event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
function setWidgetHidden(widget, hidden) {
|
||||
if (!widget) return;
|
||||
if (!widget._dh3lvOriginal) {
|
||||
widget._dh3lvOriginal = {
|
||||
type: widget.type,
|
||||
computeSize: widget.computeSize,
|
||||
hidden: widget.hidden,
|
||||
};
|
||||
}
|
||||
if (hidden) {
|
||||
widget.type = "hidden";
|
||||
widget.hidden = true;
|
||||
widget.computeSize = () => [0, -4];
|
||||
return;
|
||||
}
|
||||
widget.type = widget._dh3lvOriginal.type;
|
||||
widget.hidden = !!widget._dh3lvOriginal.hidden;
|
||||
widget.computeSize = widget._dh3lvOriginal.computeSize;
|
||||
}
|
||||
|
||||
function applyVisibility(node) {
|
||||
const state = readState(node);
|
||||
for (const group of GROUPS) {
|
||||
for (const name of group.widgets) {
|
||||
const widget = findWidget(node, name);
|
||||
if (!widget || widget.name === DOM_WIDGET_NAME) continue;
|
||||
setWidgetHidden(widget, !state[group.id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resizeNode(node) {
|
||||
requestAnimationFrame(() => {
|
||||
const size = node.computeSize?.();
|
||||
if (Array.isArray(size)) {
|
||||
node.size[0] = Math.max(MIN_WIDTH, size[0] || 0, node.size?.[0] || 0);
|
||||
node.size[1] = Math.max(MIN_HEIGHT, size[1] || 0);
|
||||
}
|
||||
node.setDirtyCanvas?.(true, true);
|
||||
});
|
||||
}
|
||||
|
||||
function renderToolbar(node) {
|
||||
const ui = node._dh3lvUI;
|
||||
if (!ui) return;
|
||||
const state = readState(node);
|
||||
ui.list.innerHTML = "";
|
||||
for (const group of GROUPS) {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.className = "dh3lv-chip";
|
||||
button.dataset.open = state[group.id] ? "true" : "false";
|
||||
button.textContent = state[group.id] ? `Hide ${group.label}` : `Show ${group.label}`;
|
||||
|
||||
const count = document.createElement("span");
|
||||
count.className = "dh3lv-count";
|
||||
count.textContent = String(group.widgets.filter((name) => findWidget(node, name)).length);
|
||||
button.appendChild(count);
|
||||
|
||||
button.addEventListener("click", () => {
|
||||
const next = readState(node);
|
||||
next[group.id] = !next[group.id];
|
||||
writeState(node, next);
|
||||
applyVisibility(node);
|
||||
renderToolbar(node);
|
||||
resizeNode(node);
|
||||
});
|
||||
ui.list.appendChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
function setAll(node, open) {
|
||||
const next = {};
|
||||
for (const group of GROUPS) next[group.id] = !!open;
|
||||
writeState(node, next);
|
||||
applyVisibility(node);
|
||||
renderToolbar(node);
|
||||
resizeNode(node);
|
||||
}
|
||||
|
||||
function setupNode(node) {
|
||||
if (node._dh3lvUI) return;
|
||||
injectCSS();
|
||||
writeState(node, readState(node));
|
||||
|
||||
const root = document.createElement("div");
|
||||
root.className = "dh3lv-sections";
|
||||
|
||||
const head = document.createElement("div");
|
||||
head.className = "dh3lv-sections-head";
|
||||
|
||||
const title = document.createElement("div");
|
||||
title.className = "dh3lv-sections-title";
|
||||
title.textContent = "Sections";
|
||||
|
||||
const actions = document.createElement("div");
|
||||
actions.className = "dh3lv-sections-actions";
|
||||
|
||||
const expandAll = document.createElement("button");
|
||||
expandAll.type = "button";
|
||||
expandAll.className = "dh3lv-action";
|
||||
expandAll.textContent = "Expand All";
|
||||
expandAll.addEventListener("click", () => setAll(node, true));
|
||||
|
||||
const collapseAll = document.createElement("button");
|
||||
collapseAll.type = "button";
|
||||
collapseAll.className = "dh3lv-action";
|
||||
collapseAll.textContent = "Collapse Extras";
|
||||
collapseAll.addEventListener("click", () => {
|
||||
const next = defaultState();
|
||||
writeState(node, next);
|
||||
applyVisibility(node);
|
||||
renderToolbar(node);
|
||||
resizeNode(node);
|
||||
});
|
||||
|
||||
actions.append(expandAll, collapseAll);
|
||||
head.append(title, actions);
|
||||
|
||||
const list = document.createElement("div");
|
||||
list.className = "dh3lv-sections-list";
|
||||
root.append(head, list);
|
||||
root.addEventListener("pointerdown", stopCanvasEvent);
|
||||
root.addEventListener("mousedown", stopCanvasEvent);
|
||||
root.addEventListener("click", stopCanvasEvent);
|
||||
root.addEventListener("dblclick", stopCanvasEvent);
|
||||
root.addEventListener("keydown", stopCanvasKeyboard, true);
|
||||
|
||||
node._dh3lvUI = { root, list };
|
||||
const widget = node.addDOMWidget(DOM_WIDGET_NAME, "custom", root, {
|
||||
getValue: () => null,
|
||||
setValue: () => {},
|
||||
serialize: false,
|
||||
getMinHeight: () => 52,
|
||||
hideOnZoom: false,
|
||||
});
|
||||
applyAdaptiveCanvasOnly(widget);
|
||||
const widgets = node.widgets || [];
|
||||
const index = widgets.indexOf(widget);
|
||||
if (index > 0) {
|
||||
widgets.splice(index, 1);
|
||||
widgets.unshift(widget);
|
||||
}
|
||||
|
||||
applyVisibility(node);
|
||||
renderToolbar(node);
|
||||
resizeNode(node);
|
||||
}
|
||||
|
||||
app.registerExtension({
|
||||
name: "Dumas.H3LongVideosSections",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData) {
|
||||
if (nodeData?.name !== COMFY_CLASS) return;
|
||||
|
||||
const originalOnNodeCreated = nodeType.prototype.onNodeCreated;
|
||||
nodeType.prototype.onNodeCreated = function onNodeCreated() {
|
||||
const result = originalOnNodeCreated?.apply(this, arguments);
|
||||
setupNode(this);
|
||||
return result;
|
||||
};
|
||||
|
||||
const originalConfigure = nodeType.prototype.onConfigure;
|
||||
nodeType.prototype.onConfigure = function onConfigure() {
|
||||
const result = originalConfigure?.apply(this, arguments);
|
||||
setupNode(this);
|
||||
writeState(this, readState(this));
|
||||
applyVisibility(this);
|
||||
renderToolbar(this);
|
||||
resizeNode(this);
|
||||
return result;
|
||||
};
|
||||
|
||||
const originalSerialize = nodeType.prototype.onSerialize;
|
||||
nodeType.prototype.onSerialize = function onSerialize(o) {
|
||||
writeState(this, readState(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;
|
||||
};
|
||||
},
|
||||
});
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "dumasnodes"
|
||||
description = "Dumas-branded generic utility nodes for ComfyUI, starting with JSON helpers."
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
license = { file = "LICENSE" }
|
||||
|
||||
[project.urls]
|
||||
|
||||
@@ -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()
|
||||
File diff suppressed because it is too large
Load Diff
+28
-848
@@ -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,839 +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,
|
||||
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": None,
|
||||
"picture_label": "",
|
||||
"image": image,
|
||||
"summary": "Dave reference.",
|
||||
"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_input_types_do_not_expose_picture_id(self):
|
||||
required = self.image_nodes.DumasCharacterReferenceNode.INPUT_TYPES()["required"]
|
||||
self.assertNotIn("picture_id", required)
|
||||
|
||||
def test_character_reference_handles_missing_optional_fields(self):
|
||||
node = self.image_nodes.DumasCharacterReferenceNode()
|
||||
image = FakeTensorBatch()
|
||||
|
||||
result = node.build_reference(
|
||||
image=image,
|
||||
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.assertIsNone(reference["picture_id"])
|
||||
self.assertEqual(reference["picture_label"], "")
|
||||
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,
|
||||
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": None,
|
||||
"picture_label": "",
|
||||
"image": image,
|
||||
"summary": "Coffee Shop reference.",
|
||||
"description": "Warm tungsten lighting, narrow counter, rainy front window.",
|
||||
"wardrobe": "",
|
||||
"general": "Evening ambience, cramped but cozy.",
|
||||
"facts": {},
|
||||
},
|
||||
)
|
||||
|
||||
def test_location_reference_input_types_do_not_expose_picture_id(self):
|
||||
required = self.image_nodes.DumasLocationReferenceNode.INPUT_TYPES()["required"]
|
||||
self.assertNotIn("picture_id", required)
|
||||
|
||||
def test_character_helper_restores_image_and_text_outputs(self):
|
||||
node = self.image_nodes.DumasCharacterHelperNode()
|
||||
image1 = FakeTensorBatch()
|
||||
image2 = FakeTensorBatch()
|
||||
|
||||
result = node.build_character_text(
|
||||
image1=image1,
|
||||
image2=image2,
|
||||
image1_picture_id="1",
|
||||
image2_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",
|
||||
general="Moves carefully and notices every exit",
|
||||
wardrobe="weathered red flight jacket, grey cargo shorts, black boots",
|
||||
)
|
||||
|
||||
self.assertIs(result[0], image1)
|
||||
self.assertIs(result[1], image2)
|
||||
self.assertIn("<Picture 1> and <Picture 2> reference the same character", result[2])
|
||||
self.assertIn("Dave is also known as The Locksmith", result[2])
|
||||
self.assertIn("is 41 years old", result[2])
|
||||
self.assertEqual(result[3], "Dave = weathered red flight jacket, grey cargo shorts, black boots")
|
||||
|
||||
def test_location_helper_matches_character_helper_shape_without_wardrobe(self):
|
||||
node = self.image_nodes.DumasLocationHelperNode()
|
||||
image1 = FakeTensorBatch()
|
||||
image2 = FakeTensorBatch()
|
||||
|
||||
result = node.build_location_text(
|
||||
image1=image1,
|
||||
image2=image2,
|
||||
image1_picture_id="3",
|
||||
image2_picture_id="4",
|
||||
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.assertIs(result[0], image1)
|
||||
self.assertIs(result[1], image2)
|
||||
self.assertIn("<Picture 3> and <Picture 4> reference the same location", result[2])
|
||||
self.assertIn("Coffee Shop is also known as Cafe Interior", result[2])
|
||||
self.assertIn("Warm tungsten lighting, narrow counter, rainy front window.", result[2])
|
||||
self.assertIn("Evening ambience, cramped but cozy.", result[2])
|
||||
self.assertEqual(len(result), 3)
|
||||
|
||||
def test_soundscape_helper_defaults_to_selected_preset_description(self):
|
||||
node = self.image_nodes.DumasSoundscapeHelperNode()
|
||||
|
||||
result = node.build_soundscape("rainy street", "")
|
||||
|
||||
self.assertEqual(result[0], "steady rain, wet pavement, distant traffic hum")
|
||||
|
||||
def test_h3_prompt_curator_compacts_named_references(self):
|
||||
node = self.image_nodes.DumasH3PromptCuratorNode()
|
||||
dave_image = FakeTensorBatch()
|
||||
cafe_image = FakeTensorBatch()
|
||||
van_image = FakeTensorBatch()
|
||||
dave = self.image_nodes.make_reference(
|
||||
kind="character",
|
||||
image=dave_image,
|
||||
name="Dave",
|
||||
aliases="The Locksmith",
|
||||
description="tired eyes, cropped brown hair",
|
||||
wardrobe="red flight jacket",
|
||||
)
|
||||
cafe = self.image_nodes.make_reference(
|
||||
kind="location",
|
||||
image=cafe_image,
|
||||
name="Coffee Shop",
|
||||
description="warm tungsten lighting and rainy windows",
|
||||
)
|
||||
van = self.image_nodes.make_reference(
|
||||
kind="location",
|
||||
image=van_image,
|
||||
name="Blue Van",
|
||||
description="scuffed blue delivery van",
|
||||
)
|
||||
|
||||
result = node.curate_prompt(
|
||||
action_prompt="Dave runs from the Coffee Shop into the rain.",
|
||||
anatomy_guard="auto",
|
||||
anchor="grounded handheld thriller",
|
||||
soundscape="steady rain",
|
||||
ref_1=dave,
|
||||
ref_2=van,
|
||||
ref_3=cafe,
|
||||
)
|
||||
|
||||
prompt = result[0]
|
||||
self.assertIn("<Picture 1> Dave", prompt)
|
||||
self.assertIn("<Picture 2> Coffee Shop", prompt)
|
||||
self.assertIn("Action: Dave runs from the Coffee Shop into the rain.", prompt)
|
||||
self.assertIn("Anatomy guard:", prompt)
|
||||
self.assertIs(result[1], dave_image)
|
||||
self.assertIs(result[2], cafe_image)
|
||||
self.assertIsNone(result[3])
|
||||
self.assertEqual(result[10], 2)
|
||||
self.assertIn("input 3-><Picture 2> Coffee Shop", result[11])
|
||||
|
||||
def test_h3_prompt_curator_renumbers_explicit_reference_tags(self):
|
||||
node = self.image_nodes.DumasH3PromptCuratorNode()
|
||||
image1 = FakeTensorBatch()
|
||||
image3 = FakeTensorBatch()
|
||||
unused = FakeTensorBatch()
|
||||
first = self.image_nodes.make_reference(kind="character", image=image1, name="Maya")
|
||||
second = self.image_nodes.make_reference(kind="location", image=unused, name="Lobby")
|
||||
third = self.image_nodes.make_reference(kind="location", image=image3, name="Rooftop")
|
||||
|
||||
result = node.curate_prompt(
|
||||
action_prompt="<Picture 1> Maya crosses to <ref3> as the wind rises.",
|
||||
anatomy_guard="off",
|
||||
ref_1=first,
|
||||
ref_2=second,
|
||||
ref_3=third,
|
||||
)
|
||||
|
||||
prompt = result[0]
|
||||
self.assertIn("<Picture 1> Maya crosses to <Picture 2>", prompt)
|
||||
self.assertNotIn("<Picture 3>", prompt)
|
||||
self.assertIs(result[1], image1)
|
||||
self.assertIs(result[2], image3)
|
||||
self.assertIsNone(result[3])
|
||||
self.assertEqual(result[10], 2)
|
||||
|
||||
def test_helper_node_mappings_use_general_purpose_helpers(self):
|
||||
mappings = self.image_nodes.NODE_CLASS_MAPPINGS
|
||||
display = self.image_nodes.NODE_DISPLAY_NAME_MAPPINGS
|
||||
|
||||
self.assertIs(mappings["DumasCharacterHelper"], self.image_nodes.DumasCharacterHelperNode)
|
||||
self.assertIs(mappings["DumasLocationHelper"], self.image_nodes.DumasLocationHelperNode)
|
||||
self.assertIs(mappings["DumasSoundscapeHelper"], self.image_nodes.DumasSoundscapeHelperNode)
|
||||
self.assertIs(mappings["DumasH3PromptCurator"], self.image_nodes.DumasH3PromptCuratorNode)
|
||||
self.assertEqual(display["DumasCharacterHelper"], "Dumas Character Helper")
|
||||
self.assertEqual(display["DumasLocationHelper"], "Dumas Location Helper")
|
||||
self.assertEqual(display["DumasSoundscapeHelper"], "Dumas Soundscape Helper")
|
||||
self.assertEqual(display["DumasH3PromptCurator"], "Dumas H3 Prompt Curator")
|
||||
|
||||
def test_h3_prompt_curator_uses_documented_reference_limits(self):
|
||||
node = self.image_nodes.DumasH3PromptCuratorNode()
|
||||
self.assertEqual(len(node.RETURN_TYPES), 12)
|
||||
self.assertEqual(node.RETURN_NAMES[1:10], tuple(f"ref_image_{i}" for i in range(1, 10)))
|
||||
|
||||
def test_normalize_reference_upgrades_generic_summary_with_socket_picture_id(self):
|
||||
image = FakeTensorBatch()
|
||||
|
||||
reference = self.image_nodes.normalize_reference(
|
||||
{
|
||||
"kind": "character",
|
||||
"name": "Dave",
|
||||
"image": image,
|
||||
"summary": "Dave reference.",
|
||||
},
|
||||
picture_id=3,
|
||||
allow_image_fallback=False,
|
||||
)
|
||||
|
||||
self.assertEqual(reference["picture_id"], 3)
|
||||
self.assertEqual(reference["picture_label"], "<Picture 3>")
|
||||
self.assertEqual(reference["summary"], "Dave shown in <Picture 3>.")
|
||||
|
||||
def test_normalize_reference_keeps_custom_summary_when_socket_picture_id_is_added(self):
|
||||
image = FakeTensorBatch()
|
||||
|
||||
reference = self.image_nodes.normalize_reference(
|
||||
{
|
||||
"kind": "character",
|
||||
"name": "Dave",
|
||||
"image": image,
|
||||
"summary": "Primary hero look for the opening close-up.",
|
||||
},
|
||||
picture_id=3,
|
||||
allow_image_fallback=False,
|
||||
)
|
||||
|
||||
self.assertEqual(reference["picture_id"], 3)
|
||||
self.assertEqual(reference["summary"], "Primary hero look for the opening close-up.")
|
||||
|
||||
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.assertNotIn("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()
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user