How moonhugo/comfyui-ffmpeg works
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 nodes pkg · imagePath2Tensor.py Image to tensor · __init__.py __init__ · video2frames.py Video to frames
Components 20
Runtime
External execution boundaries and shared storage.
- ComfyUI · The host application that loads the custom node extension.
- Files · Shared on-disk interchange for media and image sequences.
- FFmpeg · External binary used for encoding, filtering, trimming, muxing, and transitions.
Extension
ComfyUI package entry points and shared helpers.
- __init__ · Package startup hook for ComfyUI node registration.
__init__.py - Nodes map · Node class and display-name mapping used by ComfyUI discovery.
nodes_map.py - nodes pkg · Nodes package initializer for the functional node modules.
nodes/__init__.py - Helpers · Common helper layer for command assembly, validation, and process handling.
func.py
Media Nodes
Core FFmpeg-backed video and audio operations.
- Video to frames · Splits a video into an image sequence.
nodes/video2frames.py - Frames to video · Reconstructs a video from frame images.
nodes/frames2video.py - Cut video · Single-video cutting and segment extraction.
nodes/singleCuttingVideo.py - Merge videos · Combines multiple videos into one output.
nodes/mergingVideoByPlenty.py - Add audio · Adds or replaces audio in a video stream.
nodes/addAudio.py - Text watermark · Renders text onto video using font resources.
nodes/addTextWatermark.py - Transition · Creates transitions between video clips.
nodes/videoTransition.py - Picture-in-picture · Overlays one video inside another.
nodes/pipVideo.py
Image Bridge
Nodes that convert between filesystem images and ComfyUI tensors.
- Image to tensor · Loads filesystem images into ComfyUI image tensors.
nodes/imagePath2Tensor.py - Load images · Reads images from a directory for ComfyUI workflows.
nodes/loadImageFromDir.py - Save images · Writes ComfyUI images back to disk.
nodes/imagesSave.py - Copy image · Replicates image files within the local workflow storage.
nodes/imageCopy.py
Resources
Static resources used by the extension.
- Fonts · Font assets used by text watermarking.
fonts/put_fontfile_here
Connections 36
- 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.