mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-09-15 14:09:28 +00:00
Merge branch 'v3-definition' into js/extension-api-example
This commit is contained in:
@@ -10,7 +10,7 @@ from comfy_api.latest._input_impl import VideoFromFile, VideoFromComponents
|
||||
from comfy_api.latest._util import VideoCodec, VideoContainer, VideoComponents
|
||||
from comfy_api.latest._io import _IO as io #noqa: F401
|
||||
from comfy_api.latest._ui import _UI as ui #noqa: F401
|
||||
from comfy_api.latest._resources import _RESOURCES as resources #noqa: F401
|
||||
# from comfy_api.latest._resources import _RESOURCES as resources #noqa: F401
|
||||
from comfy_execution.utils import get_executing_context
|
||||
from comfy_execution.progress import get_progress_state, PreviewImageTuple
|
||||
from PIL import Image
|
||||
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional, Union
|
||||
import io
|
||||
import av
|
||||
from comfy_api.util import VideoContainer, VideoCodec, VideoComponents
|
||||
|
||||
class VideoInput(ABC):
|
||||
@@ -70,3 +71,15 @@ class VideoInput(ABC):
|
||||
components = self.get_components()
|
||||
frame_count = components.images.shape[0]
|
||||
return float(frame_count / components.frame_rate)
|
||||
|
||||
def get_container_format(self) -> str:
|
||||
"""
|
||||
Returns the container format of the video (e.g., 'mp4', 'mov', 'avi').
|
||||
|
||||
Returns:
|
||||
Container format as string
|
||||
"""
|
||||
# Default implementation - subclasses should override for better performance
|
||||
source = self.get_stream_source()
|
||||
with av.open(source, mode="r") as container:
|
||||
return container.format.name
|
||||
|
@@ -120,6 +120,18 @@ class VideoFromFile(VideoInput):
|
||||
|
||||
raise ValueError(f"Could not determine duration for file '{self.__file}'")
|
||||
|
||||
def get_container_format(self) -> str:
|
||||
"""
|
||||
Returns the container format of the video (e.g., 'mp4', 'mov', 'avi').
|
||||
|
||||
Returns:
|
||||
Container format as string
|
||||
"""
|
||||
if isinstance(self.__file, io.BytesIO):
|
||||
self.__file.seek(0)
|
||||
with av.open(self.__file, mode='r') as container:
|
||||
return container.format.name
|
||||
|
||||
def get_components_internal(self, container: InputContainer) -> VideoComponents:
|
||||
# Get video frames
|
||||
frames = []
|
||||
|
@@ -6,26 +6,27 @@ from abc import ABC, abstractmethod
|
||||
from collections import Counter
|
||||
from dataclasses import asdict, dataclass
|
||||
from enum import Enum
|
||||
from typing import Any, Callable, Literal, TypedDict, TypeVar
|
||||
from typing import Any, Callable, Literal, TypedDict, TypeVar, TYPE_CHECKING
|
||||
from typing_extensions import NotRequired, final
|
||||
|
||||
# used for type hinting
|
||||
import torch
|
||||
from spandrel import ImageModelDescriptor
|
||||
from typing_extensions import NotRequired, final
|
||||
|
||||
from comfy.clip_vision import ClipVisionModel
|
||||
from comfy.clip_vision import Output as ClipVisionOutput_
|
||||
from comfy.controlnet import ControlNet
|
||||
from comfy.hooks import HookGroup, HookKeyframeGroup
|
||||
from comfy.model_patcher import ModelPatcher
|
||||
from comfy.samplers import CFGGuider, Sampler
|
||||
from comfy.sd import CLIP, VAE
|
||||
from comfy.sd import StyleModel as StyleModel_
|
||||
from comfy_api.input import VideoInput
|
||||
if TYPE_CHECKING:
|
||||
from spandrel import ImageModelDescriptor
|
||||
from comfy.clip_vision import ClipVisionModel
|
||||
from comfy.clip_vision import Output as ClipVisionOutput_
|
||||
from comfy.controlnet import ControlNet
|
||||
from comfy.hooks import HookGroup, HookKeyframeGroup
|
||||
from comfy.model_patcher import ModelPatcher
|
||||
from comfy.samplers import CFGGuider, Sampler
|
||||
from comfy.sd import CLIP, VAE
|
||||
from comfy.sd import StyleModel as StyleModel_
|
||||
from comfy_api.input import VideoInput
|
||||
from comfy_api.internal import (_ComfyNodeInternal, _NodeOutputInternal, classproperty, copy_class, first_real_override, is_class,
|
||||
prune_dict, shallow_clone_class)
|
||||
from comfy_api.latest._resources import Resources, ResourcesLocal
|
||||
from comfy_execution.graph import ExecutionBlocker
|
||||
from comfy_execution.graph_utils import ExecutionBlocker
|
||||
|
||||
# from comfy_extras.nodes_images import SVG as SVG_ # NOTE: needs to be moved before can be imported due to circular reference
|
||||
|
||||
@@ -543,7 +544,8 @@ class Conditioning(ComfyTypeIO):
|
||||
|
||||
@comfytype(io_type="SAMPLER")
|
||||
class Sampler(ComfyTypeIO):
|
||||
Type = Sampler
|
||||
if TYPE_CHECKING:
|
||||
Type = Sampler
|
||||
|
||||
@comfytype(io_type="SIGMAS")
|
||||
class Sigmas(ComfyTypeIO):
|
||||
@@ -555,44 +557,54 @@ class Noise(ComfyTypeIO):
|
||||
|
||||
@comfytype(io_type="GUIDER")
|
||||
class Guider(ComfyTypeIO):
|
||||
Type = CFGGuider
|
||||
if TYPE_CHECKING:
|
||||
Type = CFGGuider
|
||||
|
||||
@comfytype(io_type="CLIP")
|
||||
class Clip(ComfyTypeIO):
|
||||
Type = CLIP
|
||||
if TYPE_CHECKING:
|
||||
Type = CLIP
|
||||
|
||||
@comfytype(io_type="CONTROL_NET")
|
||||
class ControlNet(ComfyTypeIO):
|
||||
Type = ControlNet
|
||||
if TYPE_CHECKING:
|
||||
Type = ControlNet
|
||||
|
||||
@comfytype(io_type="VAE")
|
||||
class Vae(ComfyTypeIO):
|
||||
Type = VAE
|
||||
if TYPE_CHECKING:
|
||||
Type = VAE
|
||||
|
||||
@comfytype(io_type="MODEL")
|
||||
class Model(ComfyTypeIO):
|
||||
Type = ModelPatcher
|
||||
if TYPE_CHECKING:
|
||||
Type = ModelPatcher
|
||||
|
||||
@comfytype(io_type="CLIP_VISION")
|
||||
class ClipVision(ComfyTypeIO):
|
||||
Type = ClipVisionModel
|
||||
if TYPE_CHECKING:
|
||||
Type = ClipVisionModel
|
||||
|
||||
@comfytype(io_type="CLIP_VISION_OUTPUT")
|
||||
class ClipVisionOutput(ComfyTypeIO):
|
||||
Type = ClipVisionOutput_
|
||||
if TYPE_CHECKING:
|
||||
Type = ClipVisionOutput_
|
||||
|
||||
@comfytype(io_type="STYLE_MODEL")
|
||||
class StyleModel(ComfyTypeIO):
|
||||
Type = StyleModel_
|
||||
if TYPE_CHECKING:
|
||||
Type = StyleModel_
|
||||
|
||||
@comfytype(io_type="GLIGEN")
|
||||
class Gligen(ComfyTypeIO):
|
||||
'''ModelPatcher that wraps around a 'Gligen' model.'''
|
||||
Type = ModelPatcher
|
||||
if TYPE_CHECKING:
|
||||
Type = ModelPatcher
|
||||
|
||||
@comfytype(io_type="UPSCALE_MODEL")
|
||||
class UpscaleModel(ComfyTypeIO):
|
||||
Type = ImageModelDescriptor
|
||||
if TYPE_CHECKING:
|
||||
Type = ImageModelDescriptor
|
||||
|
||||
@comfytype(io_type="AUDIO")
|
||||
class Audio(ComfyTypeIO):
|
||||
@@ -603,7 +615,8 @@ class Audio(ComfyTypeIO):
|
||||
|
||||
@comfytype(io_type="VIDEO")
|
||||
class Video(ComfyTypeIO):
|
||||
Type = VideoInput
|
||||
if TYPE_CHECKING:
|
||||
Type = VideoInput
|
||||
|
||||
@comfytype(io_type="SVG")
|
||||
class SVG(ComfyTypeIO):
|
||||
@@ -629,11 +642,13 @@ class Mesh(ComfyTypeIO):
|
||||
|
||||
@comfytype(io_type="HOOKS")
|
||||
class Hooks(ComfyTypeIO):
|
||||
Type = HookGroup
|
||||
if TYPE_CHECKING:
|
||||
Type = HookGroup
|
||||
|
||||
@comfytype(io_type="HOOK_KEYFRAMES")
|
||||
class HookKeyframes(ComfyTypeIO):
|
||||
Type = HookKeyframeGroup
|
||||
if TYPE_CHECKING:
|
||||
Type = HookKeyframeGroup
|
||||
|
||||
@comfytype(io_type="TIMESTEPS_RANGE")
|
||||
class TimestepsRange(ComfyTypeIO):
|
||||
|
@@ -6,7 +6,7 @@ from comfy_api.latest import (
|
||||
)
|
||||
from typing import Type, TYPE_CHECKING
|
||||
from comfy_api.internal.async_to_sync import create_sync_class
|
||||
from comfy_api.latest import io, ui, resources #noqa: F401
|
||||
from comfy_api.latest import io, ui #noqa: F401
|
||||
|
||||
|
||||
class ComfyAPIAdapter_v0_0_2(ComfyAPI_latest):
|
||||
|
Reference in New Issue
Block a user