Skip to content

load_video

Load image definition.

VideoLoader

Bases: ComfyUILoader

Load video.

Source code in client/ayon_comfyui/plugins/load/load_video.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class VideoLoader(ComfyUILoader):
    """Load video."""

    product_types: ClassVar[set[str]] = {"video"}
    representations: ClassVar[set[str]] = {"mp4", "mov", "webm"}
    label = "Load video into current graph."
    icon = "image"
    order = -10.1

    def load(
        self,
        context: dict,
        name: str | None = None,
        namespace: str | None = None,
        options: dict | None = None,
    ) -> None:
        """Load asset via database.

        Arguments:
            context (dict): Full parenthood of representation to load
            name (str, optional): Use pre-defined name
            namespace (str, optional): Use pre-defined namespace
            options (dict, optional): Additional settings dictionary
        """
        # Retrieve filepath
        filepaths = self.filepath_from_context(context=context)
        self.log.debug(filepaths)
        folder = f"{namespace}_{name}" if namespace else name
        # Upload video to ComfyUI.

        image_upload_info = upload_input_images(
            [filepaths], self.comfy_url, subfolder=folder
        )
        # containerizing also adds to context.
        container: dict = containerise(
            name=name,
            namespace=namespace,
            context=context,
            image_upload_info=image_upload_info,
            loader=self.__class__.__name__,
        )

        # Create the video loader node with the data on it.
        self.stub.create_load_node(container, LoadType.VIDEO)

    def remove(self, container: dict) -> None:
        """Remove container from context and scene."""
        self.stub.remove_containers(container)
        self.stub.remove_load_nodes(container, LoadType.VIDEO)

    def update(self, container: dict, context: dict) -> None:
        """Update container with new uploded file."""
        # Retrieve filepaths
        # filepath = self.filepath_from_context(context=context)
        filepaths = [self.filepath_from_context(context=context)]
        # Upload video to ComfyUI.
        old_subfolder = next(iter(container["image_upload_info"]))["subfolder"]

        image_upload_info = upload_input_images(
            filepaths, self.comfy_url, subfolder=old_subfolder
        )

        container["representation"] = context["representation"]["id"]
        container["image_upload_info"] = image_upload_info

        self.stub.update_containers(container)

    def switch(self, container: dict, context: dict) -> None:
        """Provide interface for switching calls."""
        self.update(container=container, context=context)

    # Maybe deprecate. should be singular.
    def expand_files_if_sequence(self, context: dict) -> list[str]:
        """Return all images in sequence if appliccable."""
        filepath = self.filepath_from_context(context=context)
        basename = os.path.basename(filepath)
        filedir = os.path.dirname(filepath)
        files = [f for f in os.listdir(filedir) if not os.path.isdir(f)]

        collections, _ = clique.assemble(files)
        collections: list[clique.Collection]
        for collection in collections:
            if collection.match(basename):
                return [os.path.join(filedir, f) for f in collection]
        return [filepath]

expand_files_if_sequence(context)

Return all images in sequence if appliccable.

Source code in client/ayon_comfyui/plugins/load/load_video.py
87
88
89
90
91
92
93
94
95
96
97
98
99
def expand_files_if_sequence(self, context: dict) -> list[str]:
    """Return all images in sequence if appliccable."""
    filepath = self.filepath_from_context(context=context)
    basename = os.path.basename(filepath)
    filedir = os.path.dirname(filepath)
    files = [f for f in os.listdir(filedir) if not os.path.isdir(f)]

    collections, _ = clique.assemble(files)
    collections: list[clique.Collection]
    for collection in collections:
        if collection.match(basename):
            return [os.path.join(filedir, f) for f in collection]
    return [filepath]

load(context, name=None, namespace=None, options=None)

Load asset via database.

Parameters:

Name Type Description Default
context dict

Full parenthood of representation to load

required
name str

Use pre-defined name

None
namespace str

Use pre-defined namespace

None
options dict

Additional settings dictionary

None
Source code in client/ayon_comfyui/plugins/load/load_video.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def load(
    self,
    context: dict,
    name: str | None = None,
    namespace: str | None = None,
    options: dict | None = None,
) -> None:
    """Load asset via database.

    Arguments:
        context (dict): Full parenthood of representation to load
        name (str, optional): Use pre-defined name
        namespace (str, optional): Use pre-defined namespace
        options (dict, optional): Additional settings dictionary
    """
    # Retrieve filepath
    filepaths = self.filepath_from_context(context=context)
    self.log.debug(filepaths)
    folder = f"{namespace}_{name}" if namespace else name
    # Upload video to ComfyUI.

    image_upload_info = upload_input_images(
        [filepaths], self.comfy_url, subfolder=folder
    )
    # containerizing also adds to context.
    container: dict = containerise(
        name=name,
        namespace=namespace,
        context=context,
        image_upload_info=image_upload_info,
        loader=self.__class__.__name__,
    )

    # Create the video loader node with the data on it.
    self.stub.create_load_node(container, LoadType.VIDEO)

remove(container)

Remove container from context and scene.

Source code in client/ayon_comfyui/plugins/load/load_video.py
60
61
62
63
def remove(self, container: dict) -> None:
    """Remove container from context and scene."""
    self.stub.remove_containers(container)
    self.stub.remove_load_nodes(container, LoadType.VIDEO)

switch(container, context)

Provide interface for switching calls.

Source code in client/ayon_comfyui/plugins/load/load_video.py
82
83
84
def switch(self, container: dict, context: dict) -> None:
    """Provide interface for switching calls."""
    self.update(container=container, context=context)

update(container, context)

Update container with new uploded file.

Source code in client/ayon_comfyui/plugins/load/load_video.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def update(self, container: dict, context: dict) -> None:
    """Update container with new uploded file."""
    # Retrieve filepaths
    # filepath = self.filepath_from_context(context=context)
    filepaths = [self.filepath_from_context(context=context)]
    # Upload video to ComfyUI.
    old_subfolder = next(iter(container["image_upload_info"]))["subfolder"]

    image_upload_info = upload_input_images(
        filepaths, self.comfy_url, subfolder=old_subfolder
    )

    container["representation"] = context["representation"]["id"]
    container["image_upload_info"] = image_upload_info

    self.stub.update_containers(container)