Skip to content

Commit ab96cf2

Browse files
authored
Merge version 1.5.15
2 parents 972c87d + f837d6f commit ab96cf2

File tree

10 files changed

+38
-20
lines changed

10 files changed

+38
-20
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-videohelpersuite"
33
description = "Nodes related to video workflows"
4-
version = "1.5.14"
4+
version = "1.5.15"
55
license = { file = "LICENSE" }
66
dependencies = ["opencv-python", "imageio-ffmpeg"]
77

video_formats/ProRes.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
[
44
"-n", "-c:v", "prores_ks",
55
"-profile:v", ["profile",["1","2","3","4"], {"default": "3"}],
6-
"-colorspace", "1", "-color_primaries", "1", "-color_trc", "1"
7-
6+
"-vf", "scale=out_color_matrix=bt709"
87
],
8+
"fake_trc": "bt709",
99
"audio_pass": ["-c:a", "pcm_s16le"],
1010
"extension": "mov"
1111
}

video_formats/av1-webm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"-n", "-c:v", "libsvtav1",
55
"-pix_fmt", ["pix_fmt", ["yuv420p10le", "yuv420p"]],
66
"-crf", ["crf","INT", {"default": 23, "min": 0, "max": 100, "step": 1}],
7-
"-vf", "colorspace=all=bt709:iall=bt601-6-625:fast=1",
8-
"-colorspace", "1", "-color_primaries", "1", "-color_trc", "1"
7+
"-vf", "scale=out_color_matrix=bt709"
98
],
9+
"fake_trc": "bt709",
1010
"audio_pass": ["-c:a", "libopus"],
1111
"input_color_depth": ["input_color_depth", ["8bit", "16bit"]],
1212
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],

video_formats/gifski.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"main_pass":
33
[
4-
"-pix_fmt", "yuv420p"
4+
"-pix_fmt", "yuv420p",
5+
"-vf", "scale=out_color_matrix=bt709"
56
],
67
"extension": "gif",
78
"gifski_pass": [

video_formats/h264-mp4.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"-n", "-c:v", "libx264",
55
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le"]],
66
"-crf", ["crf","INT", {"default": 19, "min": 0, "max": 100, "step": 1}],
7-
"-vf", "colorspace=all=bt709:iall=bt601-6-625:fast=1",
8-
"-colorspace", "1", "-color_primaries", "1", "-color_trc", "1"
7+
"-vf", "scale=out_color_matrix=bt709"
98
],
9+
"fake_trc": "bt709",
1010
"audio_pass": ["-c:a", "aac"],
1111
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
1212
"trim_to_audio": ["trim_to_audio", "BOOLEAN", {"default": false}],

video_formats/h265-mp4.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"-pix_fmt", ["pix_fmt", ["yuv420p10le", "yuv420p"]],
77
"-crf", ["crf","INT", {"default": 22, "min": 0, "max": 100, "step": 1}],
88
"-preset", "medium",
9-
"-vf", "colorspace=all=bt709:iall=bt601-6-625:fast=1",
10-
"-colorspace", "1", "-color_primaries", "1", "-color_trc", "1",
9+
"-vf", "scale=out_color_matrix=bt709",
1110
"-x265-params", "log-level=quiet"
1211
],
12+
"fake_trc": "bt709",
1313
"audio_pass": ["-c:a", "aac"],
1414
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
1515
"extension": "mp4"

video_formats/nvenc_h264-mp4.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"main_pass":
33
[
44
"-n", "-c:v", "h264_nvenc",
5-
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le", "rgba"]]
5+
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le"]],
6+
"-vf", "scale=out_color_matrix=bt709"
67
],
8+
"fake_trc": "bt709",
79
"audio_pass": ["-c:a", "aac"],
810
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
911
"megabit": ["megabit","BOOLEAN", {"default": true}],

video_formats/nvenc_hevc-mp4.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
[
44
"-n", "-c:v", "hevc_nvenc",
55
"-vtag", "hvc1",
6-
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le", "rgba"]]
6+
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le"]],
7+
"-vf", "scale=out_color_matrix=bt709"
78
],
9+
"fake_trc": "bt709",
810
"audio_pass": ["-c:a", "aac"],
911
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
1012
"megabit": ["megabit","BOOLEAN", {"default": true}],

video_formats/webm.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"-pix_fmt", ["pix_fmt",["yuv420p","yuva420p"]],
66
"-crf", ["crf","INT", {"default": 20, "min": 0, "max": 100, "step": 1}],
77
"-b:v", "0",
8-
"-colorspace", "1", "-color_primaries", "1", "-color_trc", "1"
8+
"-vf", "scale=out_color_matrix=bt709"
99
],
10+
"fake_trc": "bt709",
1011
"audio_pass": ["-c:a", "libvorbis"],
1112
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
1213
"trim_to_audio": ["trim_to_audio", "BOOLEAN", {"default": false}],

videohelpersuite/nodes.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,13 @@ def ffmpeg_process(args, video_format, video_metadata, file_path, env):
165165
if len(res) > 0:
166166
print(res.decode(*ENCODE_ARGS), end="", file=sys.stderr)
167167

168-
def gifski_process(args, video_format, file_path, env):
168+
def gifski_process(args, dimensions, video_format, file_path, env):
169169
frame_data = yield
170170
with subprocess.Popen(args + video_format['main_pass'] + ['-f', 'yuv4mpegpipe', '-'],
171171
stderr=subprocess.PIPE, stdin=subprocess.PIPE,
172172
stdout=subprocess.PIPE, env=env) as procff:
173173
with subprocess.Popen([gifski_path] + video_format['gifski_pass']
174+
+ ['-W', f'{dimensions[0]}', '-H', f'{dimensions[1]}']
174175
+ ['-q', '-o', file_path, '-'], stderr=subprocess.PIPE,
175176
stdin=procff.stdout, stdout=subprocess.PIPE,
176177
env=env) as procgs:
@@ -417,12 +418,11 @@ def pad(image):
417418
padded = padfunc(image.to(dtype=torch.float32))
418419
return padded.permute((1,2,0))
419420
images = map(pad, images)
420-
new_dims = (-first_image.shape[1] % dim_alignment + first_image.shape[1],
421-
-first_image.shape[0] % dim_alignment + first_image.shape[0])
422-
dimensions = f"{new_dims[0]}x{new_dims[1]}"
421+
dimensions = (-first_image.shape[1] % dim_alignment + first_image.shape[1],
422+
-first_image.shape[0] % dim_alignment + first_image.shape[0])
423423
logger.warn("Output images were not of valid resolution and have had padding applied")
424424
else:
425-
dimensions = f"{first_image.shape[1]}x{first_image.shape[0]}"
425+
dimensions = (first_image.shape[1], first_image.shape[0])
426426
if loop_count > 0:
427427
loop_args = ["-vf", "loop=loop=" + str(loop_count)+":size=" + str(num_frames)]
428428
else:
@@ -450,7 +450,18 @@ def pad(image):
450450
if bitrate is not None:
451451
bitrate_arg = ["-b:v", str(bitrate) + "M" if video_format.get('megabit') == 'True' else str(bitrate) + "K"]
452452
args = [ffmpeg_path, "-v", "error", "-f", "rawvideo", "-pix_fmt", i_pix_fmt,
453-
"-s", dimensions, "-r", str(frame_rate), "-i", "-"] \
453+
# The image data is in an undefined generic RGB color space, which in practice means sRGB.
454+
# sRGB has the same primaries and matrix as BT.709, but a different transfer function (gamma),
455+
# called by the sRGB standard name IEC 61966-2-1. However, video hosting platforms like YouTube
456+
# standardize on full BT.709 and will convert the colors accordingly. This last minute change
457+
# in colors can be confusing to users. We can counter it by lying about the transfer function
458+
# on a per format basis, i.e. for video we will lie to FFmpeg that it is already BT.709. Also,
459+
# because the input data is in RGB (not YUV) it is more efficient (fewer scale filter invocations)
460+
# to specify the input color space as RGB and then later, if the format actually wants YUV,
461+
# to convert it to BT.709 YUV via FFmpeg's -vf "scale=out_color_matrix=bt709".
462+
"-color_range", "full", "-colorspace", "rgb", "-color_primaries", "bt709",
463+
"-color_trc", video_format.get("fake_trc", "iec61966-2-1"),
464+
"-s", f"{dimensions[0]}x{dimensions[1]}", "-r", str(frame_rate), "-i", "-"] \
454465
+ loop_args
455466

456467
images = map(lambda x: x.tobytes(), images)
@@ -479,8 +490,9 @@ def pad(image):
479490
args = args[:13] + video_format['inputs_main_pass'] + args[13:]
480491

481492
if output_process is None:
493+
format = 'image/gif'
482494
if 'gifski_pass' in video_format:
483-
output_process = gifski_process(args, video_format, file_path, env)
495+
output_process = gifski_process(args, dimensions, video_format, file_path, env)
484496
else:
485497
args += video_format['main_pass'] + bitrate_arg
486498
merge_filter_args(args)

0 commit comments

Comments
 (0)