comfyui-video-denoise 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- comfyui_video_denoise-0.1.0/LICENSE +21 -0
- comfyui_video_denoise-0.1.0/PKG-INFO +482 -0
- comfyui_video_denoise-0.1.0/README.md +443 -0
- comfyui_video_denoise-0.1.0/THIRD_PARTY_NOTICES.txt +43 -0
- comfyui_video_denoise-0.1.0/pyproject.toml +169 -0
- comfyui_video_denoise-0.1.0/pyproject.toml.orig +148 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/__init__.py +20 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/cli.py +687 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/comfy_client.py +188 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/config.py +80 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/identity.py +261 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/install.py +115 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/metrics.py +717 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/nodes.py +272 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/py.typed +0 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/raft.py +36 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/review.py +448 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/stabilize.py +274 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/stabilize_video.py +487 -0
- comfyui_video_denoise-0.1.0/src/comfyui_video_denoise/video.py +801 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Max
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: comfyui-video-denoise
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Denoising and restoration tools for noisy video: a RAFT motion-compensated temporal stabilizer, evaluation metrics, review videos and ComfyUI nodes.
|
|
5
|
+
Keywords: comfyui,video,denoising,video denoising,restoration,temporal stabilization,optical flow,raft,pytorch
|
|
6
|
+
Author: Max
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: THIRD_PARTY_NOTICES.txt
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Multimedia :: Video
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Dist: numpy>=1.26
|
|
25
|
+
Requires-Dist: torch>=2.4
|
|
26
|
+
Requires-Dist: torchvision>=0.19
|
|
27
|
+
Requires-Dist: comfyui-video-denoise[metrics,identity] ; extra == 'all'
|
|
28
|
+
Requires-Dist: opencv-python-headless>=4.10.0.84 ; extra == 'identity'
|
|
29
|
+
Requires-Dist: onnxruntime>=1.19 ; extra == 'identity'
|
|
30
|
+
Requires-Dist: opencv-python-headless>=4.10.0.84 ; extra == 'metrics'
|
|
31
|
+
Requires-Python: >=3.12
|
|
32
|
+
Project-URL: Source, https://github.com/mxlei01/comfyui-video-denoise
|
|
33
|
+
Project-URL: Issues, https://github.com/mxlei01/comfyui-video-denoise/issues
|
|
34
|
+
Project-URL: Changelog, https://github.com/mxlei01/comfyui-video-denoise/blob/master/CHANGELOG.md
|
|
35
|
+
Provides-Extra: all
|
|
36
|
+
Provides-Extra: identity
|
|
37
|
+
Provides-Extra: metrics
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# comfyui-video-denoise
|
|
41
|
+
|
|
42
|
+
Denoising and restoration tools for noisy video. They work as a Python package, as the `comfyui-video-denoise` command
|
|
43
|
+
and as ComfyUI nodes:
|
|
44
|
+
|
|
45
|
+
- **Temporal stabilizer.** Every frame is averaged with its motion-aligned neighbours.
|
|
46
|
+
- The motion comes from RAFT optical flow (RAFT-large with torchvision's weights), measured on a reference: the
|
|
47
|
+
original the frames were made from, or the frames themselves.
|
|
48
|
+
- The averaging is mismatch-weighted: per pixel, each aligned neighbour is weighted by a Gaussian (of width sigma,
|
|
49
|
+
in 8-bit levels) of how far it differs from the frame in the reference's blurred luma, and is left out where the
|
|
50
|
+
forward and backward flow disagree. Moving or occluded parts therefore fall back to the frame itself and do not
|
|
51
|
+
ghost at the default sigma of 3. A looser sigma trades that for more smoothing: at sigma 10, fine moving detail,
|
|
52
|
+
such as hair or eyes, can smear.
|
|
53
|
+
- It runs on frames in memory, on a whole file (streaming, resumable after a crash) or as a ComfyUI node.
|
|
54
|
+
- **Evaluation.** Noise and detail metrics against the original (crawl, phone-scale crawl, grain, texture and drift,
|
|
55
|
+
per region when region maps are given), ArcFace face-identity scores, and side-by-side, A/B, split and grid review
|
|
56
|
+
videos.
|
|
57
|
+
- **ComfyUI plumbing.** The node, an installer that makes ComfyUI load it, and a small client for ComfyUI's HTTP API.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
Requirements:
|
|
62
|
+
- Python 3.12 or newer, on Linux (x86_64 or aarch64) or on macOS with Apple silicon. Intel Macs cannot install the
|
|
63
|
+
package: PyTorch publishes no macOS x86_64 wheels for torch 2.4 or newer. Windows is untested, and `evaluate` cannot
|
|
64
|
+
run there: it measures in processes started from a fork server, which Windows lacks.
|
|
65
|
+
- ffmpeg and ffprobe 5.1 or newer on the `PATH` for everything that reads or writes video files: the readers use
|
|
66
|
+
`-fps_mode`, which 5.1 added. The package is tested with ffmpeg 6.1, 7.1 and 8.1. Without them, `stabilize`,
|
|
67
|
+
`evaluate`, `identity` and `review` stop with a usage error that names what is missing. The ComfyUI node works on
|
|
68
|
+
ComfyUI's frames and needs neither.
|
|
69
|
+
- For the review videos, which caption every panel and are H.264: ffmpeg's `drawtext` filter and `libx264` encoder,
|
|
70
|
+
which some builds leave out (`ffmpeg -filters` and `ffmpeg -encoders` list them when they are there), and a font file.
|
|
71
|
+
Set `COMFYUI_VIDEO_DENOISE_FONT` to the font path if the default DejaVu Sans Bold is unavailable. Without a file at
|
|
72
|
+
that path, a review stops before it writes anything, with an error that names the path. Without `drawtext`, the
|
|
73
|
+
`review` command stops with a usage error before it reads anything; without `libx264`, it stops with ffmpeg's error,
|
|
74
|
+
in a traceback, once it has read the videos with ffprobe.
|
|
75
|
+
- For the `stabilize` command: a CUDA GPU, and an ffmpeg with NVENC for its default encoder (`--cpu-encoder` uses
|
|
76
|
+
libx265 instead). Where torch finds no CUDA GPU, or ffmpeg does not list the encoder the command would use
|
|
77
|
+
(`hevc_nvenc`, or `libx265` with `--cpu-encoder`), the command stops with a usage error before it reads, writes or
|
|
78
|
+
downloads anything (an encoder that ffmpeg lists can still fail to start, if the GPU or its driver lacks NVENC).
|
|
79
|
+
The reference's sound is copied into the MP4 output unchanged, so it must be one an MP4 can hold: uncompressed PCM of
|
|
80
|
+
16 or 24 bits needs ffmpeg 6.1 or newer, the first whose MP4 muxer takes it, and some sounds, such as WMA, A-law or
|
|
81
|
+
8-bit PCM, cannot go into an MP4 at all. `stabilize` does not check this before it starts, and such a run fails at its
|
|
82
|
+
final join.
|
|
83
|
+
|
|
84
|
+
The base package needs numpy, torch and torchvision. The extras add what the other parts need:
|
|
85
|
+
|
|
86
|
+
| Extra | Adds | Needed by |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `metrics` | OpenCV | `comfyui_video_denoise.metrics`, `comfyui-video-denoise evaluate` |
|
|
89
|
+
| `identity` | OpenCV, onnxruntime | `comfyui_video_denoise.identity`, `comfyui-video-denoise identity` |
|
|
90
|
+
| `all` | Both of the above | |
|
|
91
|
+
|
|
92
|
+
Without its extra, `evaluate` or `identity` stops with a usage error that names the extra to install. onnxruntime
|
|
93
|
+
publishes wheels only, no source distribution, so the `identity` extra (and with it `all`) installs only on a Python
|
|
94
|
+
for which onnxruntime has published wheels.
|
|
95
|
+
|
|
96
|
+
Install the base package from PyPI with pip, or add it to a uv project:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
python -m pip install comfyui-video-denoise
|
|
100
|
+
uv add comfyui-video-denoise
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Use `python -m pip install "comfyui-video-denoise[all]"` or `uv add "comfyui-video-denoise[all]"` for both extras, or
|
|
104
|
+
name one, as in `comfyui-video-denoise[metrics]`.
|
|
105
|
+
|
|
106
|
+
To follow changes that are not released yet, install it from its repository,
|
|
107
|
+
<https://github.com/mxlei01/comfyui-video-denoise>, with pip or uv:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
python -m pip install "comfyui-video-denoise[all] @ git+https://github.com/mxlei01/comfyui-video-denoise"
|
|
111
|
+
uv add git+https://github.com/mxlei01/comfyui-video-denoise --extra all
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`--tag`, `--branch` or `--rev` pin a uv git dependency to a release, a branch or a commit.
|
|
115
|
+
|
|
116
|
+
To work on the package, clone the repository outside the uv project that will use it, then add the clone to that
|
|
117
|
+
project from the project's folder:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
git clone https://github.com/mxlei01/comfyui-video-denoise /path/to/comfyui-video-denoise
|
|
121
|
+
cd /path/to/project
|
|
122
|
+
uv add /path/to/comfyui-video-denoise # a copy of the clone as it is now
|
|
123
|
+
uv add --editable /path/to/comfyui-video-denoise # follows the clone: changes apply on the next start
|
|
124
|
+
uv add --editable --extra all /path/to/comfyui-video-denoise # the same, with every extra
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
A clone inside the project's folder would become a workspace member instead, which is always editable, unless
|
|
128
|
+
`uv add` is given `--no-workspace`.
|
|
129
|
+
|
|
130
|
+
With pip, in the clone's root: `python -m pip install .`, or `python -m pip install ".[all]"` with every extra. pip
|
|
131
|
+
also installs the wheel that `make build` writes to `dist/`.
|
|
132
|
+
|
|
133
|
+
Which torch you get depends on how the package is installed:
|
|
134
|
+
- In a clone of the repository, uv takes torch and torchvision on Linux from the PyTorch CUDA 13.0 index that
|
|
135
|
+
`pyproject.toml` names in `[tool.uv.sources]`.
|
|
136
|
+
- A uv project that adds the package from a path or from git, as above and in the ComfyUI section, inherits that
|
|
137
|
+
setting on Linux: it gets the CUDA 13.0 build of torch too, which needs a driver that supports CUDA 13.
|
|
138
|
+
- pip ignores that setting and installs whatever torch it resolves. A built wheel, from PyPI or `make build`, asks for
|
|
139
|
+
plain `torch` and `torchvision`, so pip and uv resolve them from the installing environment's package indexes.
|
|
140
|
+
|
|
141
|
+
## Use it in ComfyUI
|
|
142
|
+
|
|
143
|
+
ComfyUI loads nodes only from folders in its `custom_nodes/`, and its Python must be able to import the package. For a
|
|
144
|
+
uv-managed ComfyUI checkout:
|
|
145
|
+
|
|
146
|
+
1. List the package in the checkout's `pyproject.toml` dependencies, so that `uv sync` keeps it:
|
|
147
|
+
```bash
|
|
148
|
+
cd /path/to/ComfyUI
|
|
149
|
+
uv add comfyui-video-denoise # or uv add --editable /path/to/a/clone, to follow a clone of the repository
|
|
150
|
+
```
|
|
151
|
+
`uv sync` makes the environment match that file exactly. Upstream ComfyUI's `pyproject.toml` lists no
|
|
152
|
+
dependencies, so add ComfyUI's own requirements to it first (`uv add -r requirements.txt`), or a sync removes them.
|
|
153
|
+
It also allows Python 3.10 and newer, while this package needs 3.12, so uv refuses the `uv add` until the
|
|
154
|
+
checkout narrows its range: `requires-python = ">=3.12"`, or `[tool.uv] environments` limited to Python 3.12+.
|
|
155
|
+
2. Write `custom_nodes/comfyui-video-denoise/__init__.py`, a short loader that imports the nodes from the package:
|
|
156
|
+
```bash
|
|
157
|
+
comfyui-video-denoise install-node --comfyui /path/to/ComfyUI
|
|
158
|
+
```
|
|
159
|
+
The command comes with the package, so after step 1 it is in the checkout's `.venv/bin/`. It also checks that the
|
|
160
|
+
checkout's Python can import the package, and says what to do if it cannot.
|
|
161
|
+
3. Restart ComfyUI. With an editable install, code changes in the clone apply on the next restart.
|
|
162
|
+
|
|
163
|
+
For a ComfyUI that uv does not manage, install the package with that ComfyUI's Python
|
|
164
|
+
(`<python> -m pip install comfyui-video-denoise`, or the path of a clone in place of the name), then run step 2.
|
|
165
|
+
|
|
166
|
+
In ComfyUI, connect **Load Optical Flow Model** (a core node; pick `raft_large_C_T_SKHT_V2-ff5fadd5.pth` from
|
|
167
|
+
`models/optical_flow`) to **Temporal Stabilize (RAFT, motion-compensated)**. The command line downloads those weights
|
|
168
|
+
there on first use. ComfyUI 0.46.0 and later load them into ComfyUI's own RAFT, which the node runs one frame pair at
|
|
169
|
+
a time, in the precision ComfyUI picks for the device (float16 where it uses half precision); earlier releases load
|
|
170
|
+
them into torchvision's RAFT-large, which the node runs in float32, as the command line does. When stabilizing a
|
|
171
|
+
restored or generated version, give the node the original it was made from as `reference`, so that motion and
|
|
172
|
+
mismatch are read from the original.
|
|
173
|
+
|
|
174
|
+
## Command line
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
comfyui-video-denoise stabilize SRC REF OUT [--radius 6] [--sigma 3] [--flow-scale 0.5] [--segment 600] [--max-frames N] [--torch-threads 4] [--cpu-encoder]
|
|
178
|
+
comfyui-video-denoise evaluate BASE[@FIRST] [LABEL=]VERSION[@FIRST]... [--frames N] [--regions NPZ --region-first T] \
|
|
179
|
+
[--json OUT] [--cache DIR] [--workers N]
|
|
180
|
+
comfyui-video-denoise identity BASE[@FIRST] [LABEL=]VERSION[@FIRST]... [--frames N] [--regions NPZ --region-first T] \
|
|
181
|
+
[--json OUT] [--step N]
|
|
182
|
+
comfyui-video-denoise review {sbs,ab,split,grid} [LABEL=]REF[@FIRST] [LABEL=]VERSION[@FIRST]... --out OUT.mp4 \
|
|
183
|
+
[--frames N]
|
|
184
|
+
comfyui-video-denoise install-node [--comfyui DIR] [--name NAME]
|
|
185
|
+
comfyui-video-denoise --version
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
- **`stabilize`:** stabilizes SRC with motion read from REF and copies REF's audio. It encodes HEVC Main 10 with
|
|
189
|
+
NVENC, at a variable bitrate that aims at 80 Mbps with peaks of 100 Mbps. OUT must end in `.mp4`, be in a folder that
|
|
190
|
+
exists and takes new files, not hold both a line break and `#` or `?` in its path (the list that joins its segments,
|
|
191
|
+
which ffmpeg reads line by line, could not name them), and be neither SRC nor REF under any spelling (`./graded.mp4`
|
|
192
|
+
is `graded.mp4`, and so is `file:graded.mp4`, ffmpeg's spelling of it where nothing is named so), and SRC and REF must
|
|
193
|
+
have one frame size and length; otherwise the command stops with a usage error before it reads a frame.
|
|
194
|
+
The frames are written at one steady rate, SRC's, and REF's sound is copied as it is, so after a gap in REF's
|
|
195
|
+
timestamps the picture runs ahead of the sound.
|
|
196
|
+
If it is interrupted, run the same command again: it continues after its last complete segment. A rerun with another
|
|
197
|
+
`--radius`, `--sigma`, `--flow-scale`, `--max-frames` or encoder, or after SRC or REF has changed, stops with an
|
|
198
|
+
error that names the setting (`frames` for `--max-frames`) or the file, as its frames would not match the finished
|
|
199
|
+
segments; delete `OUT.segments` (OUT without `.mp4`) to start again with new settings or files. SRC and REF are
|
|
200
|
+
compared by size and by their first and last mebibyte, not by path: a moved or copied file still continues, and a
|
|
201
|
+
change that keeps the size and falls between those parts goes unnoticed, as does any change to an input that is not
|
|
202
|
+
a local file (a URL, for example).
|
|
203
|
+
The run keeps its segments in the folder `OUT.segments` and writes OUT as `OUT.partial.mp4` until it is complete (OUT
|
|
204
|
+
without `.mp4` in both). In that folder it deletes only files of its own names (on a disk that ignores case, also in
|
|
205
|
+
another letter case): segments (`NNNNNN-NNNNNN.mp4`, with more digits from frame 1000000 on) outside the chain of
|
|
206
|
+
complete ones from the first frame, partial segments (`NNNNNN-NNNNNN.partial.mp4`) and an old join list
|
|
207
|
+
(`concat.txt`), and at the end its segments, join list and settings (`settings.json`). Anything else in the folder
|
|
208
|
+
stays as it is, and so does the folder then (as does an `OUT.segments` that is a link to a folder), which the run says
|
|
209
|
+
in its log; otherwise it removes the folder at the end. A SRC or REF that is one of the files in `OUT.segments` (a
|
|
210
|
+
link there counts only under one of the run's names) or is `OUT.partial.mp4`, under any spelling, and an
|
|
211
|
+
`OUT.segments` that is not a folder, stop the command with a usage error before it reads a frame: move or rename that
|
|
212
|
+
file, or choose another OUT.
|
|
213
|
+
`--flow-scale` sets the resolution RAFT runs at, relative to the frames (0.25 to 1, default 0.5). Lower is
|
|
214
|
+
faster and needs less GPU memory; higher follows the motion more precisely. For 1920x1080 frames at radius 6, the
|
|
215
|
+
stabilizer alone (without decoding and encoding) needs about 2.4 GiB of GPU memory at 0.25 and 11.5 GiB at 0.5,
|
|
216
|
+
and 0.25 runs about four times as fast as 0.5; 0.75 and 1 need far more, so they suit smaller frames. `--radius`,
|
|
217
|
+
`--segment` and `--torch-threads` take an integer of at least 1, `--max-frames` one of at least 0 (0, the default,
|
|
218
|
+
takes every frame) and `--sigma` a finite number of at least about 7.7e-20 (below that, `2*sigma*sigma` underflows
|
|
219
|
+
in single precision and frames can come out black); any other value stops the command before it starts, with a
|
|
220
|
+
usage error that names the option.
|
|
221
|
+
- **`[LABEL=]PATH[@FIRST]`:** the label defaults to the file name without extension. `@FIRST` is the frame where the
|
|
222
|
+
compared window starts in that file. For example, `graded.mov@120 excerpt.mov --frames 60` compares frames 120-179
|
|
223
|
+
of a full-length original with a 60-frame excerpt. A spec that names an existing file, with or without its
|
|
224
|
+
`@FIRST`, is a path, even if the name contains `=`.
|
|
225
|
+
- **File names:** a file whose name ffmpeg and ffprobe would read as an option or a protocol reaches them as that file.
|
|
226
|
+
A relative name that starts with `-`, such as `-clip.mov`, goes after `--`, which ends the options
|
|
227
|
+
(`comfyui-video-denoise evaluate --frames 60 -- graded.mov -clip.mov`), or is written `./-clip.mov`; both work, and so
|
|
228
|
+
do `--out=-review.mp4` and `--out ./-review.mp4`. A name that ffmpeg would read as a protocol, such as `clip:1.mov` or
|
|
229
|
+
`file:clip.mov`, is the file, folder or link of that name where there is one, so a video that is a folder is reported
|
|
230
|
+
as `Is a directory`, and one that is a link to a missing file as `No such file or directory`. A video of such a name
|
|
231
|
+
where there is none is left for ffmpeg to read as the URL or protocol it names: a missing `clip:1.mov` is reported in
|
|
232
|
+
ffprobe's words for a protocol, such as `Protocol not found`, and `file:clip.mov` is ffmpeg's spelling of the file
|
|
233
|
+
`clip.mov`. OUT, `--out` and the files `stabilize` keeps next to OUT are written as the local files their names say,
|
|
234
|
+
`o:1.mp4` and `take#2.mp4` among them, except a name in ffmpeg's `file:` spelling where nothing is named so, which
|
|
235
|
+
reaches it as written: `file:NAME` writes NAME. `stabilize` refuses an OUT whose path holds a line break together with
|
|
236
|
+
`#` or `?` (see above), and cannot write an OUT whose name starts with `file:`, also given as `./file:NAME.mp4`: its
|
|
237
|
+
run fails after RAFT is loaded.
|
|
238
|
+
- **Videos that cannot be read:** a video that ffprobe cannot read (a missing file, a folder, a file that is not a
|
|
239
|
+
video) stops `stabilize`, `evaluate`, `identity` and `review` before they write anything, with a usage error that
|
|
240
|
+
names it and gives ffprobe's reason, such as `No such file or directory`; so does a file without a video stream,
|
|
241
|
+
with a usage error that says so.
|
|
242
|
+
- **Labels in `evaluate` and `identity`:** each version's results are named by its label, so the versions need labels
|
|
243
|
+
of their own (and `evaluate` keeps `base` for the reference). Give clashing files a label, e.g.
|
|
244
|
+
`run1=run1/out.mov run2=run2/out.mov`; otherwise the command stops with an error that names them.
|
|
245
|
+
- **Frame sizes in `evaluate`, `identity` and `review`:** every video must have the reference's frame size. Otherwise
|
|
246
|
+
the command stops before decoding anything, with a usage error that names the video, its size and the expected size.
|
|
247
|
+
Scale or crop a version to the reference's size first. A video with rotation metadata counts at the size it is shown
|
|
248
|
+
at, turned upright, as ffmpeg decodes it.
|
|
249
|
+
- **Windows in `evaluate` and `identity`:** the window is `--frames` frames from each video's `@FIRST` frame, by
|
|
250
|
+
default the longest that every video has. `evaluate` measures frame pairs, so its window needs at least 2 frames,
|
|
251
|
+
and `identity` needs a version besides the reference. A video that ends before its window does, a `--regions` file
|
|
252
|
+
that is missing, is not an `.npz` file or lacks an array or a map the window needs, a `--json` file that could not
|
|
253
|
+
be written (its folder is missing or read-only, or the name is a folder's or a read-only file's) or that is one of
|
|
254
|
+
the videos or the `--regions` file under any spelling, or an option value out of range stops the command before it
|
|
255
|
+
decodes anything, with a usage error that names the video, the file or the option.
|
|
256
|
+
- **Measuring processes in `evaluate`:** `--workers N` sets them. The default is a quarter of the CPUs the command
|
|
257
|
+
may use (all of them, or the ones `taskset` allows), at most 48. If they cannot start, as when the arrays in the
|
|
258
|
+
`--regions` file are corrupt or cut off (the checks before decoding read only their headers), the command stops
|
|
259
|
+
with an error that says what failed. An error in one of them, or Ctrl-C, stops the others at once, and if the
|
|
260
|
+
command is killed, they end too.
|
|
261
|
+
- **Threads in `identity`:** each of its two face models runs on as many threads as the CPUs the command may use (all
|
|
262
|
+
of them, or the ones `taskset` allows), at most 16.
|
|
263
|
+
- **Report of `evaluate`:** a version's change against the reference reads n/a where it cannot be computed: where the
|
|
264
|
+
reference's value is 0, or either value is NaN.
|
|
265
|
+
- **`review`:** the first video is the reference panel, and its frame rate is used for all panels. `ab` and `split`
|
|
266
|
+
take exactly two videos, `sbs` two or more. `split` divides the picture in the middle; `grid` shows a centred crop
|
|
267
|
+
of half the frame size from every video. Without `--frames`, every video plays from its `@FIRST` frame to its end
|
|
268
|
+
(in `sbs` and `grid`, until the shortest one ends), with the reference's sound from the same point until the picture
|
|
269
|
+
ends (in `ab`, under each video until that video ends), or silent if the reference has none; with `--frames N`, each
|
|
270
|
+
plays its frames FIRST to FIRST+N-1, looped and silent. The sound is lined up by time (FIRST/fps seconds into the
|
|
271
|
+
reference), the picture by frame number, so a reference with a gap in its timestamps gets its sound out of step from
|
|
272
|
+
the gap on (from the start, if the gap comes before `@FIRST`). A `@FIRST` past the end of its file stops the command
|
|
273
|
+
before it writes anything, with a usage error that names the file. `--out` must end in `.mp4`, be in a folder that
|
|
274
|
+
exists and takes new files, and not be one of the videos under any spelling; otherwise the command stops with a
|
|
275
|
+
usage error before it reads a video. Labels are only captions here and may repeat.
|
|
276
|
+
|
|
277
|
+
`comfyui-video-denoise --help` and `comfyui-video-denoise <command> --help` list every option.
|
|
278
|
+
|
|
279
|
+
## Python API
|
|
280
|
+
|
|
281
|
+
| Module | What |
|
|
282
|
+
|---|---|
|
|
283
|
+
| `comfyui_video_denoise.stabilize` | `stabilize` and `stabilize_iter`: the stabilizer on (N, H, W, 3) float frames in 0..1 |
|
|
284
|
+
| `comfyui_video_denoise.stabilize_video` | `stabilize_video`: whole files, streaming and resumable; `check_working_files`: its checks that the list joining OUT's segments can name them and that SRC and REF are apart from the files it keeps next to OUT |
|
|
285
|
+
| `comfyui_video_denoise.raft` | `load_raft`: RAFT-large, with its weights downloaded into the model folder on first use |
|
|
286
|
+
| `comfyui_video_denoise.video` | ffmpeg I/O: `probe`, `read_frames`, `write_prores`, `StreamFrames`, `SegmentWriter`, `retag_bt709` |
|
|
287
|
+
| `comfyui_video_denoise.metrics` | `evaluate` and `report`: the noise and detail metrics; `check_sizes` and `check_region_maps`: input checks |
|
|
288
|
+
| `comfyui_video_denoise.identity` | `identity_scores`: ArcFace similarity to the original |
|
|
289
|
+
| `comfyui_video_denoise.review` | `side_by_side`, `ab`, `split`, `grid`: review videos |
|
|
290
|
+
| `comfyui_video_denoise.comfy_client` | `ComfyClient`: queue API-format graphs on a ComfyUI server and wait for them; `PartiallyQueuedError` when ComfyUI queued only the outputs that validated |
|
|
291
|
+
| `comfyui_video_denoise.nodes`, `install` | The ComfyUI node, and `install_node` |
|
|
292
|
+
| `comfyui_video_denoise.config` | Default locations (see Configuration) |
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
from pathlib import Path
|
|
296
|
+
|
|
297
|
+
from comfyui_video_denoise import config
|
|
298
|
+
from comfyui_video_denoise.metrics import Source, evaluate, report
|
|
299
|
+
from comfyui_video_denoise.stabilize_video import stabilize_video
|
|
300
|
+
from comfyui_video_denoise.video import probe
|
|
301
|
+
|
|
302
|
+
stabilize_video("restored.mov", "graded.mov", "stabilized.mp4")
|
|
303
|
+
|
|
304
|
+
info = probe("graded.mov")
|
|
305
|
+
res = evaluate(
|
|
306
|
+
{"base": Source(Path("graded.mov")), "stabilized": Source(Path("stabilized.mp4"))},
|
|
307
|
+
n=60,
|
|
308
|
+
width=info.width,
|
|
309
|
+
height=info.height,
|
|
310
|
+
cache_dir=config.cache_dir(),
|
|
311
|
+
)
|
|
312
|
+
print(report(res["summary"], "stabilized against graded"))
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
With its defaults (`device="cuda"`, `encoder=video.NVENC_HEVC`), `stabilize_video` needs what the `stabilize` command
|
|
316
|
+
needs, a CUDA GPU and an ffmpeg with NVENC, and unlike the command it does not check for them first. Elsewhere, pass
|
|
317
|
+
`device="cpu"` and `encoder=video.X265_MAIN10` (`from comfyui_video_denoise import video`), which is much slower.
|
|
318
|
+
|
|
319
|
+
`evaluate`'s processes do not run your program again, so a script that calls it needs no
|
|
320
|
+
`if __name__ == "__main__":` guard. `evaluate` does not replace or change your program's main module: its other threads
|
|
321
|
+
can use it, pickle what it defines and start processes of their own while `evaluate` runs.
|
|
322
|
+
|
|
323
|
+
## Configuration
|
|
324
|
+
|
|
325
|
+
Default locations and the caption font come from `comfyui_video_denoise.config`, and each can be set with an environment
|
|
326
|
+
variable:
|
|
327
|
+
|
|
328
|
+
| Setting | Environment variable | Default |
|
|
329
|
+
|---|---|---|
|
|
330
|
+
| ComfyUI checkout | `COMFYUI_ROOT` | `~/ComfyUI` |
|
|
331
|
+
| Model folder | `COMFYUI_VIDEO_DENOISE_MODELS` | `<ComfyUI>/models` |
|
|
332
|
+
| ComfyUI server URL | `COMFY_URL` | `http://127.0.0.1:8188` |
|
|
333
|
+
| Metrics decode cache | `COMFYUI_VIDEO_DENOISE_CACHE` | `<ComfyUI>/output/video_denoise_cache` |
|
|
334
|
+
| Caption font of the review videos | `COMFYUI_VIDEO_DENOISE_FONT` | `/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf` |
|
|
335
|
+
|
|
336
|
+
Set `COMFYUI_ROOT` if your checkout lives elsewhere. In `COMFYUI_ROOT`, `COMFYUI_VIDEO_DENOISE_MODELS`,
|
|
337
|
+
`COMFYUI_VIDEO_DENOISE_CACHE` and `COMFYUI_VIDEO_DENOISE_FONT`, a leading `~` stands for your home directory. Without
|
|
338
|
+
one (as for some container users), anything that needs such a path, the default `~/ComfyUI` included, stops with an
|
|
339
|
+
error that names the variable to set to a full path: in the commands, a usage error, before they decode anything. A
|
|
340
|
+
leading `~` in `--cache`, `--comfyui`, `--json`, `--out` and `--regions` stands for your home directory too, also after
|
|
341
|
+
`=` (as in `--cache=~/cache`, which the shell leaves as written); without one, they stop with a usage error.
|
|
342
|
+
`COMFYUI_ROOT`, `COMFYUI_VIDEO_DENOISE_MODELS`, `COMFYUI_VIDEO_DENOISE_CACHE`, `COMFY_URL` and
|
|
343
|
+
`COMFYUI_VIDEO_DENOISE_FONT` count as unset when they are set but empty. The models are kept in the model folder:
|
|
344
|
+
- RAFT-large in `<models>/optical_flow`, where ComfyUI's Load Optical Flow Model reads it too, so one download serves
|
|
345
|
+
both. It is downloaded on first use and kept only if its SHA-256 starts with the `ff5fadd5` in its file name;
|
|
346
|
+
otherwise the command stops with an `invalid hash value` error, and the next run downloads it again.
|
|
347
|
+
- InsightFace's `buffalo_l` (`det_10g.onnx` and `w600k_r50.onnx`, from its v0.7 release) in
|
|
348
|
+
`<models>/insightface/buffalo_l`. These are not downloaded automatically. ComfyUI custom nodes that load them with
|
|
349
|
+
InsightFace's own package keep them one folder deeper, in `<models>/insightface/models/buffalo_l`: copy or link the
|
|
350
|
+
two files from there. Without the two files in its folder, `identity` stops with a usage error that says where to put
|
|
351
|
+
them, before it decodes anything.
|
|
352
|
+
|
|
353
|
+
## Models and their terms
|
|
354
|
+
|
|
355
|
+
The package's licence covers its own code, not the model files it runs, which come with terms of their own. Check
|
|
356
|
+
them for your use:
|
|
357
|
+
|
|
358
|
+
- **RAFT-large** (`raft_large_C_T_SKHT_V2-ff5fadd5.pth`): torchvision's weights, which `comfyui-video-denoise stabilize`
|
|
359
|
+
and `load_raft` download from `download.pytorch.org` on first use. torchvision trained them on FlyingChairs and
|
|
360
|
+
FlyingThings3D and fine-tuned them on Sintel, KITTI, HD1K and FlyingThings3D. Its documentation says that its
|
|
361
|
+
pre-trained models "may have their own licenses or terms and conditions derived from the dataset used for training"
|
|
362
|
+
and that "It is your responsibility to determine whether you have permission to use the models for your use case"
|
|
363
|
+
([torchvision's models](https://docs.pytorch.org/vision/stable/models.html)). FlyingChairs and FlyingThings3D are
|
|
364
|
+
offered for research purposes only, KITTI under a non-commercial Creative Commons licence, and Sintel for
|
|
365
|
+
non-commercial scientific research.
|
|
366
|
+
- **InsightFace's `buffalo_l`** (`det_10g.onnx` and `w600k_r50.onnx`), which only `comfyui_video_denoise.identity` and
|
|
367
|
+
`comfyui-video-denoise identity` use. The package does not download them: you place them in
|
|
368
|
+
`<models>/insightface/buffalo_l`. InsightFace offers the models it trained for non-commercial research purposes only,
|
|
369
|
+
and, for its open-sourced face recognition models such as the `buffalo_l` package, asks to be contacted for
|
|
370
|
+
licensing ([InsightFace's licence](https://github.com/deepinsight/insightface#license)).
|
|
371
|
+
|
|
372
|
+
## Development
|
|
373
|
+
|
|
374
|
+
In a clone of the repository, on Linux x86_64 or on macOS with Apple silicon (`uv.lock` leaves out Linux on aarch64,
|
|
375
|
+
where uv refuses to set up the environment):
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
make dev # uv sync --all-extras: Python 3.13, torch + torchvision from the CUDA 13.0 index on Linux
|
|
379
|
+
make check # every gate below, without changing files
|
|
380
|
+
make lint # ruff check (E, F, PL, D, C90, I, PT, ANN; line length 120)
|
|
381
|
+
make format # ruff import sorting + ruff format (format-check only checks)
|
|
382
|
+
make ty # ty type check of src and tests
|
|
383
|
+
make bandit # security lint
|
|
384
|
+
make pytest # the tests that run anywhere, with a coverage report
|
|
385
|
+
make pytest-gpu # every test, including the ones that need CUDA, NVENC and the RAFT weights
|
|
386
|
+
make all # format, then every gate
|
|
387
|
+
make build # wheel + sdist in dist/
|
|
388
|
+
make release-requirements # rewrite .github/requirements/twine.txt from twine.in (needs the network)
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
- All code, tests included, has Google-style docstrings and full type hints.
|
|
392
|
+
- Warnings fail the tests, which need ffmpeg 6.0 or newer (one uses `-display_rotation`).
|
|
393
|
+
- Checks inherit the caller's CPU affinity. On Linux, set `CPUS` to an allowed CPU list to pin a check, e.g.
|
|
394
|
+
`make pytest CPUS=0-3`. An optional, untracked `local.mk` next to the Makefile is read first, for one machine's
|
|
395
|
+
settings such as `CPUS ?= 0-3`.
|
|
396
|
+
- CI (`.github/workflows/ci.yml`) runs `make dev` and every gate except the GPU tests on GitHub's runners (Ubuntu
|
|
397
|
+
24.04, no GPU): on pull requests, on pushes to `master`, weekly and on demand. The face-identity test runs there on
|
|
398
|
+
InsightFace's `buffalo_l` models, fetched from their release and checked by sha256. A separate job runs `make dev`
|
|
399
|
+
and the tests on Python 3.12 and 3.14 too, and merging does not wait for it. `make pytest-gpu` runs the GPU tests on
|
|
400
|
+
a machine with CUDA.
|
|
401
|
+
|
|
402
|
+
### Releasing
|
|
403
|
+
|
|
404
|
+
A release is made from `master` by publishing a GitHub release, which runs `.github/workflows/release.yaml`. The
|
|
405
|
+
version is the one in `pyproject.toml`, and the release's tag is `v` and that version, such as `v0.1.0`. The one-time
|
|
406
|
+
setup on GitHub and on PyPI that the workflow relies on is described at the top of that file.
|
|
407
|
+
|
|
408
|
+
1. **A pull request for the release**, after an issue, as for any change. It sets the version unless it is set
|
|
409
|
+
already (`uv version X.Y.Z --no-sync` updates `pyproject.toml` and `uv.lock`), and gives the version its section in
|
|
410
|
+
`CHANGELOG.md`: `## Unreleased` becomes `## X.Y.Z` and the date, under a new, empty `## Unreleased`. Before it is
|
|
411
|
+
merged, run the workflow by hand on its branch (Actions, Release, Run workflow). This dry run builds, checks and
|
|
412
|
+
tests the files as a release would, uploads nothing, and says whether the changelog has the version's section.
|
|
413
|
+
2. **The GitHub release.** Once the pull request is merged, draft a new release on the repository's Releases page: type
|
|
414
|
+
the new tag `vX.Y.Z` (created on publish), keep the target `master`, and paste the version's changelog section as
|
|
415
|
+
the notes. Tick "Set as a pre-release" only for a pre-release, whose tag ends in `a`, `b` or `rc` and a number, such
|
|
416
|
+
as `v0.2.0rc1`. Then publish it.
|
|
417
|
+
|
|
418
|
+
Publishing runs the workflow:
|
|
419
|
+
|
|
420
|
+
1. It checks the release: the repository is public, the release is not immutable, the tag is `v` and a version as
|
|
421
|
+
PEP 440 spells it, the pre-release box matches the tag, the tag names the version in `pyproject.toml`,
|
|
422
|
+
`CHANGELOG.md` has a section for that version, and the tagged commit is one of `master`'s own commits, not one
|
|
423
|
+
merged in from a branch.
|
|
424
|
+
2. It builds the source distribution and the wheel once, with the uv that CI uses, and records their sha256 sums.
|
|
425
|
+
Every later job compares the files it is given with that record before it uses them.
|
|
426
|
+
3. It checks the files: a pure-Python wheel of the version, the licence files in both archives and named by their
|
|
427
|
+
metadata, and `twine check --strict`. It installs the wheel with every extra on Python 3.12, 3.13 and 3.14, next to
|
|
428
|
+
the versions `uv.lock` pins, and runs the tests that need no GPU against it, from a folder without the sources.
|
|
429
|
+
4. It uploads both files to PyPI through trusted publishing: PyPI trusts this repository's `release.yaml` running in
|
|
430
|
+
the `pypi` environment, which only `v*` tags may use, so no token is stored. Each file gets an attestation that
|
|
431
|
+
names the workflow. Just before the upload, the job checks again that it holds the recorded files, and that the
|
|
432
|
+
release is still published and its tag still names the commit the run built.
|
|
433
|
+
5. It attaches the same files to the GitHub release and confirms by sha256 that the release and PyPI hold exactly the
|
|
434
|
+
files it built.
|
|
435
|
+
|
|
436
|
+
Keep the repository's immutable releases off: an immutable release takes no files once published. PyPI never takes a
|
|
437
|
+
file name twice, even after the file, the release or the whole project has been deleted, so a version's files can
|
|
438
|
+
never be replaced: a broken release can be yanked or deleted, and the fix is a new version. Hence the dry run.
|
|
439
|
+
|
|
440
|
+
If a run stops before "Publish to PyPI", nothing was uploaded. A failure that a re-run need not repeat, such as a
|
|
441
|
+
failed download or a lost runner, needs only "Re-run failed jobs". For a refusal of the release check or any other
|
|
442
|
+
failure, a re-run sees the release as it was first published, and editing a release starts no run, so follow the
|
|
443
|
+
failed job's message: usually, delete the release (and its tag, if the tag is wrong or must move), make the fix it
|
|
444
|
+
asks for, and publish again. Deleting a release does not stop its run: cancel the run before publishing again.
|
|
445
|
+
|
|
446
|
+
Once "Publish to PyPI" has started, use "Re-run failed jobs" on the same run. If the upload failed, the re-run sends
|
|
447
|
+
the files it built to PyPI again: PyPI accepts a file it already holds with the same bytes, and refuses one that
|
|
448
|
+
differs. GitHub allows re-runs for 30 days, and PyPI takes no new files for a version 14 days after its first upload.
|
|
449
|
+
Do not delete or unpublish the release meanwhile: both upload jobs check first that it is still published. If it
|
|
450
|
+
happens anyway, publish the release again on the same tag, at the same commit, cancel the run that starts, and re-run
|
|
451
|
+
the first run's failed jobs. If the tag was deleted too, first push it again at the commit the run built
|
|
452
|
+
(`git tag vX.Y.Z <commit>`, then `git push origin vX.Y.Z`): a tag that the release form creates lands on the tip of
|
|
453
|
+
`master`, which may be a later commit, and the re-run then stops because the tag moved. If "Attach to the release and
|
|
454
|
+
compare" finds a file on the release that differs from the build, delete that file from the release and re-run the
|
|
455
|
+
job. After GitHub's 30 days, the files PyPI lists for the version can still be attached to the release by hand.
|
|
456
|
+
|
|
457
|
+
## Contributing
|
|
458
|
+
|
|
459
|
+
Bug reports and questions are welcome as issues. Before you open a pull request, read
|
|
460
|
+
[CONTRIBUTING.md](https://github.com/mxlei01/comfyui-video-denoise/blob/master/CONTRIBUTING.md): a change starts with an
|
|
461
|
+
issue, and every commit subject names it, `Issue #N: <summary>`, which CI checks. Report a security problem
|
|
462
|
+
privately, as [SECURITY.md](https://github.com/mxlei01/comfyui-video-denoise/blob/master/SECURITY.md) explains.
|
|
463
|
+
|
|
464
|
+
## Layout
|
|
465
|
+
|
|
466
|
+
| Path | What |
|
|
467
|
+
|---|---|
|
|
468
|
+
| `src/comfyui_video_denoise/` | The package (see Python API) |
|
|
469
|
+
| `tests/` | pytest on synthetic clips; CPU unless marked `gpu`. ComfyUI and its server are replaced by stand-ins |
|
|
470
|
+
| `.github/` | The CI and release workflows (see Releasing), twine's hashed list and its input, and Dependabot |
|
|
471
|
+
| [`CHANGELOG.md`](https://github.com/mxlei01/comfyui-video-denoise/blob/master/CHANGELOG.md) | Changes |
|
|
472
|
+
| `CONTRIBUTING.md`, `SECURITY.md` | How to contribute, and how to report a vulnerability (see Contributing) |
|
|
473
|
+
| `LICENSE`, `THIRD_PARTY_NOTICES.txt` | The package's licence, and the notice of the code it follows (see Licence) |
|
|
474
|
+
|
|
475
|
+
## Licence
|
|
476
|
+
|
|
477
|
+
The package's own code is under the licence in
|
|
478
|
+
[`LICENSE`](https://github.com/mxlei01/comfyui-video-denoise/blob/master/LICENSE), which its metadata names. Two parts
|
|
479
|
+
of `comfyui_video_denoise.identity` follow InsightFace's MIT-licensed code, whose notice is kept in
|
|
480
|
+
[`THIRD_PARTY_NOTICES.txt`](https://github.com/mxlei01/comfyui-video-denoise/blob/master/THIRD_PARTY_NOTICES.txt).
|
|
481
|
+
ffmpeg, which the package runs as a separate program, and the model files (see Models and their terms) come with
|
|
482
|
+
licences and terms of their own.
|