Use higher quality defaults for Save Video encoding. (#16663) · code/app-python-comfyui@a65316b · GitHub
Skip to content

Commit a65316b

Browse files
Use higher quality defaults for Save Video encoding. (Comfy-Org#16663)
Default CRF is now 18 on h264 and 24 on AV1.
1 parent 9d80841 commit a65316b

5 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎comfy_api/latest/_input/video_types.py‎

Lines changed: 1 addition & 1 deletion

‎comfy_api/latest/_input_impl/video_types.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,15 @@ def video_stream_color_space(stream) -> str | None:
210210
def video_encoder_options(
211211
codec: VideoCodec, crf: float | None, preset: str | None = None
212212
) -> dict[str, str]:
213+
if crf is None:
214+
crf = 24 if codec == VideoCodec.AV1 else 18
213215
options = {}
214216
if preset is not None and codec == VideoCodec.H264:
215217
options["preset"] = preset
216-
if crf is not None:
217-
if codec == VideoCodec.AV1 and crf == 0:
218-
options["svtav1-params"] = "lossless=1"
219-
else:
220-
options["crf"] = str(crf)
218+
if codec == VideoCodec.AV1 and crf == 0:
219+
options["svtav1-params"] = "lossless=1"
220+
else:
221+
options["crf"] = str(crf)
221222
return options
222223

223224

‎comfy_extras/nodes_video.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _save_video_codec_input(supported_codecs: list[str], *, optional=False, hidd
9090
io.DynamicCombo.Option(
9191
"re-encode",
9292
[
93-
io.Float.Input("crf", default=23.0, min=0.0, max=51.0, step=1.0, tooltip="Lower values produce higher quality and larger files."),
93+
io.Float.Input("crf", default=18.0, min=0.0, max=51.0, step=1.0, tooltip="Lower values produce higher quality and larger files."),
9494
],
9595
),
9696
],
@@ -113,7 +113,7 @@ def _save_video_codec_input(supported_codecs: list[str], *, optional=False, hidd
113113
io.DynamicCombo.Option(
114114
"re-encode",
115115
[
116-
io.Float.Input("crf", default=30.0, min=0.0, max=63.0, step=1.0, tooltip="Lower values produce higher quality and larger files."),
116+
io.Float.Input("crf", default=24.0, min=0.0, max=63.0, step=1.0, tooltip="Lower values produce higher quality and larger files."),
117117
],
118118
),
119119
],

‎tests-unit/comfy_api_test/input_impl_test.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ def test_av1_zero_crf_uses_lossless_mode():
103103
assert video_encoder_options(VideoCodec.AV1, 0) == {"svtav1-params": "lossless=1"}
104104
assert video_encoder_options(VideoCodec.AV1, 30.0) == {"crf": "30.0"}
105105
assert video_encoder_options(VideoCodec.H264, 0) == {"crf": "0"}
106-
assert video_encoder_options(VideoCodec.AV1, None) == {}
106+
assert video_encoder_options(VideoCodec.AV1, None) == {"crf": "24"}

‎tests-unit/comfy_api_test/video_types_test.py‎

Lines changed: 3 additions & 2 deletions

0 commit comments

Comments
 (0)