mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-26 17:54:14 +00:00
fix: detect video output from data in Nodes 2.0 (#8943)
## Summary - Fixes SaveWebM node showing "Error loading image" in Vue nodes mode - Extracts `isAnimatedOutput`/`isVideoOutput` utility functions from inline logic in `unsafeUpdatePreviews` so both the litegraph canvas renderer and Vue nodes renderer can detect video output directly from execution data - Uses output-based detection in `imagePreviewStore.isImageOutputs` to avoid applying image preview format conversion to video files ## Background In Vue nodes mode, `nodeMedia` relied on `node.previewMediaType` to determine if output is video. This property is only set via `onDrawBackground` → `unsafeUpdatePreviews` in the litegraph canvas path, which doesn't run in Vue nodes mode. This caused webm output to render via `<img>` instead of `<video>`. ## Before https://github.com/user-attachments/assets/36f8a033-0021-4351-8f82-d19e3faa80c2 ## After https://github.com/user-attachments/assets/6558d261-d70e-4968-9637-6c24532e23ac ## Test plan - [x] `pnpm typecheck` passes - [x] `pnpm lint` passes - [x] `pnpm test:unit` passes (4500 tests) ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8943-fix-detect-video-output-from-data-in-Vue-nodes-mode-30a6d73d365081e98e91d6d1dcc88785) by [Unito](https://www.unito.io) --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
committed by
GitHub
parent
b47414a52f
commit
d3c0e331eb
@@ -9,9 +9,12 @@ import type {
|
||||
import type { ISerialisedGraph } from '@/lib/litegraph/src/types/serialisation'
|
||||
import type { IWidget } from '@/lib/litegraph/src/types/widgets'
|
||||
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import type { ExecutedWsMessage } from '@/schemas/apiSchema'
|
||||
import {
|
||||
compressWidgetInputSlots,
|
||||
createNode,
|
||||
isAnimatedOutput,
|
||||
isVideoOutput,
|
||||
migrateWidgetsValues
|
||||
} from '@/utils/litegraphUtil'
|
||||
|
||||
@@ -199,6 +202,106 @@ describe('migrateWidgetsValues', () => {
|
||||
})
|
||||
})
|
||||
|
||||
function createOutput(
|
||||
overrides: Partial<ExecutedWsMessage['output']> = {}
|
||||
): ExecutedWsMessage['output'] {
|
||||
return { ...overrides }
|
||||
}
|
||||
|
||||
describe('isAnimatedOutput', () => {
|
||||
it('returns false for undefined output', () => {
|
||||
expect(isAnimatedOutput(undefined)).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when animated array is missing', () => {
|
||||
expect(isAnimatedOutput(createOutput())).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when all animated values are false', () => {
|
||||
expect(isAnimatedOutput(createOutput({ animated: [false, false] }))).toBe(
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
it('returns true when any animated value is true', () => {
|
||||
expect(isAnimatedOutput(createOutput({ animated: [false, true] }))).toBe(
|
||||
true
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isVideoOutput', () => {
|
||||
it('returns false for non-animated output', () => {
|
||||
expect(
|
||||
isVideoOutput(
|
||||
createOutput({
|
||||
animated: [false],
|
||||
images: [{ filename: 'video.webm' }]
|
||||
})
|
||||
)
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for animated webp output', () => {
|
||||
expect(
|
||||
isVideoOutput(
|
||||
createOutput({
|
||||
animated: [true],
|
||||
images: [{ filename: 'anim.webp' }]
|
||||
})
|
||||
)
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for animated png output', () => {
|
||||
expect(
|
||||
isVideoOutput(
|
||||
createOutput({
|
||||
animated: [true],
|
||||
images: [{ filename: 'anim.png' }]
|
||||
})
|
||||
)
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('returns true for animated webm output', () => {
|
||||
expect(
|
||||
isVideoOutput(
|
||||
createOutput({
|
||||
animated: [true],
|
||||
images: [{ filename: 'output.webm' }]
|
||||
})
|
||||
)
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('returns true for animated mp4 output', () => {
|
||||
expect(
|
||||
isVideoOutput(
|
||||
createOutput({
|
||||
animated: [true],
|
||||
images: [{ filename: 'output.mp4' }]
|
||||
})
|
||||
)
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('returns true for animated output with no images array', () => {
|
||||
expect(isVideoOutput(createOutput({ animated: [true] }))).toBe(true)
|
||||
})
|
||||
|
||||
it('does not false-positive on filenames containing webp as substring', () => {
|
||||
expect(
|
||||
isVideoOutput(
|
||||
createOutput({
|
||||
animated: [true],
|
||||
images: [{ filename: 'my_webp_file.mp4' }]
|
||||
})
|
||||
)
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('compressWidgetInputSlots', () => {
|
||||
it('should remove unconnected widget input slots', () => {
|
||||
// Using partial mock - only including properties needed for test
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
LGraph,
|
||||
LGraphCanvas
|
||||
} from '@/lib/litegraph/src/litegraph'
|
||||
import type { ExecutedWsMessage } from '@/schemas/apiSchema'
|
||||
import {
|
||||
LGraphGroup,
|
||||
LGraphNode,
|
||||
@@ -77,6 +78,32 @@ export function isVideoNode(node: LGraphNode | undefined): node is VideoNode {
|
||||
return node.previewMediaType === 'video' || !!node.videoContainer
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if output data indicates animated content (animated webp/png or video).
|
||||
*/
|
||||
export function isAnimatedOutput(
|
||||
output: ExecutedWsMessage['output'] | undefined
|
||||
): boolean {
|
||||
return !!output?.animated?.find(Boolean)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if output data indicates video content (animated but not webp/png).
|
||||
*/
|
||||
export function isVideoOutput(
|
||||
output: ExecutedWsMessage['output'] | undefined
|
||||
): boolean {
|
||||
if (!isAnimatedOutput(output)) return false
|
||||
|
||||
const isAnimatedWebp = output?.images?.some((img) =>
|
||||
img.filename?.endsWith('.webp')
|
||||
)
|
||||
const isAnimatedPng = output?.images?.some((img) =>
|
||||
img.filename?.endsWith('.png')
|
||||
)
|
||||
return !isAnimatedWebp && !isAnimatedPng
|
||||
}
|
||||
|
||||
export function isAudioNode(node: LGraphNode | undefined): boolean {
|
||||
return !!node && node.previewMediaType === 'audio'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user