Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Use higher quality defaults for Save Video encoding. (#16663)

comfyanonymousa65316bd54bd
diff --git a/comfy_api/latest/_input/video_types.py b/comfy_api/latest/_input/video_types.py
index 600e116cc..8b4936a47 100644
--- a/comfy_api/latest/_input/video_types.py
+++ b/comfy_api/latest/_input/video_types.py
@@ -37,7 +37,7 @@ class VideoInput(ABC):
Abstract method to save the video input to a file.
bit_depth selects the encoded bit depth; None keeps the video's native depth.
- crf selects the H.264 or AV1 constant rate factor; None uses the encoder default.
+ crf selects the H.264 or AV1 constant rate factor; None uses 18 for H.264 or 24 for AV1 when encoding.
preset selects the H.264 encoder speed/compression trade-off (e.g. "ultrafast");
None uses the encoder default. Ignored for other codecs.
color_space="sRGB" selects SDR BT.709/sRGB, "HDR" selects BT.2020/HLG, and "HDR PQ"
diff --git a/comfy_api/latest/_input_impl/video_types.py b/comfy_api/latest/_input_impl/video_types.py
index d32b48260..b0e331b8d 100644
--- a/comfy_api/latest/_input_impl/video_types.py
+++ b/comfy_api/latest/_input_impl/video_types.py
@@ -210,14 +210,15 @@ def video_stream_color_space(stream) -> str | None:
def video_encoder_options(
codec: VideoCodec, crf: float | None, preset: str | None = None
) -> dict[str, str]:
+ if crf is None:
+ crf = 24 if codec == VideoCodec.AV1 else 18
options = {}
if preset is not None and codec == VideoCodec.H264:
options["preset"] = preset
- if crf is not None:
- if codec == VideoCodec.AV1 and crf == 0:
- options["svtav1-params"] = "lossless=1"
- else:
- options["crf"] = str(crf)
+ if codec == VideoCodec.AV1 and crf == 0:
+ options["svtav1-params"] = "lossless=1"
+ else:
+ options["crf"] = str(crf)
return options
diff --git a/comfy_extras/nodes_video.py b/comfy_extras/nodes_video.py
index 70876a96b..a753211ed 100644
--- a/comfy_extras/nodes_video.py
+++ b/comfy_extras/nodes_video.py
@@ -90,7 +90,7 @@ def _save_video_codec_input(supported_codecs: list[str], *, optional=False, hidd
io.DynamicCombo.Option(
"re-encode",
[
- 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."),
+ 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."),
],
),
],
@@ -113,7 +113,7 @@ def _save_video_codec_input(supported_codecs: list[str], *, optional=False, hidd
io.DynamicCombo.Option(
"re-encode",
[
- 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."),
+ 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."),
],
),
],
diff --git a/tests-unit/comfy_api_test/input_impl_test.py b/tests-unit/comfy_api_test/input_impl_test.py
index 2a6f8a6f1..eb46b02e7 100644
--- a/tests-unit/comfy_api_test/input_impl_test.py
+++ b/tests-unit/comfy_api_test/input_impl_test.py
@@ -103,4 +103,4 @@ def test_av1_zero_crf_uses_lossless_mode():
assert video_encoder_options(VideoCodec.AV1, 0) == {"svtav1-params": "lossless=1"}
assert video_encoder_options(VideoCodec.AV1, 30.0) == {"crf": "30.0"}
assert video_encoder_options(VideoCodec.H264, 0) == {"crf": "0"}
- assert video_encoder_options(VideoCodec.AV1, None) == {}
+ assert video_encoder_options(VideoCodec.AV1, None) == {"crf": "24"}
diff --git a/tests-unit/comfy_api_test/video_types_test.py b/tests-unit/comfy_api_test/video_types_test.py
index eac6c2508..713088998 100644
--- a/tests-unit/comfy_api_test/video_types_test.py
+++ b/tests-unit/comfy_api_test/video_types_test.py
@@ -1549,14 +1549,15 @@ def test_video_encoder_options_applies_h264_preset():
from comfy_api.latest._input_impl.video_types import video_encoder_options
assert video_encoder_options(VideoCodec.H264, None, "ultrafast") == {
- "preset": "ultrafast"
+ "preset": "ultrafast",
+ "crf": "18",
}
assert video_encoder_options(VideoCodec.H264, 23.0, "ultrafast") == {
"preset": "ultrafast",
"crf": "23.0",
}
assert video_encoder_options(VideoCodec.H264, 23.0, None) == {"crf": "23.0"}
- assert video_encoder_options(VideoCodec.AV1, None, "ultrafast") == {}
+ assert video_encoder_options(VideoCodec.AV1, None, "ultrafast") == {"crf": "24"}
assert video_encoder_options(VideoCodec.AV1, 0, "ultrafast") == {
"svtav1-params": "lossless=1"
}