# moonhugo/comfyui-ffmpeg architecture

> Architecture diagram of the GitHub repository moonhugo/comfyui-ffmpeg, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moonhugo/comfyui-ffmpeg
- Repository: https://github.com/moonhugo/comfyui-ffmpeg

## Overview

1. This repository is a ComfyUI custom-node extension that wraps common FFmpeg workflows as discrete nodes. The architecture is “node-first”: each feature is exposed as a separate ComfyUI node rather than as a monolithic app.

2. The package entry points are `__init__.py` and `nodes_map.py`. Together they likely register node classes, display names, input/output types, and the mapping ComfyUI uses to discover the extension at startup.

3. The `nodes/` directory is the main functional layer. Each file implements one operation: video-to-frames, frames-to-video, audio extraction, audio muxing, watermarking, stitching, concatenation, cutting, flipping, playback/reversal, transitions, picture-in-picture, and image utilities.

4. The core data flow is file-based. Almost every node accepts local file paths and writes a new media file or image sequence to `output_path`. Intermediate data is usually persisted on disk rather than passed in memory, which keeps the nodes composable in ComfyUI workflows.

5. FFmpeg is the primary execution backend. The README makes it clear that FFmpeg must be installed separately; these nodes are essentially convenience wrappers around FFmpeg commands and filters, including xfade-based transitions, trimming, merging, and audio/video stream handling.

6. A second data path exists for image/tensor integration with ComfyUI. Files such as `imagePath2Tensor.py`, `loadImageFromDir.py`, `imagesSave.py`, and `imageCopy.py` indicate conversion between filesystem images and ComfyUI image tensors, allowing FFmpeg workflows to connect to image-generation pipelines.

7. Video processing nodes break into a few functional groups:
   - frame extraction and reconstruction: `video2frames.py`, `frames2video.py`
   - cutting and concatenation: `singleCuttingVideo.py`, `multiCuttingVideo.py`, `mergingVideoByTwo.py`, `mergingVideoByPlenty.py`
   - compositing and effects: `stitchingVideo.py`, `pipVideo.py`, `videoTransition.py`, `videoFlip.py`, `videoPlayback.py`
   - audio handling: `extractAudio.py`, `addAudio.py`
   - overlays: `addTextWatermark.py`, `addImgWatermark.py`

8. Several nodes depend on FFmpeg filter behavior and codec compatibility. The README highlights CPU/GPU selection for some operations, aspect-ratio and scaling handling, and keyframe-based cutting constraints. That means the architecture is not purely cosmetic; it exposes FFmpeg’s media-encoding boundaries directly to users.

9. The repository includes `fonts/` and `assets/` as supporting resources. `fonts/` is used for text watermarking with user-supplied font files, while `assets/` stores screenshots for documentation and does not affect runtime behavior.

10. `func.py` is likely the shared utility layer. Based on the repo shape, it probably contains common helpers such as command assembly, path handling, validation, and subprocess execution, reducing duplication across the individual node modules.

11. `requirements.txt` appears to cover only the Python-side dependencies needed by ComfyUI integration and any helper libraries. The heavy lifting remains external through the FFmpeg binary, so the runtime boundary is split between Python/ComfyUI and the installed system FFmpeg toolchain.

12. The repository has no evidence of a server, database, queue, or background worker system. The architecture is local and synchronous from a user perspective: a ComfyUI graph triggers a node, the node runs FFmpeg on local media files, and the result is written back to disk for downstream nodes or manual use.

13. For an architecture diagram, the key boundaries are:
   - ComfyUI host application
   - this custom-node package as the extension layer
   - FFmpeg as the external media-processing engine
   - local filesystem as the shared interchange medium
   - optional image-tensor bridge for ComfyUI image workflows

Main entry points: [`nodes/__init__.py`](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/__init__.py) (nodes pkg), [`nodes/imagePath2Tensor.py`](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/imagePath2Tensor.py) (Image to tensor), [`__init__.py`](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/__init__.py) (__init__), [`nodes/video2frames.py`](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/video2frames.py) (Video to frames)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_comfyui["ComfyUI<br/>host app"]
  node_filesystem[("Files<br/>local storage")]
  node_ffmpeg{{"FFmpeg<br/>media engine"}}
end

subgraph group_package["Extension"]
  node_init["__init__<br/>entry point<br/>[__init__.py]"]
  node_nodes_map["Nodes map<br/>registry map<br/>[nodes_map.py]"]
  node_nodes_init["nodes pkg<br/>module init<br/>[__init__.py]"]
  node_func["Helpers<br/>shared utils<br/>[func.py]"]
end

subgraph group_media["Media Nodes"]
  node_video2frames["Video to frames<br/>frame extractor<br/>[video2frames.py]"]
  node_frames2video["Frames to video<br/>video encoder<br/>[frames2video.py]"]
  node_cutting["Cut video<br/>trim node"]
  node_merge_many["Merge videos<br/>concat node"]
  node_add_audio["Add audio<br/>mux node<br/>[addAudio.py]"]
  node_text_watermark["Text watermark<br/>overlay node"]
  node_transition["Transition<br/>xfade node<br/>[videoTransition.py]"]
  node_pip["Picture-in-picture<br/>compositing node<br/>[pipVideo.py]"]
end

subgraph group_bridge["Image Bridge"]
  node_img2tensor["Image to tensor<br/>bridge node"]
  node_load_dir["Load images<br/>directory loader"]
  node_save_images["Save images<br/>image exporter<br/>[imagesSave.py]"]
  node_copy_image["Copy image<br/>file utility<br/>[imageCopy.py]"]
end

subgraph group_support["Resources"]
  node_fonts["Fonts<br/>resource dir"]
end

node_comfyui -->|"loads"| node_init
node_init -->|"registers"| node_nodes_map
node_init -->|"imports"| node_nodes_init
node_nodes_map -->|"maps"| node_nodes_init
node_nodes_init -->|"exposes"| node_video2frames
node_nodes_init -->|"exposes"| node_frames2video
node_nodes_init -->|"exposes"| node_cutting
node_nodes_init -->|"exposes"| node_merge_many
node_nodes_init -->|"exposes"| node_add_audio
node_nodes_init -->|"exposes"| node_text_watermark
node_nodes_init -->|"exposes"| node_transition
node_nodes_init -->|"exposes"| node_pip
node_nodes_init -->|"exposes"| node_img2tensor
node_nodes_init -->|"exposes"| node_load_dir
node_nodes_init -->|"exposes"| node_save_images
node_nodes_init -->|"exposes"| node_copy_image
node_video2frames -->|"runs"| node_ffmpeg
node_frames2video -->|"runs"| node_ffmpeg
node_cutting -->|"runs"| node_ffmpeg
node_merge_many -->|"runs"| node_ffmpeg
node_add_audio -->|"runs"| node_ffmpeg
node_text_watermark -->|"runs"| node_ffmpeg
node_transition -->|"runs"| node_ffmpeg
node_pip -->|"runs"| node_ffmpeg
node_video2frames -->|"reads/writes"| node_filesystem
node_frames2video -->|"reads/writes"| node_filesystem
node_cutting -->|"reads/writes"| node_filesystem
node_merge_many -->|"reads/writes"| node_filesystem
node_add_audio -->|"reads/writes"| node_filesystem
node_text_watermark -->|"uses"| node_fonts
node_img2tensor -->|"reads"| node_filesystem
node_load_dir -->|"reads"| node_filesystem
node_save_images -->|"writes"| node_filesystem
node_copy_image -->|"reads/writes"| node_filesystem
node_save_images -->|"feeds"| node_img2tensor
node_load_dir -->|"feeds"| node_img2tensor

click node_init "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/__init__.py"
click node_nodes_map "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes_map.py"
click node_nodes_init "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/__init__.py"
click node_func "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/func.py"
click node_video2frames "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/video2frames.py"
click node_frames2video "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/frames2video.py"
click node_cutting "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/singleCuttingVideo.py"
click node_merge_many "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/mergingVideoByPlenty.py"
click node_add_audio "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/addAudio.py"
click node_text_watermark "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/addTextWatermark.py"
click node_transition "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/videoTransition.py"
click node_pip "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/pipVideo.py"
click node_img2tensor "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/imagePath2Tensor.py"
click node_load_dir "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/loadImageFromDir.py"
click node_save_images "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/imagesSave.py"
click node_copy_image "https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/imageCopy.py"
click node_fonts "https://github.com/moonhugo/comfyui-ffmpeg/tree/main/fonts/put_fontfile_here"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_comfyui,node_filesystem,node_ffmpeg toneBlue
class node_init,node_nodes_map,node_nodes_init,node_func toneAmber
class node_video2frames,node_frames2video,node_cutting,node_merge_many,node_add_audio,node_text_watermark,node_transition,node_pip toneMint
class node_img2tensor,node_load_dir,node_save_images,node_copy_image toneRose
class node_fonts toneIndigo
```

## Components

### Runtime

External execution boundaries and shared storage.

- **ComfyUI**: host app · The host application that loads the custom node extension.
- **Files**: local storage · Shared on-disk interchange for media and image sequences.
- **FFmpeg**: media engine · External binary used for encoding, filtering, trimming, muxing, and transitions.

### Extension

ComfyUI package entry points and shared helpers.

- [__init__](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/__init__.py): entry point · Package startup hook for ComfyUI node registration. · `__init__.py`
- [Nodes map](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes_map.py): registry map · Node class and display-name mapping used by ComfyUI discovery. · `nodes_map.py`
- [nodes pkg](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/__init__.py): module init · Nodes package initializer for the functional node modules. · `nodes/__init__.py`
- [Helpers](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/func.py): shared utils · Common helper layer for command assembly, validation, and process handling. · `func.py`

### Media Nodes

Core FFmpeg-backed video and audio operations.

- [Video to frames](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/video2frames.py): frame extractor · Splits a video into an image sequence. · `nodes/video2frames.py`
- [Frames to video](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/frames2video.py): video encoder · Reconstructs a video from frame images. · `nodes/frames2video.py`
- [Cut video](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/singleCuttingVideo.py): trim node · Single-video cutting and segment extraction. · `nodes/singleCuttingVideo.py`
- [Merge videos](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/mergingVideoByPlenty.py): concat node · Combines multiple videos into one output. · `nodes/mergingVideoByPlenty.py`
- [Add audio](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/addAudio.py): mux node · Adds or replaces audio in a video stream. · `nodes/addAudio.py`
- [Text watermark](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/addTextWatermark.py): overlay node · Renders text onto video using font resources. · `nodes/addTextWatermark.py`
- [Transition](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/videoTransition.py): xfade node · Creates transitions between video clips. · `nodes/videoTransition.py`
- [Picture-in-picture](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/pipVideo.py): compositing node · Overlays one video inside another. · `nodes/pipVideo.py`

### Image Bridge

Nodes that convert between filesystem images and ComfyUI tensors.

- [Image to tensor](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/imagePath2Tensor.py): bridge node · Loads filesystem images into ComfyUI image tensors. · `nodes/imagePath2Tensor.py`
- [Load images](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/loadImageFromDir.py): directory loader · Reads images from a directory for ComfyUI workflows. · `nodes/loadImageFromDir.py`
- [Save images](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/imagesSave.py): image exporter · Writes ComfyUI images back to disk. · `nodes/imagesSave.py`
- [Copy image](https://github.com/moonhugo/comfyui-ffmpeg/blob/main/nodes/imageCopy.py): file utility · Replicates image files within the local workflow storage. · `nodes/imageCopy.py`

### Resources

Static resources used by the extension.

- [Fonts](https://github.com/moonhugo/comfyui-ffmpeg/tree/main/fonts/put_fontfile_here): resource dir · Font assets used by text watermarking. · `fonts/put_fontfile_here`

## Connections

- ComfyUI → __init__: loads · ComfyUI loads the extension entry point at startup.
- __init__ → Nodes map: registers · Entry point exposes node registration metadata.
- __init__ → nodes pkg: imports · Package init brings in the node module set.
- Nodes map → nodes pkg: maps · Registry map points ComfyUI at the node implementations.
- nodes pkg → Video to frames: exposes · Package initializer surfaces the media nodes.
- nodes pkg → Frames to video: exposes · Package initializer surfaces the media nodes.
- nodes pkg → Cut video: exposes · Package initializer surfaces the media nodes.
- nodes pkg → Merge videos: exposes · Package initializer surfaces the media nodes.
- nodes pkg → Add audio: exposes · Package initializer surfaces the media nodes.
- nodes pkg → Text watermark: exposes · Package initializer surfaces the media nodes.
- nodes pkg → Transition: exposes · Package initializer surfaces the media nodes.
- nodes pkg → Picture-in-picture: exposes · Package initializer surfaces the media nodes.
- nodes pkg → Image to tensor: exposes · Package initializer surfaces the bridge nodes.
- nodes pkg → Load images: exposes · Package initializer surfaces the bridge nodes.
- nodes pkg → Save images: exposes · Package initializer surfaces the bridge nodes.
- nodes pkg → Copy image: exposes · Package initializer surfaces the bridge nodes.
- Video to frames → FFmpeg: runs · Frame extraction delegates to FFmpeg.
- Frames to video → FFmpeg: runs · Video reconstruction delegates to FFmpeg.
- Cut video → FFmpeg: runs · Cutting and trimming use FFmpeg filters and seek behavior.
- Merge videos → FFmpeg: runs · Concatenation and merging use FFmpeg.
- Add audio → FFmpeg: runs · Audio muxing delegates to FFmpeg stream handling.
- Text watermark → FFmpeg: runs · Text overlay uses FFmpeg filter graphs.
- Transition → FFmpeg: runs · Transitions rely on FFmpeg xfade-style processing.
- Picture-in-picture → FFmpeg: runs · Picture-in-picture composition is executed by FFmpeg.
- Video to frames → Files: reads/writes · Consumes a source video and writes extracted frames.
- Frames to video → Files: reads/writes · Consumes frame images and writes a video file.
- Cut video → Files: reads/writes · Reads local media and persists trimmed output.
- Merge videos → Files: reads/writes · Reads multiple inputs and writes a merged video.
- Add audio → Files: reads/writes · Reads input media and emits muxed output.
- Text watermark → Fonts: uses · Text watermarking depends on font files.
- Image to tensor → Files: reads · Loads images from disk into ComfyUI tensors.
- Load images → Files: reads · Scans a directory of images from local storage.
- Save images → Files: writes · Persists generated images to disk.
- Copy image → Files: reads/writes · Copies image files within local storage.
- Save images → Image to tensor: feeds · Image tensors can be saved then reloaded through the bridge.
- Load images → Image to tensor: feeds · Directory images are converted into tensors for workflows.
