Skip to content

Commit

Permalink
Properly handle format widget conversion
Browse files Browse the repository at this point in the history
Format widgets don't exist in the node def. This makes converting them
into an input difficult. AddInput is now wrapped on nodes that include
format widgets (only Video Combine) to intercept and add the proper
configuration to the input on conversion. Separately, when workflow data
is loaded that includes a converted format widget, that config data is
properly applied to the already existent input.

Code to forcibly convert input types which do not match has been
removed. This code was a best effort attempt to ease over the transition
from VHS_AUDIO to AUDIO, but did not function as well as hoped and now
causes more issues than it solves. Particular by clobbering a converted
input type to wildcard when connected to a primitive.

Resolves #326
  • Loading branch information
AustinMroz committed Dec 1, 2024
1 parent 8222985 commit 05f085e
Show file tree
Hide file tree
Showing 2 changed files with 275 additions and 10 deletions.
253 changes: 253 additions & 0 deletions tests/converted-format-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
{
"last_node_id": 19,
"last_link_id": 20,
"nodes": [
{
"id": 18,
"type": "PrimitiveNode",
"pos": [
318,
618
],
"size": [
210,
82
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "INT",
"type": "INT",
"links": [
18
],
"widget": {
"name": "crf"
}
}
],
"properties": {
"Run widget replace on values": false
},
"widgets_values": [
60,
"fixed"
]
},
{
"id": 11,
"type": "LoadImage",
"pos": [
260.4530029296875,
233.2003173828125
],
"size": [
315,
314
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
19
],
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"example.png",
"image"
]
},
{
"id": 17,
"type": "VHS_VideoCombine",
"pos": [
733.3749389648438,
338.28924560546875
],
"size": [
222.91415405273438,
522.9141845703125
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 19
},
{
"name": "audio",
"type": "AUDIO",
"link": null,
"shape": 7
},
{
"name": "meta_batch",
"type": "VHS_BatchManager",
"link": null,
"shape": 7
},
{
"name": "vae",
"type": "VAE",
"link": null,
"shape": 7
},
{
"name": "crf",
"type": "INT",
"link": 18,
"widget": {
"name": "crf"
}
},
{
"name": "pix_fmt",
"type": [
"yuv420p",
"yuv420p10le"
],
"link": 20,
"widget": {
"name": "pix_fmt"
}
}
],
"outputs": [
{
"name": "Filenames",
"type": "VHS_FILENAMES",
"links": null
}
],
"properties": {
"Node name for S&R": "VHS_VideoCombine"
},
"widgets_values": {
"frame_rate": 8,
"loop_count": 0,
"filename_prefix": "AnimateDiff",
"format": "video/h264-mp4",
"pix_fmt": "yuv420p10le",
"crf": 60,
"save_metadata": true,
"pingpong": false,
"save_output": false,
"videopreview": {
"hidden": false,
"paused": false,
"params": {
"filename": "AnimateDiff_00001.mp4",
"subfolder": "",
"type": "temp",
"format": "video/h264-mp4",
"frame_rate": 8
},
"muted": false
}
}
},
{
"id": 19,
"type": "PrimitiveNode",
"pos": [
300,
760
],
"size": [
290,
110
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "COMBO",
"type": "COMBO",
"links": [
20
],
"widget": {
"name": "pix_fmt"
}
}
],
"properties": {
"Run widget replace on values": false
},
"widgets_values": [
"yuv420p10le",
"fixed",
""
]
}
],
"links": [
[
18,
18,
0,
17,
4,
"INT"
],
[
19,
11,
0,
17,
0,
"IMAGE"
],
[
20,
19,
0,
17,
5,
[
"yuv420p",
"yuv420p10le"
]
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.8264462809917354,
"offset": [
45.8650452880864,
-157.46987175292935
]
}
},
"version": 0.4,
"tests": {
"17": [{"type": "video", "key": "pix_fmt", "value": "yuv420p10le"}
],
"length": 1
}
}
32 changes: 22 additions & 10 deletions web/js/VHS.core.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"🍡"
import { app } from '../../../scripts/app.js'
import { api } from '../../../scripts/api.js'
import { setWidgetConfig } from '../../../extensions/core/widgetInputs.js'
import { applyTextReplacements } from "../../../scripts/utils.js";

function chainCallback(object, property, callback) {
Expand Down Expand Up @@ -53,16 +54,6 @@ const renameDict = {VHS_VideoCombine : {save_output : "save_image"}}
function useKVState(nodeType) {
chainCallback(nodeType.prototype, "onNodeCreated", function () {
chainCallback(this, "onConfigure", function(info) {
if (this.inputs) {
for (let i = 0; i < this.inputs.length; i++) {
let dt = this?.getInputDataType(i)
if (dt && this.inputs[i]?.type != dt && !(dt == "IMAGE" && this.inputs[i].type == "LATENT")) {
this.inputs[i].type = dt
console.warn("input type mismatch for " + this.title + " slot " + i)

}
}
}
if (!this.widgets) {
//Node has no widgets, there is nothing to restore
return
Expand Down Expand Up @@ -93,6 +84,10 @@ function useKVState(nodeType) {
}
}
}
let inputs = {}
for (let i of this.inputs) {
inputs[i.name] = i
}
if (widgetDict.length == undefined) {
for (let w of this.widgets) {
if (w.name in widgetDict) {
Expand Down Expand Up @@ -125,6 +120,9 @@ function useKVState(nodeType) {
w.value = initialValue;
}
}
if (w.name in inputs && w.config) {
setWidgetConfig(inputs[w.name], w.config.slice(1), w)
}
}
} else {
//Saved data was not a map made by this method
Expand Down Expand Up @@ -1031,6 +1029,7 @@ function addFormatWidgets(nodeType) {
//TODO: consider letting this happen and just removing from list?
let w = {};
w.name = wDef[0];
w.config = wDef;
let inputData = wDef.slice(1);
w.type = inputData[0];
w.options = inputData[1] ? inputData[1] : {};
Expand Down Expand Up @@ -1064,6 +1063,19 @@ function addFormatWidgets(nodeType) {
return formatWidget._value;
}
});
const originalAddInput = this.addInput;
this.addInput = function(name, type, options) {
if (options.widget) {
const widget = this.widgets.find((w) => w.name == name)
if (widget.config) {
//Is converted format widget
type = widget.config[1]
const symbol = Object.getOwnPropertySymbols(options.widget)[0]
options.widget[symbol] = () => widget.config.slice(1)
}
}
return originalAddInput.apply(this, [name, type, options])
}
});
}
function sizeModifiesAspect(value) {
Expand Down

0 comments on commit 05f085e

Please sign in to comment.