Skip to content

DLSS 5 Neural Rendering for Images & Video with Frame Generation, RTX Video Super Resolution, HDR, and Color Grading

Add files via upload

Merserk91e237b48ddc
diff --git a/src/core/cache_cleanup.py b/src/core/cache_cleanup.py
index 88287cb..6f782ce 100644
--- a/src/core/cache_cleanup.py
+++ b/src/core/cache_cleanup.py
@@ -19,12 +19,13 @@ import shutil
import time
from pathlib import Path
-from .paths import APP_TEMP, JOBS
+from .paths import APP_TEMP, JOBS, PREVIEW_CACHE
# Agreed retention: treat anything older than 24h as stale
# (startup sweep + periodic sweep).
CACHE_SWEEP_INTERVAL_SECONDS = 3600
CACHE_MAX_AGE_SECONDS = 24 * 3600
+PREVIEW_CACHE_MAX_BYTES = 8 * 1024 ** 3
def resolve_app_temp_dir() -> Path | None:
@@ -71,7 +72,8 @@ def _remove_entry(path: Path) -> int:
return 0
-def sweep_dir_by_age(root: Path, max_age_seconds: int) -> tuple[int, int]:
+def sweep_dir_by_age(root: Path, max_age_seconds: int, *,
+ excluded_names: frozenset[str] = frozenset()) -> tuple[int, int]:
"""Remove direct children of ``root`` older than ``max_age_seconds``.
Returns ``(removed_count, freed_bytes)``. Never raises, never removes
@@ -85,6 +87,8 @@ def sweep_dir_by_age(root: Path, max_age_seconds: int) -> tuple[int, int]:
return (0, 0)
now = time.time()
for entry in entries:
+ if entry.name in excluded_names:
+ continue
try:
stat_result = os.stat(entry.path, follow_symlinks=False)
except OSError:
@@ -96,6 +100,49 @@ def sweep_dir_by_age(root: Path, max_age_seconds: int) -> tuple[int, int]:
return (removed, freed)
+def prune_preview_cache(max_bytes: int = PREVIEW_CACHE_MAX_BYTES, *,
+ root: Path = PREVIEW_CACHE,
+ protected_keys: set[str] | None = None,
+ min_idle_seconds: int = 600) -> tuple[int, int]:
+ """Evict least recently used stage entries when the preview cache is full."""
+ protected_keys = protected_keys or set()
+ try:
+ entries = list(os.scandir(root))
+ except OSError:
+ return (0, 0)
+ sized: list[tuple[float, Path, int]] = []
+ total = 0
+ now = time.time()
+ for entry in entries:
+ path = Path(entry.path)
+ try:
+ if not entry.is_dir(follow_symlinks=False):
+ continue
+ stat = entry.stat(follow_symlinks=False)
+ size = 0
+ for folder, _dirs, files in os.walk(path):
+ for name in files:
+ try:
+ size += (Path(folder) / name).stat().st_size
+ except OSError:
+ pass
+ total += size
+ if entry.name not in protected_keys and _entry_age_seconds(stat, now) > min_idle_seconds:
+ sized.append((stat.st_mtime, path, size))
+ except OSError:
+ continue
+ removed = freed = 0
+ for _mtime, path, size in sorted(sized):
+ if total <= max_bytes:
+ break
+ actual = _remove_entry(path)
+ if not path.exists():
+ removed += 1
+ freed += actual
+ total -= size
+ return removed, freed
+
+
def cleanup_old_caches(
max_age_seconds: int = CACHE_MAX_AGE_SECONDS,
logs_dir: Path | None = None,
@@ -111,12 +158,24 @@ def cleanup_old_caches(
app_dir = resolve_app_temp_dir()
if app_dir is not None:
try:
- removed, freed = sweep_dir_by_age(app_dir, max_age_seconds)
+ removed, freed = sweep_dir_by_age(
+ app_dir, max_age_seconds, excluded_names=frozenset({PREVIEW_CACHE.name}))
removed_total += removed
freed_total += freed
except Exception:
pass
+ try:
+ if PREVIEW_CACHE.is_dir():
+ removed, freed = sweep_dir_by_age(PREVIEW_CACHE, max_age_seconds)
+ removed_total += removed
+ freed_total += freed
+ removed, freed = prune_preview_cache(root=PREVIEW_CACHE)
+ removed_total += removed
+ freed_total += freed
+ except Exception:
+ pass
+
try:
if JOBS.is_dir():
removed, freed = sweep_dir_by_age(JOBS, max_age_seconds)
diff --git a/src/core/dlss_bridge.py b/src/core/dlss_bridge.py
new file mode 100644
index 0000000..fdd512c
--- /dev/null
+++ b/src/core/dlss_bridge.py
@@ -0,0 +1,265 @@
+"""Independent NGX DLSS Super Resolution bridge (ABI 1).
+
+This module deliberately never loads the Neural Rendering or RTX Video engines.
+The native engine owns its D3D12 device, NGX feature, and estimated temporal guides.
+"""
+
+from __future__ import annotations
+
+import ctypes as C
+import threading
+
+import numpy as np
+from PIL import Image
+
+from .dlss_modes import DLSS_MODES, DLSS_PRESETS, dlss_output_size, validate_dlss
+from .gpu_selection import detect_gpu
+from .paths import DLSSSR_BRIDGE, DLSSSR_DIR, DLSSSR_RUNTIME
+
+
+class _SessionDesc(C.Structure):
+ _fields_ = [(name, C.c_uint32) for name in (
+ "size", "abi", "input_width", "input_height", "output_width", "output_height", "mode", "preset")]
+
+
+class _FrameDesc(C.Structure):
+ _fields_ = [
+ ("size", C.c_uint32), ("abi", C.c_uint32), ("input_rgba16f", C.c_void_p),
+ ("input_stride", C.c_uint32), ("output_rgba16f", C.c_void_p),
+ ("output_stride", C.c_uint32), ("reset", C.c_uint32), ("phase", C.c_uint32),
+ ]
+
+
+class _FrameResult(C.Structure):
+ _fields_ = [(name, C.c_uint32) for name in (
+ "size", "abi", "render_width", "render_height", "guide_estimated", "ngx_result", "phase", "reserved")]
+ _fields_.append(("milliseconds", C.c_double))
+
+
+class _CudaFrameDesc(C.Structure):
+ _fields_ = [(name, C.c_uint32) for name in ("size", "abi", "width", "height", "pixel_format")]
+ _fields_ += [("y_pointer", C.c_uint64), ("uv_pointer", C.c_uint64)]
+ _fields_ += [(name, C.c_uint32) for name in (
+ "y_stride", "uv_stride", "color_matrix", "color_range", "rotation",
+ "reset", "phase", "output_p010")]
+
+
+class _CudaSurfaceDesc(C.Structure):
+ _fields_ = [(name, C.c_uint32) for name in (
+ "size", "abi", "width", "height", "pixel_format", "stride")]
+ _fields_ += [("y_pointer", C.c_uint64), ("uv_pointer", C.c_uint64)]
+
+
+_library = None
+_ordinal = None
+_lock = threading.RLock()
+
+
+def _error(buffer: C.Array) -> str:
+ return buffer.value.decode("utf-8", "replace") or "DLSS native engine failed without a diagnostic."
+
+
+def _load(ordinal: int):
+ global _library, _ordinal
+ with _lock:
+ if _library is not None:
+ if _ordinal != ordinal:
+ raise RuntimeError("DLSS is already bound to another GPU; restart the application to switch GPUs.")
+ return _library
+ if not DLSSSR_RUNTIME.is_file() or not DLSSSR_BRIDGE.is_file():
+ raise RuntimeError(f"DLSS bridge or NVIDIA runtime is missing from {DLSSSR_DIR}.")
+ lib = C.CDLL(str(DLSSSR_BRIDGE))
+ lib.dlsssr_abi_version.argtypes = []
+ lib.dlsssr_abi_version.restype = C.c_uint32
+ if lib.dlsssr_abi_version() != 1:
+ raise RuntimeError("DLSS bridge ABI does not match this application.")
+ lib.dlsssr_init.argtypes = [C.c_int, C.c_wchar_p, C.c_void_p, C.c_int]
+ lib.dlsssr_init.restype = C.c_int
+ lib.dlsssr_session_create.argtypes = [C.POINTER(_SessionDesc), C.c_void_p, C.c_int]
+ lib.dlsssr_session_create.restype = C.c_void_p
+ lib.dlsssr_session_release.argtypes = [C.c_void_p]
+ lib.dlsssr_session_release.restype = None
+ lib.dlsssr_process_rgba16f.argtypes = [C.c_void_p, C.POINTER(_FrameDesc), C.POINTER(_FrameResult), C.c_void_p, C.c_int]
+ lib.dlsssr_process_rgba16f.restype = C.c_int
+ lib.dlsssr_process_cuda_yuv.argtypes = [
+ C.c_void_p, C.POINTER(_CudaFrameDesc), C.POINTER(_FrameResult),
+ C.POINTER(C.c_void_p), C.c_void_p, C.c_int]
+ lib.dlsssr_process_cuda_yuv.restype = C.c_int
+ lib.dlsssr_cuda_surface_desc.argtypes = [C.c_void_p, C.POINTER(_CudaSurfaceDesc)]
+ lib.dlsssr_cuda_surface_desc.restype = C.c_int
+ lib.dlsssr_cuda_surface_retain.argtypes = [C.c_void_p]
+ lib.dlsssr_cuda_surface_release.argtypes = [C.c_void_p]
+ error = C.create_string_buffer(1024)
+ if not lib.dlsssr_init(ordinal, str(DLSSSR_DIR), error, len(error)):
+ raise RuntimeError(_error(error))
+ _library, _ordinal = lib, ordinal
+ return lib
+
+
+def initialize_bridge(ordinal: int) -> None:
+ """Register DLSS SR with NGX before another feature fixes search paths."""
+ _load(ordinal)
+
+
+class DLSSSession:
+ def __init__(self, width: int, height: int, mode: str, preset: str = "Default", *,
+ gpu_uuid: str = "auto", even: bool = False):
+ validate_dlss(mode, preset)
+ self.width, self.height = width, height
+ self.output_width, self.output_height = dlss_output_size(width, height, mode, even=even)
+ self.mode, self.preset = mode, preset
+ gpu = detect_gpu(gpu_uuid)
+ self.gpu_name = str(gpu.get("name", "NVIDIA GPU"))
+ self.ordinal = int(gpu.get("cuda_ordinal", gpu.get("index", 0)))
+ self.lib = _load(self.ordinal)
+ desc = _SessionDesc(C.sizeof(_SessionDesc), 1, width, height,
+ self.output_width, self.output_height,
+ tuple(DLSS_MODES).index(mode), DLSS_PRESETS.index(preset))
+ error = C.create_string_buffer(1024)
+ with _lock:
+ self.handle = self.lib.dlsssr_session_create(C.byref(desc), error, len(error))
+ if not self.handle:
+ raise RuntimeError(_error(error))
+ self.frames = 0
+ self.last_result = None
+
+ def process(self, rgba: np.ndarray, *, reset: bool = False, phase: int = 0) -> np.ndarray:
+ if not self.handle:
+ raise RuntimeError("DLSS session is closed.")
+ if rgba.shape != (self.height, self.width, 4):
+ raise ValueError("DLSS input shape does not match the session.")
+ if rgba.dtype == np.uint8:
+ source = np.ascontiguousarray(rgba[..., :4].astype(np.float32) / 255, dtype=np.float16)
+ elif rgba.dtype == np.uint16:
+ source = np.ascontiguousarray(rgba[..., :4].astype(np.float32) / 65535, dtype=np.float16)
+ else:
+ source = np.ascontiguousarray(rgba[..., :4], dtype=np.float16)
+ output = np.empty((self.output_height, self.output_width, 4), dtype=np.float16)
+ frame = _FrameDesc(C.sizeof(_FrameDesc), 1, source.ctypes.data, source.strides[0],
+ output.ctypes.data, output.strides[0], int(reset), phase)
+ result = _FrameResult()
+ result.size, result.abi = C.sizeof(_FrameResult), 1
+ error = C.create_string_buffer(1024)
+ with _lock:
+ ok = self.lib.dlsssr_process_rgba16f(self.handle, C.byref(frame), C.byref(result), error, len(error))
+ if not ok:
+ raise RuntimeError(_error(error))
+ self.frames += 1
+ self.last_result = result
+ return output
+
+ def process_cuda_frame(self, frame, *, color_matrix: int = 1,
+ color_range: int = 0, rotation: int = 0,
+ reset: bool = False, phase: int = 0,
+ output_p010: bool = False):
+ """Evaluate NVDEC NV12/P010 and return a CUDA AVFrame for NVENC/NR."""
+ if not self.handle:
+ raise RuntimeError("DLSS session is closed.")
+ if getattr(getattr(frame, "format", None), "name", "") != "cuda":
+ raise ValueError("DLSS CUDA input must be a CUDA decoded video frame.")
+ pixel_format = {"nv12": 4, "p010": 5, "p010le": 5}.get(
+ getattr(getattr(frame, "sw_format", None), "name", ""))
+ if pixel_format is None or len(frame.planes) < 2:
+ raise ValueError("DLSS CUDA input must expose NV12 or P010 planes.")
+ source = _CudaFrameDesc(
+ C.sizeof(_CudaFrameDesc), 1, frame.width, frame.height, pixel_format,
+ int(frame.planes[0].buffer_ptr), int(frame.planes[1].buffer_ptr),
+ int(frame.planes[0].line_size), int(frame.planes[1].line_size),
+ int(color_matrix), int(color_range), int(rotation), int(reset),
+ int(phase), int(output_p010))
+ result = _FrameResult()
+ result.size, result.abi = C.sizeof(_FrameResult), 1
+ handle = C.c_void_p()
+ error = C.create_string_buffer(1024)
+ with _lock:
+ ok = self.lib.dlsssr_process_cuda_yuv(
+ self.handle, C.byref(source), C.byref(result), C.byref(handle), error, len(error))
+ if not ok:
+ raise RuntimeError(_error(error))
+ if not handle.value:
+ raise RuntimeError("DLSS returned no CUDA output surface.")
+ surface = _CudaSurfaceDesc()
+ surface.size, surface.abi = C.sizeof(_CudaSurfaceDesc), 1
+ if not self.lib.dlsssr_cuda_surface_desc(handle, C.byref(surface)):
+ self.lib.dlsssr_cuda_surface_release(handle)
+ raise RuntimeError("DLSS returned an invalid CUDA output surface.")
+ from .neural_bridge import _DLPackPlane
+ import av
+ released = False
+
+ def retain():
+ self.lib.dlsssr_cuda_surface_retain(handle)
+
+ def release():
+ self.lib.dlsssr_cuda_surface_release(handle)
+
+ bits = 16 if surface.pixel_format == 5 else 8
+ item_size = bits // 8
+ y = _DLPackPlane(
+ pointer=surface.y_pointer, shape=(surface.height, surface.width),
+ strides=(surface.stride // item_size, 1), bits=bits,
+ device_id=self.ordinal, retain=retain, release=release)
+ uv = _DLPackPlane(
+ pointer=surface.uv_pointer,
+ shape=((surface.height + 1) // 2, (surface.width + 1) // 2, 2),
+ strides=(surface.stride // item_size, 2, 1), bits=bits,
+ device_id=self.ordinal, retain=retain, release=release)
+ try:
+ output = av.VideoFrame.from_dlpack(
+ [y, uv], format="p010le" if bits == 16 else "nv12",
+ width=surface.width, height=surface.height,
+ device_id=self.ordinal, primary_ctx=True)
+ finally:
+ if not released:
+ release()
+ released = True
+ self.frames += 1
+ self.last_result = result
+ return output, {
+ "input_ms": 0.0, "ngx_ms": result.milliseconds,
+ "output_ms": 0.0, "scene_cut": bool(result.reserved),
+ "gpu_pre_resize": (result.render_width, result.render_height) != (self.width, self.height),
+ }
+
+ def close(self):
+ if self.handle:
+ with _lock:
+ self.lib.dlsssr_session_release(self.handle)
+ self.handle = None
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *_):
+ self.close()
+
+
+def process_image(rgba: np.ndarray, mode: str, preset: str = "Default", *,
+ gpu_uuid: str = "auto", controller=None):
+ """Evaluate a still once; duplicate frames contain no new spatial samples."""
+ height, width = rgba.shape[:2]
+ with DLSSSession(width, height, mode, preset, gpu_uuid=gpu_uuid) as session:
+ if controller is not None and controller.cancel.is_set():
+ from .jobs import Cancelled
+ raise Cancelled("DLSS image processing stopped by user.")
+ result = session.process(rgba, reset=True)
+ high_depth = rgba.dtype == np.uint16
+ levels = 65535 if high_depth else 255
+ processed = np.rint(np.clip(result.astype(np.float32), 0, 1) * levels).astype(
+ np.uint16 if high_depth else np.uint8)
+ if rgba.shape[2] == 4:
+ alpha = Image.fromarray(rgba[..., 3]).resize(
+ (session.output_width, session.output_height), Image.Resampling.LANCZOS)
+ processed[..., 3] = np.clip(np.asarray(alpha), 0, levels).astype(processed.dtype)
+ return processed, {
+ "engine": "DLSS Super Resolution", "mode": mode, "preset": preset,
+ "evaluations": 1, "guide_estimated": True,
+ "media_pipeline": "source-anchored DLSS",
+ "synthetic_jitter": False,
+ "render_width": session.last_result.render_width,
+ "render_height": session.last_result.render_height,
+ "gpu_pre_resize": (session.last_result.render_width,
+ session.last_result.render_height) != (width, height),
+ "ngx_result": f"0x{session.last_result.ngx_result:08X}",
+ "gpu": session.gpu_name,
+ }
diff --git a/src/core/dlss_modes.py b/src/core/dlss_modes.py
new file mode 100644
index 0000000..6a638d6
--- /dev/null
+++ b/src/core/dlss_modes.py
@@ -0,0 +1,38 @@
+"""User-facing DLSS Super Resolution modes and output sizing."""
+
+from __future__ import annotations
+
+import math
+
+# Each media frame is evaluated once. Repeating a resolved still cannot
+# reproduce the new geometry samples supplied by a jittered game renderer.
+DLSS_MODES = {
+ "DLAA": (1.0, 1),
+ "Quality": (1.5, 1),
+ "Balanced": (1.724, 1),
+ "Performance": (2.0, 1),
+ "Ultra Performance": (3.0, 1),
+}
+DLSS_PRESETS = ("Default", "J", "K", "L", "M")
+DLSS_METHODS = ("Standard", "DLSS")
+UPSCALE_ENGINES = ("RTX Video Super Resolution", "DLSS")
+
+
+def validate_dlss(mode: str, preset: str) -> None:
+ if mode not in DLSS_MODES:
+ raise ValueError(f"Unknown DLSS mode: {mode!r}.")
+ if preset not in DLSS_PRESETS:
+ raise ValueError(f"Unknown DLSS preset: {preset!r}.")
+
+
+def dlss_output_size(width: int, height: int, mode: str, *, even: bool = False) -> tuple[int, int]:
+ if mode not in DLSS_MODES:
+ raise ValueError(f"Unknown DLSS mode: {mode!r}.")
+ if width < 32 or height < 32:
+ raise ValueError("DLSS input must be at least 32×32 pixels.")
+ factor = DLSS_MODES[mode][0]
+ rounder = (lambda value: max(2, math.ceil(value / 2) * 2)) if even else math.ceil
+ output = rounder(width * factor), rounder(height * factor)
+ if max(output) > 16384:
+ raise ValueError("DLSS output exceeds the 16384-pixel texture limit.")
+ return output
diff --git a/src/core/ffmpeg/__init__.py b/src/core/ffmpeg/__init__.py
index 96264d2..3e317a5 100644
--- a/src/core/ffmpeg/__init__.py
+++ b/src/core/ffmpeg/__init__.py
@@ -14,6 +14,7 @@ from .preview import (
resolve_final_preview, resolve_preview_codec, wants_compat_preview,
)
from .probe import preview_frame_count, probe_video
+from .precision import chroma_location_code, decoded_rgba, output_video_depth
__all__ = [
"AUTO_BITRATE_DIVISORS", "AudioPlan", "CODEC_CHOICES", "DEFAULT_PREVIEW_ENCODING",
@@ -24,4 +25,6 @@ __all__ = [
"probe_video", "resolve_encoding_quality", "resolve_final_preview",
"resolve_preview_codec", "resolve_video_gpu", "start_encoder",
"validate_codec_container", "verify_mux_comment", "wants_compat_preview",
+ "decoded_rgba", "output_video_depth",
+ "chroma_location_code",
]
diff --git a/src/core/ffmpeg/codecs.py b/src/core/ffmpeg/codecs.py
index 26f8bc8..90291de 100644
--- a/src/core/ffmpeg/codecs.py
+++ b/src/core/ffmpeg/codecs.py
@@ -142,13 +142,11 @@ def _hdr_color_args(metadata: dict | None) -> list[str]:
trc = metadata.get("color_transfer")
if isinstance(trc, str) and trc not in ("unknown", "", None):
args.extend(["-color_trc", trc])
- # color_range is not probed currently; default tv for HDR
- # If HDR, ensure range is tv
- if metadata.get("hdr"):
- # Ensure we signal full vs limited correctly – probe doesn't give range, use tv
- # Don't double-add if already present
- if "-color_range" not in args:
- args.extend(["-color_range", "tv"])
+ color_range = str(metadata.get("color_range") or "").lower()
+ if color_range in {"pc", "jpeg", "full"}:
+ args.extend(["-color_range", "pc"])
+ elif color_range in {"tv", "mpeg", "limited"}:
+ args.extend(["-color_range", "tv"])
return args
@@ -169,7 +167,9 @@ def _x265_hdr_params(metadata: dict | None) -> str | None:
cmat = mapping["color_space"] if mapping["color_space"] not in ("unknown", "", None) else "bt709"
# x265 colormatrix for bt2020nc is bt2020nc, for bt709 is bt709
# Ensure x265-compatible values: bt2020nc is valid, bt709 is valid
- return f"colorprim={prim}:transfer={trc}:colormatrix={cmat}:range=limited"
+ color_range = str(metadata.get("color_range") or "").lower()
+ range_name = "full" if color_range in {"pc", "jpeg", "full"} else "limited"
+ return f"colorprim={prim}:transfer={trc}:colormatrix={cmat}:range={range_name}"
def validate_codec_container(codec: str, container: str) -> None:
diff --git a/src/core/ffmpeg/encoder.py b/src/core/ffmpeg/encoder.py
index 1e0c10c..4c049de 100644
--- a/src/core/ffmpeg/encoder.py
+++ b/src/core/ffmpeg/encoder.py
@@ -143,7 +143,7 @@ def _codec_command(
hdr_mode: bool = False,
hdr_metadata: dict | None = None,
*,
- speed_profile: str = "default",
+ speed_profile: str = "default", output_depth: int | None = None,
) -> tuple[list[str], str, dict]:
"""Return FFmpeg codec args for an explicit user-facing codec choice.
@@ -164,11 +164,11 @@ def _codec_command(
f"HDR Mode is not available for {codec!r}; choose H.265, H.265 (NVIDIA NVENC), "
"AV1, AV1 (NVIDIA NVENC), ProRes, or FFV1 Lossless RGB 10-bit."
)
- # HDR mode needs 10-bit divisor
- quality = resolve_encoding_quality(quality_name, codec, width, height, fps, hdr_mode=hdr_mode)
+ high_depth = hdr_mode or (output_depth is not None and output_depth > 8)
+ quality = resolve_encoding_quality(quality_name, codec, width, height, fps, hdr_mode=high_depth)
# ProRes Proxy is always 10-bit; HDR just copies colorspace
if norm == "ProRes Proxy":
- hdr_extra = _hdr_color_args(hdr_metadata) if hdr_mode and hdr_metadata else []
+ hdr_extra = _hdr_color_args(hdr_metadata) if hdr_metadata else []
prores_quality = (
["-bits_per_mb", str(int(quality["bits_per_mb"]))]
if quality.get("bits_per_mb") is not None
@@ -185,7 +185,7 @@ def _codec_command(
if norm == "ProRes HQ":
return (
["-c:v", "prores_ks", "-profile:v", "3", "-pix_fmt", "yuv422p10le",
- *(_hdr_color_args(hdr_metadata) if hdr_mode and hdr_metadata else [])],
+ *(_hdr_color_args(hdr_metadata) if hdr_metadata else [])],
"prores_ks (HQ)", quality,
)
if norm == "FFV1 Lossless RGB 10-bit":
@@ -203,7 +203,13 @@ def _codec_command(
nvenc_quality = ["-rc", "vbr", "-b:v", bitrate]
software_quality = ["-b:v", bitrate]
gpu_args = ["-gpu", str(gpu_ordinal)] if gpu_ordinal is not None else []
- hdr_color = _hdr_color_args(hdr_metadata) if hdr_mode and hdr_metadata else []
+ signal_metadata = hdr_metadata
+ if high_depth and not hdr_mode:
+ signal_metadata = dict(hdr_metadata or {})
+ for field in ("color_space", "color_primaries", "color_transfer"):
+ if signal_metadata.get(field) in (None, "", "unknown", "unspecified"):
+ signal_metadata[field] = "bt709"
+ hdr_color = _hdr_color_args(signal_metadata) if signal_metadata else []
# CPU variants – never probe NVENC, always use software encoder
if norm == "H.264":
@@ -214,8 +220,11 @@ def _codec_command(
)
if hdr_mode:
raise ValueError("HDR Mode is not available for H.264; choose H.265/AV1/ProRes.")
+ x264_color = _x265_hdr_params(signal_metadata)
return (
- ["-c:v", "libx264", "-preset", software_preset, *software_quality, "-pix_fmt", "yuv420p"],
+ ["-c:v", "libx264", "-preset", software_preset, *software_quality,
+ "-pix_fmt", "yuv420p",
+ *(["-x264-params", x264_color] if x264_color else []), *hdr_color],
"libx264",
quality,
)
@@ -224,14 +233,19 @@ def _codec_command(
raise RuntimeError(
f"H.265 (CPU) was requested but NVENC was required; choose H.265 (NVIDIA NVENC) for GPU encoding."
)
- # HDR → 10-bit yuv420p10le, SDR → yuv420p.
- pix_fmt = "yuv420p10le" if hdr_mode else "yuv420p"
- if hdr_mode:
- x265_params = _x265_hdr_params(hdr_metadata)
+ # Source precision or HDR selects 10-bit independently of SDR transfer.
+ pix_fmt = "yuv420p10le" if high_depth else "yuv420p"
+ if high_depth:
+ x265_params = _x265_hdr_params(signal_metadata)
x265_extra = ["-x265-params", x265_params] if x265_params else []
- # For x265, use x265-params exclusively for HDR (generic breaks VUI)
+ range_extra = (
+ ["-color_range", "pc"]
+ if str((signal_metadata or {}).get("color_range") or "").lower()
+ in {"pc", "jpeg", "full"} else []
+ )
+ # x265 owns VUI color fields; the generic range flag also tags the stream.
return (
- ["-c:v", "libx265", "-preset", software_preset, *software_quality, "-pix_fmt", pix_fmt, *x265_extra],
+ ["-c:v", "libx265", "-preset", software_preset, *software_quality, "-pix_fmt", pix_fmt, *x265_extra, *range_extra],
"libx265",
quality,
)
@@ -245,7 +259,7 @@ def _codec_command(
raise RuntimeError(
"AV1 (CPU) was requested but NVENC was required; choose AV1 (NVIDIA NVENC) for GPU encoding."
)
- pix_fmt = "yuv420p10le" if hdr_mode else "yuv420p"
+ pix_fmt = "yuv420p10le" if high_depth else "yuv420p"
# Prefer libsvtav1 (fastest CPU AV1), fallback to libaom-av1
if _cpu_encoder_available("libsvtav1"):
if quality["mode"] == "constant-quality":
@@ -299,7 +313,7 @@ def _codec_command(
f"H.265 (NVIDIA NVENC) cannot encode {width}×{height} on the selected Video Processing GPU. "
"Choose H.265 (CPU) or another GPU."
)
- pix_fmt = "p010le" if hdr_mode else "yuv420p"
+ pix_fmt = "p010le" if high_depth else "yuv420p"
# HEVC HDR should use main10 implicitly via p010le
return (
[
@@ -315,7 +329,7 @@ def _codec_command(
f"AV1 (NVIDIA NVENC) cannot encode {width}×{height} on the selected GPU/driver. "
"Choose AV1 (CPU) with libsvtav1, or H.264/H.265, or a lower upscaling factor."
)
- pix_fmt = "p010le" if hdr_mode else "yuv420p"
+ pix_fmt = "p010le" if high_depth else "yuv420p"
return (
["-c:v", "av1_nvenc", *gpu_args, "-preset", "p6", *nvenc_quality, "-pix_fmt", pix_fmt, *hdr_color],
"av1_nvenc",
@@ -342,14 +356,20 @@ def start_encoder(
speed_profile: str = "default", source_audio: Path | None = None,
direct_container: str | None = None, comment: str | None = None,
audio_duration: float | None = None, include_source_metadata: bool = True,
- audio_plan: AudioPlan | None = None,
+ audio_plan: AudioPlan | None = None, output_depth: int | None = None,
):
codec_args, selected, quality = _codec_command(
codec, quality_name, width, height, fps, gpu_ordinal, require_nvenc, hdr_mode, hdr_metadata,
- speed_profile=speed_profile,
+ speed_profile=speed_profile, output_depth=output_depth,
)
normalized_codec = _normalize_codec(codec)
- if normalized_codec in {"ProRes HQ", "FFV1 Lossless RGB 10-bit"}:
+ if (output_depth is not None and output_depth > 8
+ and str((hdr_metadata or {}).get("color_range") or "").lower()
+ in {"pc", "jpeg", "full"}
+ and normalized_codec in {"H.265", "HEVC", "AV1"}):
+ range_filter = "scale=in_range=pc:out_range=pc"
+ video_filter = f"{video_filter},{range_filter}" if video_filter else range_filter
+ if normalized_codec in {"ProRes Proxy", "ProRes HQ", "FFV1 Lossless RGB 10-bit"}:
colors = hdr_metadata or {}
primaries = str(colors.get("color_primaries") or "bt709")
transfer = str(colors.get("color_transfer") or "bt709")
diff --git a/src/core/ffmpeg/mux.py b/src/core/ffmpeg/mux.py
index 421a2af..d10e097 100644
--- a/src/core/ffmpeg/mux.py
+++ b/src/core/ffmpeg/mux.py
@@ -12,6 +12,7 @@ from ..render_metadata import (
)
from ..paths import FFMPEG, FFPROBE
from .audio import AudioPlan, plan_audio_streams
+from .codecs import _hdr_color_args
from .probe import _run_json
def _probe_rendered_duration(path: Path, controller: JobController | None = None) -> float:
@@ -100,6 +101,8 @@ def final_mux(
preserve_supported_subtitles: bool = False,
*, render_note: str | None = None, metadata_diagnostics: dict | None = None,
source_time_origin: float | None = None, audio_diagnostics: dict | None = None,
+ video_bitstream_filter: str | None = None,
+ video_color_metadata: dict | None = None,
) -> None:
check_cancelled(controller)
audio_plan = plan_audio_streams(source, container, controller)
@@ -110,7 +113,7 @@ def final_mux(
record_embedding(metadata_diagnostics, "skipped", reason="unsupported_format")
elif metadata_diagnostics is not None and not metadata_diagnostics:
record_embedding(metadata_diagnostics, "not_requested")
- _final_mux_once(temp_video, source, output, container, controller, preserve_supported_subtitles, audio_plan, source_time_origin=source_time_origin)
+ _final_mux_once(temp_video, source, output, container, controller, preserve_supported_subtitles, audio_plan, source_time_origin=source_time_origin, video_bitstream_filter=video_bitstream_filter, video_color_metadata=video_color_metadata)
return
try:
@@ -123,12 +126,12 @@ def final_mux(
except (ValueError, TypeError, RuntimeError) as exc:
check_cancelled(controller)
embedding_warning(metadata_diagnostics, exc)
- _final_mux_once(temp_video, source, output, container, controller, preserve_supported_subtitles, audio_plan, source_time_origin=source_time_origin)
+ _final_mux_once(temp_video, source, output, container, controller, preserve_supported_subtitles, audio_plan, source_time_origin=source_time_origin, video_bitstream_filter=video_bitstream_filter, video_color_metadata=video_color_metadata)
return
try:
_final_mux_once(temp_video, source, output, container, controller,
- preserve_supported_subtitles, audio_plan, comment=comment, source_time_origin=source_time_origin)
+ preserve_supported_subtitles, audio_plan, comment=comment, source_time_origin=source_time_origin, video_bitstream_filter=video_bitstream_filter, video_color_metadata=video_color_metadata)
except Cancelled:
raise
except (ValueError, RuntimeError) as exc:
@@ -138,7 +141,7 @@ def final_mux(
# A mux failure caused by optional metadata should not destroy the render.
# Retry once without the note because there is not yet a valid output.
embedding_warning(metadata_diagnostics, exc)
- _final_mux_once(temp_video, source, output, container, controller, preserve_supported_subtitles, audio_plan, source_time_origin=source_time_origin)
+ _final_mux_once(temp_video, source, output, container, controller, preserve_supported_subtitles, audio_plan, source_time_origin=source_time_origin, video_bitstream_filter=video_bitstream_filter, video_color_metadata=video_color_metadata)
return
# Verification is deliberately read-only. If the optional settings note did
@@ -177,6 +180,8 @@ def _final_mux_once(
temp_video: Path, source: Path, output: Path, container: str,
controller: JobController | None, preserve_supported_subtitles: bool, audio_plan: AudioPlan,
*, comment: str | None = None, source_time_origin: float | None = None,
+ video_bitstream_filter: str | None = None,
+ video_color_metadata: dict | None = None,
) -> None:
check_cancelled(controller)
duration = _probe_rendered_duration(temp_video, controller)
@@ -237,6 +242,8 @@ def _final_mux_once(
"-map_chapters",
"1",
*streams,
+ *_hdr_color_args(video_color_metadata),
+ *(["-bsf:v", video_bitstream_filter] if video_bitstream_filter else []),
*(["-avoid_negative_ts", "disabled", "-metadata:s:v:0", "rotate=0"] if source_time_origin is not None else []),
*(["-metadata", "comment=" + comment] if comment is not None else []),
str(output),
diff --git a/src/core/ffmpeg/precision.py b/src/core/ffmpeg/precision.py
new file mode 100644
index 0000000..70bc1ee
--- /dev/null
+++ b/src/core/ffmpeg/precision.py
@@ -0,0 +1,25 @@
+"""Keep sample depth independent from HDR transfer and signaling."""
+
+from .codecs import _normalize_codec
+
+
+def output_video_depth(source_depth: int, codec: str, hdr_mode: bool = False) -> int:
+ name = _normalize_codec(codec)
+ if name in {"H.264", "H.264 (NVIDIA NVENC)"}:
+ return 8
+ if name in {"ProRes Proxy", "ProRes HQ", "FFV1 Lossless RGB 10-bit"}:
+ return 10
+ return 10 if int(source_depth) > 8 or hdr_mode else 8
+
+
+def decoded_rgba(frame, source_depth: int):
+ """Decode to 16-bit RGBA before processing whenever source precision exceeds 8 bits."""
+ return frame.to_ndarray(format="rgba64le" if int(source_depth) > 8 else "rgba")
+
+
+def chroma_location_code(metadata: dict) -> int:
+ """FFmpeg AVChromaLocation value; unspecified 4:2:0 uses MPEG left siting."""
+ return {"left": 1, "center": 2, "topleft": 3, "top": 4,
+ "bottomleft": 5, "bottom": 6}.get(
+ str(metadata.get("chroma_location") or "").casefold(), 1
+ )
diff --git a/src/core/ffmpeg/probe.py b/src/core/ffmpeg/probe.py
index d034a34..fb0f53f 100644
--- a/src/core/ffmpeg/probe.py
+++ b/src/core/ffmpeg/probe.py
@@ -138,7 +138,7 @@ def probe_video(
"-select_streams",
"v:0",
"-show_entries",
- "stream=index,codec_name,pix_fmt,bits_per_raw_sample,width,height,avg_frame_rate,r_frame_rate,time_base,duration,nb_frames,nb_read_frames,nb_read_packets,color_range,color_primaries,color_transfer,color_space:stream_tags=rotate:stream_side_data=rotation",
+ "stream=index,codec_name,pix_fmt,bits_per_raw_sample,width,height,avg_frame_rate,r_frame_rate,time_base,duration,nb_frames,nb_read_frames,nb_read_packets,color_range,color_primaries,color_transfer,color_space,chroma_location:stream_tags=rotate:stream_side_data=rotation",
"-show_entries",
"format=duration,format_name",
"-of",
@@ -225,6 +225,7 @@ def probe_video(
"color_primaries": primaries,
"color_space": color_space,
"color_range": color_range,
+ "chroma_location": stream.get("chroma_location") or "unknown",
"hdr": transfer in {"smpte2084", "arib-std-b67"},
}
diff --git a/src/core/gpu_memory.py b/src/core/gpu_memory.py
new file mode 100644
index 0000000..5dcc966
--- /dev/null
+++ b/src/core/gpu_memory.py
@@ -0,0 +1,95 @@
+from __future__ import annotations
+
+"""Sample total adapter VRAM during a render through NVIDIA's NVML API."""
+
+import ctypes
+import threading
+
+
+class _MemoryInfo(ctypes.Structure):
+ _fields_ = [
+ ("total", ctypes.c_ulonglong),
+ ("free", ctypes.c_ulonglong),
+ ("used", ctypes.c_ulonglong),
+ ]
+
+
+class GPUVramTracker:
+ """Observe device use; the delta includes other processes on the adapter."""
+
+ def __init__(self, index: int) -> None:
+ self._nvml = None
+ self._device = ctypes.c_void_p()
+ self._stop = threading.Event()
+ self._thread: threading.Thread | None = None
+ self._lock = threading.Lock()
+ self._baseline = 0
+ self._peak = 0
+ self._samples = 0
+ try:
+ nvml = ctypes.WinDLL("nvml.dll")
+ nvml.nvmlInit_v2.restype = ctypes.c_int
+ nvml.nvmlShutdown.restype = ctypes.c_int
+ nvml.nvmlDeviceGetHandleByIndex_v2.argtypes = [
+ ctypes.c_uint, ctypes.POINTER(ctypes.c_void_p)
+ ]
+ nvml.nvmlDeviceGetHandleByIndex_v2.restype = ctypes.c_int
+ nvml.nvmlDeviceGetMemoryInfo.argtypes = [
+ ctypes.c_void_p, ctypes.POINTER(_MemoryInfo)
+ ]
+ nvml.nvmlDeviceGetMemoryInfo.restype = ctypes.c_int
+ if nvml.nvmlInit_v2():
+ return
+ if nvml.nvmlDeviceGetHandleByIndex_v2(int(index), ctypes.byref(self._device)):
+ nvml.nvmlShutdown()
+ return
+ self._nvml = nvml
+ self._sample()
+ self._thread = threading.Thread(
+ target=self._run, name="dlss5-vram-sampler", daemon=True
+ )
+ self._thread.start()
+ except (AttributeError, OSError):
+ self._nvml = None
+
+ def _sample(self) -> None:
+ if self._nvml is None:
+ return
+ info = _MemoryInfo()
+ if self._nvml.nvmlDeviceGetMemoryInfo(self._device, ctypes.byref(info)):
+ return
+ with self._lock:
+ used = int(info.used)
+ if not self._samples:
+ self._baseline = used
+ self._peak = max(self._peak, used)
+ self._samples += 1
+
+ def _run(self) -> None:
+ while not self._stop.wait(0.1):
+ self._sample()
+
+ def snapshot(self) -> dict[str, object]:
+ self._sample()
+ with self._lock:
+ if not self._samples:
+ return {"status": "unavailable"}
+ mib = 1024 * 1024
+ return {
+ "status": "sampled",
+ "scope": "total_adapter_used_memory",
+ "baseline_mib": round(self._baseline / mib, 1),
+ "peak_mib": round(self._peak / mib, 1),
+ "peak_delta_mib": round(max(0, self._peak - self._baseline) / mib, 1),
+ "samples": self._samples,
+ }
+
+ def close(self) -> None:
+ self._stop.set()
+ if self._thread is not None:
+ self._thread.join(timeout=1)
+ self._thread = None
+ self._sample()
+ if self._nvml is not None:
+ self._nvml.nvmlShutdown()
+ self._nvml = None
diff --git a/src/core/neural_bridge.py b/src/core/neural_bridge.py
index 51cd639..60c3c27 100644
--- a/src/core/neural_bridge.py
+++ b/src/core/neural_bridge.py
@@ -25,6 +25,7 @@ from .ngx_runtime import NGX_RUNTIME_LOCK
BRIDGE_ABI_VERSION = 6
+BRIDGE_FRAME_ABI_MAX_VERSION = 7
BRIDGE_WATCHDOG_SECONDS = 45.0
MEMORY_HOST = 0
MEMORY_CUDA = 1
@@ -32,6 +33,7 @@ MEMORY_NONE = 2
FORMAT_RGBA8 = 1
FORMAT_NV12 = 2
FORMAT_P010 = 3
+FORMAT_RGBA16LE = 4
def _bridge_failure_requires_restart(detail: str) -> bool:
@@ -311,7 +313,7 @@ class _CudaDriver:
except OSError as exc:
raise NeuralBridgeError(
"CUDA interoperability is unavailable because nvcuda.dll could not be "
- "loaded. Switch GPU OFF to use the bridge host-staging path."
+ "loaded. Neural Rendering requires CUDA/D3D12 interoperability."
) from exc
self._bind("cuInit", [ctypes.c_uint])
@@ -585,6 +587,10 @@ class BridgeSessionDiagnostics:
decode_backend: str = "software"
encode_backend: str = "cpu"
pixel_format: str = "rgba8"
+ source_format: str = "unknown"
+ working_format: str = "rgba8"
+ ngx_format: str = "rgba16f"
+ output_format: str = "unknown"
frames: int = 0
feature_evaluations: int = 0
scene_resets: int = 0
@@ -597,11 +603,16 @@ class BridgeSessionDiagnostics:
def as_dict(self) -> dict[str, Any]:
return {
"bridge_abi_version": BRIDGE_ABI_VERSION,
+ "bridge_frame_abi_max_version": BRIDGE_FRAME_ABI_MAX_VERSION,
"gpu_mode": self.gpu_mode,
"memory_path": self.memory_path,
"decode_backend": self.decode_backend,
"encode_backend": self.encode_backend,
"pixel_format": self.pixel_format,
+ "source_format": self.source_format,
+ "working_format": self.working_format,
+ "ngx_format": self.ngx_format,
+ "output_format": self.output_format,
"frames": self.frames,
"feature_evaluations": self.feature_evaluations,
"scene_resets": self.scene_resets,
@@ -869,6 +880,8 @@ class NeuralBridgeManager:
ctypes.c_int,
]
library.dlss5nr_process_frame_v6.restype = ctypes.c_int
+ library.dlss5nr_process_frame_v7.argtypes = library.dlss5nr_process_frame_v6.argtypes
+ library.dlss5nr_process_frame_v7.restype = ctypes.c_int
library.dlss5nr_temporal_status.argtypes = [ctypes.c_char_p, ctypes.c_int]
library.dlss5nr_temporal_status.restype = ctypes.c_int
library.dlss5nr_scene_score_v1.argtypes = [
@@ -948,24 +961,33 @@ class NeuralBridgeManager:
) from failure[0]
return result[0]
- def initialize(self, gpu: dict[str, Any], *, require_cuda: bool) -> dict[str, Any]:
+ def initialize(self, gpu: dict[str, Any]) -> dict[str, Any]:
with self._lock:
self._guard_poison()
ordinal = int(gpu.get("cuda_ordinal", gpu.get("index", 0)))
if self._initialized_ordinal is None:
# The NVIDIA D3D12 NGX core keeps the first feature search path
# for the lifetime of the process. If Neural Rendering starts
- # first, a later DLSSG initialization succeeds superficially
- # but reports Frame Generation as unavailable. Prime DLSSG on
- # the same adapter before Feature 18; failure remains isolated
- # so systems without the optional DLSSG runtime can still use
- # Neural Rendering.
+ # first, later SR or Frame Generation initialization may report
+ # the feature unavailable. The DLSSG bridge registers both
+ # independent runtime directories. If DLSSG is missing, prime
+ # SR directly before Feature 18. Optional failures remain
+ # isolated from standard Neural Rendering.
+ frame_generation_ready = False
try:
from ..frame_interpolation.native import initialize_bridge
initialize_bridge(ordinal)
+ frame_generation_ready = True
except Exception:
pass
+ if not frame_generation_ready:
+ try:
+ from .dlss_bridge import initialize_bridge as initialize_dlss
+
+ initialize_dlss(ordinal)
+ except Exception:
+ pass
self._load()
if self._initialized_ordinal is None:
assert self._library is not None
@@ -1024,13 +1046,12 @@ class NeuralBridgeManager:
self._library.dlss5nr_cuda_status(cuda_status, len(cuda_status))
)
cuda_detail = _text(cuda_status.value) or "unavailable"
- if require_cuda and not cuda_ready:
+ if not cuda_ready:
raise NeuralBridgeError(
f"CUDA/D3D12 interoperability is unavailable ({cuda_detail}). "
- "Switch GPU OFF to use host staging; Neural Rendering still requires "
- "an RTX GPU."
+ "Neural Rendering requires a supported RTX GPU and driver."
)
- if require_cuda and self._cuda_driver is None:
+ if self._cuda_driver is None:
try:
self._cuda_driver = _CudaDriver(ordinal)
# Do not leave the primary context current on the UI/decoder
@@ -1038,12 +1059,12 @@ class NeuralBridgeManager:
self._cuda_driver.deactivate()
except Exception as exc:
raise NeuralBridgeError(
- f"CUDA/D3D12 interoperability setup failed: {exc} Switch GPU OFF "
- "to use host staging."
+ f"CUDA/D3D12 interoperability setup failed: {exc}"
) from exc
return {
"bridge_version": self._version,
"bridge_abi_version": BRIDGE_ABI_VERSION,
+ "bridge_frame_abi_max_version": BRIDGE_FRAME_ABI_MAX_VERSION,
"gpu_name": self._gpu_name,
"adapter_luid": _text(self._library.dlss5nr_adapter_luid()) or "unknown",
"cuda_ordinal": ordinal,
@@ -1075,8 +1096,7 @@ class NeuralBridgeManager:
self._guard_poison()
if self._cuda_driver is None:
raise NeuralBridgeError(
- "CUDA/D3D12 interoperability is not initialized. Switch GPU OFF to "
- "use host staging."
+ "CUDA/D3D12 interoperability is not initialized."
)
try:
return CudaFrameBuffers.create(self._cuda_driver, width, height)
@@ -1101,8 +1121,7 @@ class NeuralBridgeManager:
self._guard_poison()
if self._library is None or self._cuda_driver is None:
raise NeuralBridgeError(
- "CUDA/D3D12 interoperability is not initialized. Switch GPU OFF to "
- "use host staging."
+ "CUDA/D3D12 interoperability is not initialized."
)
if pixel_format not in (FORMAT_NV12, FORMAT_P010):
raise NeuralBridgeError("CUDA video output must be NV12 or P010.")
@@ -1117,8 +1136,7 @@ class NeuralBridgeManager:
if not handle:
detail = _text(error.value) or "unknown CUDA output allocation failure"
raise NeuralBridgeError(
- f"CUDA/D3D12 output allocation failed: {detail}. Switch GPU OFF to "
- "use host staging."
+ f"CUDA/D3D12 output allocation failed: {detail}."
)
descriptor = FrameDescriptorV1.empty()
if not self._library.dlss5nr_surface_frame_desc(
@@ -1183,6 +1201,7 @@ class NeuralBridgeManager:
color_matrix: int = 1,
color_range: int = 0,
rotation: int = 0,
+ chroma_location: int = 1,
) -> tuple[Any, dict[str, Any], float]:
"""Evaluate a PyAV CUDA frame and return a CUDA AVFrame for NVENC.
@@ -1194,8 +1213,7 @@ class NeuralBridgeManager:
self._guard_poison()
if self._library is None or self._cuda_driver is None:
raise NeuralBridgeError(
- "CUDA/D3D12 interoperability is not initialized. Switch GPU OFF to "
- "use host staging."
+ "CUDA/D3D12 interoperability is not initialized."
)
format_name = str(getattr(getattr(frame, "format", None), "name", ""))
if format_name != "cuda":
@@ -1229,6 +1247,7 @@ class NeuralBridgeManager:
source.color_matrix = int(color_matrix)
source.color_range = int(color_range)
source.rotation = int(rotation) % 360
+ source.reserved = int(chroma_location)
source.timestamp = int(timestamp)
surface = self.create_video_surface(
@@ -1265,8 +1284,7 @@ class NeuralBridgeManager:
f"{detail}. Restart the application before rendering again."
)
raise NeuralBridgeError(
- f"CUDA/D3D12 Neural Rendering failed: {detail}. Switch GPU OFF to "
- "use host staging."
+ f"CUDA/D3D12 Neural Rendering failed: {detail}."
)
# AVFrame.from_dlpack establishes its own primary-context
# references; do not leak the bridge's current context into
@@ -1353,8 +1371,7 @@ class NeuralBridgeManager:
if not ok:
detail = _text(error.value) or "unknown CUDA scene-scoring failure"
raise NeuralBridgeError(
- f"CUDA reduced-luma scene scoring failed: {detail}. Switch GPU OFF "
- "to use host staging."
+ f"CUDA reduced-luma scene scoring failed: {detail}."
)
return float(score.value), bool(reset.value)
@@ -1379,16 +1396,19 @@ class NeuralBridgeManager:
if self._library is None or self._cuda_driver is None:
raise NeuralBridgeError("Host-to-CUDA video processing requires GPU mode.")
if (
- rgba.dtype != np.uint8
+ rgba.dtype not in (np.uint8, np.uint16)
or rgba.ndim != 3
or rgba.shape[2] != 4
or not rgba.flags.c_contiguous
):
- raise NeuralBridgeError("Host video input must be contiguous RGBA8.")
+ raise NeuralBridgeError("Host video input must be contiguous RGBA8 or RGBA16LE.")
+ high_depth = rgba.dtype == np.uint16
height, width = rgba.shape[:2]
source = FrameDescriptorV1.empty()
source.memory_type = MEMORY_HOST
- source.pixel_format = FORMAT_RGBA8
+ source.pixel_format = FORMAT_RGBA16LE if high_depth else FORMAT_RGBA8
+ if high_depth:
+ source.abi_version = 7
source.width = int(width)
source.height = int(height)
source.planes[0] = int(rgba.ctypes.data)
@@ -1398,18 +1418,23 @@ class NeuralBridgeManager:
source.timestamp = int(timestamp)
surface = self.create_video_surface(width, height, output_format)
- destination = surface.descriptor
+ destination = FrameDescriptorV1.from_buffer_copy(surface.descriptor)
+ if high_depth:
+ destination.abi_version = 7
destination.color_matrix = int(color_matrix)
destination.color_range = int(color_range)
destination.timestamp = int(timestamp)
params = self._render_parameters(settings, reset, mask, cuda_mask)
result = FrameResultV1.empty()
+ if high_depth:
+ params.abi_version = result.abi_version = 7
error = ctypes.create_string_buffer(4096)
started = time.perf_counter()
try:
ok = self._call_with_watchdog(
"feature-18 host-to-CUDA video evaluation",
- lambda: self._library.dlss5nr_process_frame_v6(
+ lambda: (self._library.dlss5nr_process_frame_v7 if high_depth
+ else self._library.dlss5nr_process_frame_v6)(
ctypes.byref(source), ctypes.byref(destination),
ctypes.byref(params), ctypes.byref(result), error, len(error),
),
@@ -1421,8 +1446,7 @@ class NeuralBridgeManager:
if not ok:
detail = _text(error.value) or "unknown host-to-CUDA frame failure"
raise NeuralBridgeError(
- f"CUDA/D3D12 Neural Rendering failed: {detail}. Switch GPU OFF "
- "to use host staging."
+ f"CUDA/D3D12 Neural Rendering failed: {detail}."
)
output = surface.to_av_frame()
except BaseException:
@@ -1444,7 +1468,7 @@ class NeuralBridgeManager:
"upload_bytes": int(result.upload_bytes),
"download_bytes": int(result.download_bytes),
"timestamp": int(result.timestamp),
- "input_format": "rgba8",
+ "input_format": "rgba16le" if high_depth else "rgba8",
"output_format": "p010le" if output_format == FORMAT_P010 else "nv12",
}
return output, details, elapsed
@@ -1462,6 +1486,7 @@ class NeuralBridgeManager:
color_matrix: int = 1,
color_range: int = 0,
rotation: int = 0,
+ chroma_location: int = 1,
) -> tuple[dict[str, Any], float]:
"""Evaluate an NVDEC CUDA frame and download only the final RGBA result."""
with self._lock:
@@ -1479,13 +1504,16 @@ class NeuralBridgeManager:
f"{format_name or 'unknown'}/{sw_format or 'unknown'}."
)
if (
- destination.dtype != np.uint8
+ destination.dtype not in (np.uint8, np.uint16)
or destination.ndim != 3
or destination.shape[2] != 4
or not destination.flags.c_contiguous
):
- raise NeuralBridgeError("CUDA-to-host output must be contiguous RGBA8.")
+ raise NeuralBridgeError("CUDA-to-host output must be contiguous RGBA8 or RGBA16LE.")
+ high_depth = destination.dtype == np.uint16
source = FrameDescriptorV1.empty()
+ if high_depth:
+ source.abi_version = 7
source.memory_type = MEMORY_CUDA
source.pixel_format = source_format
source.width = int(frame.width)
@@ -1497,10 +1525,13 @@ class NeuralBridgeManager:
source.color_matrix = int(color_matrix)
source.color_range = int(color_range)
source.rotation = int(rotation) % 360
+ source.reserved = int(chroma_location)
source.timestamp = int(timestamp)
output = FrameDescriptorV1.empty()
output.memory_type = MEMORY_HOST
- output.pixel_format = FORMAT_RGBA8
+ output.pixel_format = FORMAT_RGBA16LE if high_depth else FORMAT_RGBA8
+ if high_depth:
+ output.abi_version = 7
output.width = int(destination.shape[1])
output.height = int(destination.shape[0])
output.planes[0] = int(destination.ctypes.data)
@@ -1510,11 +1541,14 @@ class NeuralBridgeManager:
output.timestamp = int(timestamp)
params = self._render_parameters(settings, reset, mask, cuda_mask)
result = FrameResultV1.empty()
+ if high_depth:
+ params.abi_version = result.abi_version = 7
error = ctypes.create_string_buffer(4096)
started = time.perf_counter()
ok = self._call_with_watchdog(
"feature-18 CUDA-to-host video evaluation",
- lambda: self._library.dlss5nr_process_frame_v6(
+ lambda: (self._library.dlss5nr_process_frame_v7 if high_depth
+ else self._library.dlss5nr_process_frame_v6)(
ctypes.byref(source), ctypes.byref(output), ctypes.byref(params),
ctypes.byref(result), error, len(error),
),
@@ -1526,8 +1560,7 @@ class NeuralBridgeManager:
if not ok:
detail = _text(error.value) or "unknown CUDA-to-host frame failure"
raise NeuralBridgeError(
- f"CUDA/D3D12 Neural Rendering failed: {detail}. Switch GPU OFF to "
- "use host staging."
+ f"CUDA/D3D12 Neural Rendering failed: {detail}."
)
return {
"ngx_create_result": f"0x{int(result.ngx_create_result) & 0xFFFFFFFF:08X}",
@@ -1539,48 +1572,9 @@ class NeuralBridgeManager:
"download_bytes": int(result.download_bytes),
"timestamp": int(result.timestamp),
"input_format": sw_format,
- "output_format": "rgba8",
+ "output_format": "rgba16le" if high_depth else "rgba8",
}, elapsed
- def process_host(
- self,
- source: np.ndarray,
- destination: np.ndarray,
- settings: dict[str, int | float | bool],
- reset: bool,
- mask: np.ndarray | None = None,
- ) -> float:
- with self._lock:
- self._guard_poison()
- assert self._library is not None
- error = ctypes.create_string_buffer(4096)
- started = time.perf_counter()
- params = self._render_parameters(settings, reset, mask, None)
- ok = self._call_with_watchdog(
- "feature-18 host evaluation",
- lambda: self._library.dlss5nr_process_v6(
- source.ctypes.data_as(ctypes.POINTER(ctypes.c_float)),
- destination.ctypes.data_as(ctypes.POINTER(ctypes.c_float)),
- source.shape[1],
- source.shape[0],
- ctypes.byref(params),
- error,
- len(error),
- ),
- (source, destination, mask, params, error),
- timeout_seconds=min(180.0, BRIDGE_WATCHDOG_SECONDS * params.nr_passes),
- )
- elapsed = time.perf_counter() - started
- if not ok:
- detail = _text(error.value) or "unknown feature-18 failure"
- if _bridge_failure_requires_restart(detail):
- self._poisoned_reason = detail
- raise NeuralBridgePoisonedError(
- f"{detail}. Restart the application before rendering again."
- )
- raise NeuralBridgeError(f"Feature-18 evaluation failed: {detail}")
- return elapsed
-
def process_cuda(
self,
source: np.ndarray,
@@ -1624,8 +1618,7 @@ class NeuralBridgeManager:
f"{detail}. Restart the application before rendering again."
)
raise NeuralBridgeError(
- f"CUDA/D3D12 Neural Rendering failed: {detail}. Switch GPU OFF to "
- "use host staging."
+ f"CUDA/D3D12 Neural Rendering failed: {detail}."
)
download_started = time.perf_counter()
buffers.driver.synchronize()
diff --git a/src/core/paths.py b/src/core/paths.py
index 7b4f6f2..5c0b9f4 100644
--- a/src/core/paths.py
+++ b/src/core/paths.py
@@ -6,8 +6,12 @@ from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
TEMP = ROOT / "temp"
APP_TEMP = TEMP / "app"
+PREVIEW_CACHE = APP_TEMP / "cache"
RUNTIME = ROOT / "bin" / "runtime"
DLSSG_DIR = RUNTIME / "dlssg"
+DLSSSR_DIR = RUNTIME / "dlsssr"
+DLSSSR_BRIDGE = DLSSSR_DIR / "neuroframe_engine_super_resolution.dll"
+DLSSSR_RUNTIME = DLSSSR_DIR / "nvngx_dlss.dll"
# In-process D3D12/NGX feature-18 runtime. The bridge and caller shim are
# self-contained and require no Python tensor framework or external add-on.
DLSSNR_DIR = RUNTIME / "dlssnr"
diff --git a/src/core/render_metadata.py b/src/core/render_metadata.py
index 94a671b..bdedee9 100644
--- a/src/core/render_metadata.py
+++ b/src/core/render_metadata.py
@@ -164,7 +164,7 @@ def build_render_note(options) -> str:
number(native["face_skin_protection"]), number(native["grain_preservation"]),
"On" if getattr(options, "nr_mask", None) else "Off",
number(native["mask_feather"]),
- "On" if native["gpu_mode"] else "Off", scale,
+ "On", scale,
)
return APPLICATION + ":\n" + PREFIX + ", ".join(
label + " - " + value for label, value in zip(_LABELS, values)
diff --git a/src/core/runtime.py b/src/core/runtime.py
index 3e78a25..e0eef03 100644
--- a/src/core/runtime.py
+++ b/src/core/runtime.py
@@ -4,6 +4,7 @@ import json
import contextlib
import math
import mmap
+import os
import re
import subprocess
import threading
@@ -16,6 +17,7 @@ import cv2
import numpy as np
from .gpu_detection import detect_gpus
+from .gpu_memory import GPUVramTracker
from .gpu_selection import resolve_runtime_ai_gpu
from .jobs import Cancelled, JobController
from .neural_bridge import (
@@ -24,7 +26,6 @@ from .neural_bridge import (
BridgeSessionDiagnostics,
CudaFrameBuffers,
CudaMaskBuffer,
- NeuralBridgeError,
FORMAT_NV12,
FORMAT_P010,
)
@@ -91,17 +92,10 @@ def resolve_output_size(width: int, height: int, factor: float) -> tuple[int, in
f"The requested {output_width}×{output_height} output is below the supported "
f"64×64 minimum. Choose Source, 75%, or 50% for this input."
)
- long_edge = max(output_width, output_height)
- short_edge = min(output_width, output_height)
- if long_edge > 7680 or short_edge > 4320:
- raise ValueError(
- f"The requested {output_width}×{output_height} output exceeds the supported "
- f"7680×4320 boundary. The source already exceeds the supported 8K boundary."
- )
return output_width, output_height
-def resolve_native_settings(options: Any, *, gpu_mode: bool | None = None) -> dict[str, int | float | bool]:
+def resolve_native_settings(options: Any) -> dict[str, int | float | bool]:
try:
style = NR_STYLES[options.nr_style]
except KeyError as exc:
@@ -140,21 +134,20 @@ def resolve_native_settings(options: Any, *, gpu_mode: bool | None = None) -> di
if not 0 <= int(mask_feather) <= 128:
raise ValueError("Mask Feather must be between 0 and 128 pixels.")
codec_name = str(getattr(options, "codec", ""))
- if gpu_mode is None:
- # Automatic path selection: an NVENC codec takes the CUDA transport,
- # a CPU codec takes the host-memory path. Options without a codec
- # (images, Live) default to GPU-resident; host pipelines pass False
- # explicitly.
- gpu_mode = True if not hasattr(options, "codec") else "NVENC" in codec_name.upper()
- if not isinstance(gpu_mode, bool):
- raise ValueError("Neural Rendering GPU mode must be a boolean value.")
nr_passes = getattr(options, "nr_passes", 1)
if isinstance(nr_passes, bool) or not isinstance(nr_passes, int):
raise ValueError("NR Passes must be an integer from 1 to 4.")
if not 1 <= nr_passes <= 4:
raise ValueError("NR Passes must be between 1 and 4.")
- prefer_nvof = bool(codec_name and "NVENC" not in codec_name.upper())
+ # NVOF remains available for adapter/driver validation. On the tested
+ # RTX 4060 Ti / 617.14 it was slower and had a higher warped-residual
+ # error than the bundled Lucas-Kanade path, so it is not a default.
+ # Frame-boundary NVENC also retains its native NVOF stall guard.
+ prefer_nvof = bool(
+ codec_name and "NVENC" not in codec_name.upper()
+ and os.environ.get("DLSS5NR_EXPERIMENTAL_NVOF") == "1"
+ )
return {
"profile": 0,
"style": style,
@@ -171,7 +164,7 @@ def resolve_native_settings(options: Any, *, gpu_mode: bool | None = None) -> di
"shimmer_suppression": validated["Shimmer Suppression"],
"prefer_nvof": prefer_nvof,
"mask_feather": int(mask_feather),
- "gpu_mode": gpu_mode,
+ "gpu_mode": True,
}
@@ -239,16 +232,26 @@ def write_failure_report(
)
-def resize_fit(rgba: np.ndarray, width: int, height: int) -> np.ndarray:
+def resize_fit(rgba: np.ndarray, width: int, height: int, *,
+ interpolation: str = "Lanczos4") -> np.ndarray:
source_height, source_width = rgba.shape[:2]
if source_width == width and source_height == height:
- return np.ascontiguousarray(rgba, dtype=np.uint8)
+ return np.ascontiguousarray(rgba)
scale = min(width / source_width, height / source_height)
fit_width = max(1, min(width, int(round(source_width * scale))))
fit_height = max(1, min(height, int(round(source_height * scale))))
- resized = cv2.resize(rgba, (fit_width, fit_height), interpolation=cv2.INTER_LANCZOS4)
- canvas = np.zeros((height, width, 4), dtype=np.uint8)
- canvas[..., 3] = 255
+ methods = {
+ "Lanczos4": cv2.INTER_LANCZOS4,
+ "Area": cv2.INTER_AREA,
+ "Bicubic": cv2.INTER_CUBIC,
+ "Bilinear": cv2.INTER_LINEAR,
+ "Nearest": cv2.INTER_NEAREST,
+ }
+ if interpolation not in methods:
+ raise ValueError(f"Unknown image scaling filter: {interpolation!r}.")
+ resized = cv2.resize(rgba, (fit_width, fit_height), interpolation=methods[interpolation])
+ canvas = np.zeros((height, width, 4), dtype=rgba.dtype)
+ canvas[..., 3] = np.iinfo(rgba.dtype).max
x = (width - fit_width) // 2
y = (height - fit_height) // 2
canvas[y : y + fit_height, x : x + fit_width] = resized
@@ -335,13 +338,12 @@ class DLSSFrameSession:
"optical_flow_seconds": 0.0,
"stabilization_seconds": 0.0,
}
- self.gpu_mode = bool(native_settings.get("gpu_mode", True))
+ if native_settings.get("gpu_mode", True) is not True:
+ raise ValueError("Neural Rendering requires CUDA/D3D12 GPU processing.")
self.cuda_video = bool(cuda_video)
- if self.cuda_video and not self.gpu_mode:
- raise ValueError("The CUDA video boundary requires Neural Rendering GPU mode.")
self.diagnostics = BridgeSessionDiagnostics(
- gpu_mode=self.gpu_mode,
- memory_path="cuda_d3d12_shared" if self.gpu_mode else "host_staging",
+ gpu_mode=True,
+ memory_path="cuda_d3d12_shared" if self.cuda_video else "host_cuda_d3d12_shared",
)
self._input_float = (
None if self.cuda_video else np.empty(
@@ -390,7 +392,7 @@ class DLSSFrameSession:
self._cuda_mask: CudaMaskBuffer | None = None
self._logs: list[str] = []
self._temporal_status_cache: dict[str, Any] = {}
- status = BRIDGE_MANAGER.initialize(gpu, require_cuda=self.gpu_mode)
+ status = BRIDGE_MANAGER.initialize(gpu)
self.bridge_status = {
**status,
"memory_path": self.diagnostics.memory_path,
@@ -427,12 +429,14 @@ class DLSSFrameSession:
}
BRIDGE_MANAGER.open_session()
self._manager_open = True
+ self._vram_tracker = GPUVramTracker(int(gpu.get("index", 0)))
+ self._vram_status: dict[str, object] | None = None
try:
- if self.gpu_mode and not self.cuda_video:
+ if not self.cuda_video:
self._cuda_buffers = BRIDGE_MANAGER.create_cuda_buffers(
self.output_width, self.output_height
)
- if self.gpu_mode and self._mask_host is not None:
+ if self._mask_host is not None:
self._cuda_mask = BRIDGE_MANAGER.create_cuda_mask(self._mask_host)
self.bridge_status["composition"]["cuda_mask_uploads"] = 1
self.bridge_status["composition"]["cuda_mask_upload_bytes"] = int(
@@ -446,6 +450,7 @@ class DLSSFrameSession:
)
)
except Exception:
+ self._vram_tracker.close()
if self._cuda_mask is not None:
with contextlib.suppress(Exception):
self._cuda_mask.close()
@@ -526,6 +531,7 @@ class DLSSFrameSession:
return {
**self.bridge_status,
**self.diagnostics.as_dict(),
+ "gpu_memory": self._vram_status or self._vram_tracker.snapshot(),
"temporal_stabilization": temporal,
}
@@ -536,7 +542,7 @@ class DLSSFrameSession:
selected, self.output_width, self.output_height, int(feather)
)
replacement = None
- if self.gpu_mode and prepared is not None:
+ if prepared is not None:
replacement = BRIDGE_MANAGER.create_cuda_mask(prepared)
previous = self._cuda_mask
composition = self.bridge_status.get("composition", {})
@@ -662,19 +668,21 @@ class DLSSFrameSession:
self._next_frame_index = int(index)
if index != self._next_frame_index:
raise ValueError("Neural Rendering frames must have consecutive uint32 indices.")
- if rgba.dtype != np.uint8 or rgba.shape != (
+ if rgba.dtype not in (np.uint8, np.uint16) or rgba.shape != (
self.output_height,
self.output_width,
4,
):
- raise ValueError("Neural Rendering input must be contiguous RGBA8 at final size.")
+ raise ValueError("Neural Rendering input must be RGBA8 or RGBA16 at final size.")
rgba = np.ascontiguousarray(rgba)
+ self.diagnostics.working_format = "rgba16le" if rgba.dtype == np.uint16 else "rgba8"
+ self.diagnostics.output_format = self.diagnostics.working_format
if output_buffer is None:
output = np.empty_like(rgba)
else:
output = output_buffer
if (
- output.dtype != np.uint8
+ output.dtype != rgba.dtype
or output.shape != rgba.shape
or not output.flags.c_contiguous
):
@@ -682,42 +690,33 @@ class DLSSFrameSession:
started = time.perf_counter()
assert self._input_float is not None and self._output_float is not None
- np.multiply(rgba[..., :3], 1.0 / 255.0, out=self._input_float, casting="unsafe")
+ max_sample = float(np.iinfo(rgba.dtype).max)
+ np.multiply(rgba[..., :3], 1.0 / max_sample, out=self._input_float, casting="unsafe")
self.process_timings["input_conversion_seconds"] += time.perf_counter() - started
- if self.gpu_mode:
- assert self._cuda_buffers is not None
- try:
- upload, evaluate, download = BRIDGE_MANAGER.process_cuda(
- self._input_float,
- self._output_float,
- self._cuda_buffers,
- self._host_bridge_settings,
- bool(reset),
- self._mask_host,
- self._cuda_mask,
- )
- except NeuralBridgeError:
- # GPU ON is a strict policy. Never retry through host staging.
- raise
- self.process_timings["input_transfer_seconds"] += upload
- self.process_timings["evaluation_wait_seconds"] += evaluate
- self.process_timings["output_transfer_seconds"] += download
- else:
- evaluate = BRIDGE_MANAGER.process_host(
- self._input_float, self._output_float, self._host_bridge_settings, bool(reset),
- self._mask_host,
- )
- self.process_timings["evaluation_wait_seconds"] += evaluate
+ assert self._cuda_buffers is not None
+ upload, evaluate, download = BRIDGE_MANAGER.process_cuda(
+ self._input_float,
+ self._output_float,
+ self._cuda_buffers,
+ self._host_bridge_settings,
+ bool(reset),
+ self._mask_host,
+ self._cuda_mask,
+ )
+ self.process_timings["input_transfer_seconds"] += upload
+ self.process_timings["evaluation_wait_seconds"] += evaluate
+ self.process_timings["output_transfer_seconds"] += download
self._stabilize_host_composition(reset=bool(reset))
started = time.perf_counter()
np.multiply(
np.clip(self._output_float, 0.0, 1.0),
- 255.0,
+ max_sample,
out=self._output_float,
)
+ np.rint(self._output_float, out=self._output_float)
np.copyto(output[..., :3], self._output_float, casting="unsafe")
output[..., 3] = rgba[..., 3]
self.process_timings["output_conversion_seconds"] += time.perf_counter() - started
@@ -750,8 +749,6 @@ class DLSSFrameSession:
return output, int(pts)
def score_cuda_frame(self, frame: Any, *, color_matrix: int, color_range: int) -> tuple[float, bool]:
- if not self.gpu_mode:
- raise RuntimeError("CUDA scene scoring is not enabled for this session.")
if self.controller.cancel.is_set():
raise Cancelled("Render stopped by user.")
return BRIDGE_MANAGER.score_cuda_video_frame(
@@ -769,11 +766,12 @@ class DLSSFrameSession:
color_matrix: int,
color_range: int,
rotation: int = 0,
+ chroma_location: int = 1,
output_buffer: np.ndarray | None = None,
) -> tuple[np.ndarray, int]:
if self.controller.cancel.is_set():
raise Cancelled("Render stopped by user.")
- if self.closed or not self.gpu_mode:
+ if self.closed:
raise RuntimeError("The CUDA Neural Rendering session is unavailable.")
if self._next_frame_index is None:
self._next_frame_index = int(index)
@@ -783,7 +781,7 @@ class DLSSFrameSession:
if output is None:
output = np.empty((self.output_height, self.output_width, 4), dtype=np.uint8)
if (
- output.dtype != np.uint8
+ output.dtype not in (np.uint8, np.uint16)
or output.shape != (self.output_height, self.output_width, 4)
or not output.flags.c_contiguous
):
@@ -799,9 +797,12 @@ class DLSSFrameSession:
color_matrix=color_matrix,
color_range=color_range,
rotation=rotation,
+ chroma_location=chroma_location,
)
self.process_timings["evaluation_wait_seconds"] += elapsed
self.diagnostics.decode_backend = "nvdec"
+ self.diagnostics.working_format = "float32-rgb"
+ self.diagnostics.output_format = result["output_format"]
self.diagnostics.pixel_format = result["input_format"]
self.diagnostics.upload_bytes += int(result["upload_bytes"])
self.diagnostics.download_bytes += int(result["download_bytes"])
@@ -819,7 +820,7 @@ class DLSSFrameSession:
"ngx_create_result": result["ngx_create_result"],
"ngx_evaluate_result": result["ngx_evaluate_result"],
"memory_path": self.diagnostics.memory_path,
- "input_format": result["input_format"], "output_format": "rgba8",
+ "input_format": result["input_format"], "output_format": result["output_format"],
"upload_bytes": result["upload_bytes"],
"download_bytes": result["download_bytes"],
}, sort_keys=True, separators=(",", ":")))
@@ -841,6 +842,7 @@ class DLSSFrameSession:
color_matrix: int,
color_range: int,
rotation: int = 0,
+ chroma_location: int = 1,
output_p010: bool = False,
) -> tuple[Any, int]:
"""Process a hardware or software decoded frame into CUDA NV12/P010."""
@@ -848,7 +850,7 @@ class DLSSFrameSession:
raise Cancelled("Render stopped by user.")
if self.closed:
raise RuntimeError("The Neural Rendering bridge session is closed.")
- if not self.cuda_video or not self.gpu_mode:
+ if not self.cuda_video:
raise RuntimeError("The CUDA video frame boundary is not enabled.")
if self._next_frame_index is None:
self._next_frame_index = int(index)
@@ -871,12 +873,16 @@ class DLSSFrameSession:
color_matrix=color_matrix,
color_range=color_range,
rotation=rotation,
+ chroma_location=chroma_location,
)
self.diagnostics.decode_backend = "nvdec"
+ self.diagnostics.working_format = "float32-rgb"
elif rgba is not None:
- rgba = np.ascontiguousarray(rgba, dtype=np.uint8)
+ rgba = np.ascontiguousarray(rgba)
+ if rgba.dtype not in (np.uint8, np.uint16):
+ raise ValueError("Software video input must be RGBA8 or RGBA16.")
if rgba.shape != (self.output_height, self.output_width, 4):
- raise ValueError("Software video input must be RGBA8 at final neural dimensions.")
+ raise ValueError("Software video input must be RGBA at final neural dimensions.")
output, result, elapsed = BRIDGE_MANAGER.process_host_to_cuda_video_frame(
rgba,
output_format=output_format,
@@ -891,6 +897,7 @@ class DLSSFrameSession:
duration=duration,
)
self.diagnostics.decode_backend = "software"
+ self.diagnostics.working_format = "rgba16le" if rgba.dtype == np.uint16 else "rgba8"
else:
raise ValueError("A CUDA frame or host RGBA frame is required.")
output.pts = int(pts)
@@ -900,6 +907,7 @@ class DLSSFrameSession:
self.process_timings["evaluation_wait_seconds"] += elapsed
self.diagnostics.encode_backend = "nvenc"
self.diagnostics.pixel_format = result["output_format"]
+ self.diagnostics.output_format = result["output_format"]
self.diagnostics.upload_bytes += int(result["upload_bytes"])
self.diagnostics.download_bytes += int(result["download_bytes"])
self.diagnostics.ngx_create_result = result["ngx_create_result"]
@@ -950,6 +958,8 @@ class DLSSFrameSession:
def _close_resources(self) -> None:
if self.closed:
return
+ self._vram_tracker.close()
+ self._vram_status = self._vram_tracker.snapshot()
if self._cuda_buffers is not None:
self._cuda_buffers.close()
self._cuda_buffers = None
diff --git a/src/desktop/AMD-FidelityFX-CAS-LICENSE.txt b/src/desktop/AMD-FidelityFX-CAS-LICENSE.txt
new file mode 100644
index 0000000..3712e34
--- /dev/null
+++ b/src/desktop/AMD-FidelityFX-CAS-LICENSE.txt
@@ -0,0 +1,21 @@
+This file is part of the FidelityFX SDK.
+
+Copyright (C) 2024 Advanced Micro Devices, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files(the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions :
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/src/desktop/NVIDIA-NIS-LICENSE.txt b/src/desktop/NVIDIA-NIS-LICENSE.txt
new file mode 100644
index 0000000..fda6832
--- /dev/null
+++ b/src/desktop/NVIDIA-NIS-LICENSE.txt
@@ -0,0 +1,20 @@
+The MIT License(MIT)
+
+Copyright(c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files(the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions :
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/desktop/auto_color.py b/src/desktop/auto_color.py
new file mode 100644
index 0000000..ebb1ba7
--- /dev/null
+++ b/src/desktop/auto_color.py
@@ -0,0 +1,231 @@
+"""Content-aware starting point for editable LUT color adjustments.
+
+Auto analyzes pixels at the source's native precision. Only the statistics
+use a bounded sample; the chosen settings are applied to full-resolution
+previews, exports, and saved cubes by the existing grading pipeline.
+"""
+
+from __future__ import annotations
+
+import math
+import subprocess
+from dataclasses import replace
+from pathlib import Path
+
+import numpy as np
+
+from ..core.jobs import Cancelled
+from ..core.paths import FFMPEG
+from ..neural_rendering.image.decoder import decode_image
+from ..settings.models import DEFAULT_SETTINGS, LUT_ADJUSTMENT_RANGES, UISettings
+from .coloring import grade_lut_rgb, load_cube_lut, sample_cube_lut
+
+
+_LUMA = np.asarray((0.2126, 0.7152, 0.0722), dtype=np.float32)
+
+
+def _check_cancel(controller) -> None:
+ if controller is not None and controller.cancel.is_set():
+ raise Cancelled("Automatic color adjustment cancelled.")
+
+
+def _clamp(value: float, low: float, high: float) -> float:
+ return max(low, min(high, value))
+
+
+def _analysis_pixels(rgba: np.ndarray, limit: int) -> np.ndarray:
+ """Sample a spatial grid while discarding transparent pixels."""
+ height, width = rgba.shape[:2]
+ stride = max(1, math.ceil(max(height, width) / 512))
+ sampled = rgba[::stride, ::stride].reshape(-1, rgba.shape[-1])
+ if len(sampled) > limit:
+ sampled = sampled[np.linspace(0, len(sampled) - 1, limit, dtype=np.intp)]
+ maximum = float(np.iinfo(rgba.dtype).max)
+ if sampled.shape[-1] == 4:
+ sampled = sampled[sampled[:, 3] > maximum * 0.05]
+ return np.ascontiguousarray(sampled[:, :3].astype(np.float32) / maximum)
+
+
+def _video_sample(source: Path, seconds: float, size: tuple[int, int], controller) -> np.ndarray | None:
+ width, height = size
+ scale = min(1.0, 512.0 / max(width, height))
+ sample_width = max(1, round(width * scale))
+ sample_height = max(1, round(height * scale))
+ command = [str(FFMPEG), "-hide_banner", "-loglevel", "error",
+ "-ss", f"{max(0.0, seconds):.6f}", "-i", str(source),
+ "-frames:v", "1", "-an", "-vf",
+ f"scale={sample_width}:{sample_height}:flags=area",
+ "-f", "rawvideo", "-pix_fmt", "rgb48le", "pipe:1"]
+ _check_cancel(controller)
+ result = subprocess.run(
+ command, capture_output=True, timeout=30, check=False,
+ creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0),
+ )
+ _check_cancel(controller)
+ if result.returncode != 0 or len(result.stdout) != sample_width * sample_height * 6:
+ return None
+ rgb = np.frombuffer(result.stdout, dtype="<u2").reshape(sample_height, sample_width, 3)
+ return _analysis_pixels(rgb, 32_000)
+
+
+def _source_pixels(source: Path, mode: str, duration_seconds: float,
+ video_size: tuple[int, int] | None, controller, progress) -> np.ndarray:
+ if mode == "Image":
+ _check_cancel(controller)
+ pixels = _analysis_pixels(decode_image(source).rgba, 220_000)
+ _check_cancel(controller)
+ elif mode == "Video":
+ if video_size is None or min(video_size) < 1:
+ raise ValueError("Video dimensions are unavailable; reload the input and try Auto again.")
+ if duration_seconds > 0:
+ stamps = [duration_seconds * fraction for fraction in
+ (0.05, 0.2, 0.35, 0.5, 0.65, 0.8, 0.95)]
+ else:
+ stamps = [0.0, 1.0, 3.0, 6.0]
+ frames = []
+ fallback_frames = []
+ for index, stamp in enumerate(stamps):
+ sample = _video_sample(source, stamp, video_size, controller)
+ if sample is not None and len(sample):
+ fallback_frames.append(sample)
+ luma = sample @ _LUMA
+ # Ignore nearly black/white transition frames when there are
+ # other usable frames in the sequence.
+ if 0.025 < float(np.median(luma)) < 0.975:
+ frames.append(sample)
+ if progress is not None:
+ progress((index + 1) / (len(stamps) + 1), "Analyzing video color")
+ if not frames:
+ frames = fallback_frames
+ if not frames:
+ raise ValueError("Could not find a usable video frame for Auto color adjustment.")
+ pixels = np.concatenate(frames, axis=0)
+ else:
+ raise ValueError("Auto color adjustment requires an image or video input.")
+ if len(pixels) < 32:
+ raise ValueError("The input has too few visible pixels for Auto color adjustment.")
+ return pixels
+
+
+def _linear(value: float) -> float:
+ return value / 12.92 if value <= 0.04045 else ((value + 0.055) / 1.055) ** 2.4
+
+
+def recommend_lut_adjustments(identity: np.ndarray, sampled: np.ndarray,
+ *, allow_white_balance: bool = True,
+ hdr: bool = False) -> dict[str, int | float]:
+ """Choose a restrained grade from robust tone and neutral-color statistics.
+
+ A universal "best" look cannot be inferred from pixels alone, so Auto
+ favors highlight protection, modest contrast, and minimal color shifts.
+ All returned controls remain editable by the user.
+ """
+ if identity.shape != sampled.shape or identity.ndim != 2 or identity.shape[1] != 3:
+ raise ValueError("Auto color analysis requires matching RGB samples.")
+ valid = np.all(np.isfinite(identity) & np.isfinite(sampled), axis=1)
+ identity = np.clip(identity[valid], 0.0, 1.0)
+ sampled = np.clip(sampled[valid], 0.0, 1.0)
+ if len(identity) < 32:
+ raise ValueError("The input has too few valid colors for Auto adjustment.")
+
+ luma = sampled @ _LUMA
+ p02, p10, p50, p90, p95, p98, p99 = np.percentile(
+ luma, (2, 10, 50, 90, 95, 98, 99))
+ if p98 - p02 < 0.06:
+ # A blank/faded frame gives no reliable evidence of the intended look.
+ return {key: getattr(DEFAULT_SETTINGS, key) for key in LUT_ADJUSTMENT_RANGES}
+ exposure = 0.55 * math.log2(_linear(0.82) / max(_linear(float(p95)), 0.003))
+ exposure = _clamp(exposure, -0.7, 1.2)
+ if p99 > 0.75:
+ highlight_limit = 0.8 * math.log2(_linear(0.98) / max(_linear(float(p99)), 0.003))
+ exposure = min(exposure, highlight_limit)
+ if p50 < 0.22 and p99 > 0.7:
+ exposure = min(exposure, 0.25) # Preserve low-key scenes with bright accents.
+ if p50 > 0.72 and p02 > 0.2:
+ exposure = max(exposure, -0.25) # Preserve a deliberate high-key scene.
+ if hdr:
+ exposure = _clamp(exposure, -0.25, 0.25)
+ exposure = round(round(_clamp(exposure, -3.0, 3.0) / 0.05) * 0.05, 2)
+
+ base_settings = replace(DEFAULT_SETTINGS, lut_exposure=exposure)
+ exposed = grade_lut_rgb(sampled, sampled, base_settings)
+ exposed_luma = exposed @ _LUMA
+ e02, e10, e50, e90, e95, e98, e99 = np.percentile(
+ exposed_luma, (2, 10, 50, 90, 95, 98, 99))
+ contrast = round(_clamp((0.64 / max(float(e90 - e10), 0.15) - 1.0) * 20.0, -12, 20))
+ shadows = round(_clamp((0.13 - float(e10)) * 115, 0, 18))
+ highlights = -round(_clamp((float(e99) - 0.92) * 140, 0, 25))
+ whites = round(_clamp((0.86 - float(e98)) * 60, 0, 12))
+ blacks = -round(_clamp((float(e02) - 0.05) * 130, 0, 18))
+ midtones = round(_clamp((0.30 - float(e50)) * 45, 0, 10)) if e99 > 0.7 else 0
+
+ temperature = tint = 0
+ if allow_white_balance:
+ chroma = np.ptp(sampled, axis=1)
+ neutral = (chroma < 0.055) & (luma > 0.18) & (luma < 0.88)
+ if np.count_nonzero(neutral) >= max(100, int(len(sampled) * 0.02)):
+ r, g, b = np.median(sampled[neutral], axis=0)
+ level = max(float((r + g + b) / 3), 0.1)
+ temperature = round(_clamp(float(b - r) / level * 125, -16, 16))
+ tint = round(_clamp(float(g - (r + b) * 0.5) / level * 220, -12, 12))
+
+ chroma = np.ptp(sampled, axis=1)
+ medium = chroma[(luma > 0.12) & (luma < 0.9)]
+ mean_chroma = float(np.mean(medium)) if len(medium) else 0.0
+ vibrance = (round(_clamp((0.2 - mean_chroma) * 75, 0, 16))
+ if mean_chroma > 0.035 else 0)
+ saturation = -round(_clamp((mean_chroma - 0.4) * 30, 0, 8))
+
+ values: dict[str, int | float] = {key: getattr(DEFAULT_SETTINGS, key)
+ for key in LUT_ADJUSTMENT_RANGES}
+ values.update(lut_mix=100, lut_exposure=exposure, lut_contrast=contrast,
+ lut_highlights=highlights, lut_shadows=shadows,
+ lut_whites=whites, lut_blacks=blacks, lut_midtones=midtones,
+ lut_temperature=temperature, lut_tint=tint,
+ lut_vibrance=vibrance, lut_saturation=saturation)
+
+ # Reject a newly clipped look. Existing clipped highlights cannot be
+ # recovered, but Auto must not substantially add to them.
+ baseline_white = float(np.mean(np.any(sampled >= 0.997, axis=1)))
+ baseline_black = float(np.mean(np.all(sampled <= 0.003, axis=1)))
+ for _ in range(8):
+ graded = grade_lut_rgb(identity, sampled, replace(DEFAULT_SETTINGS, **values))
+ white = float(np.mean(np.any(graded >= 0.997, axis=1)))
+ black = float(np.mean(np.all(graded <= 0.003, axis=1)))
+ if white <= baseline_white + 0.012 and black <= baseline_black + 0.012:
+ break
+ if white > baseline_white + 0.012:
+ if values["lut_whites"] > 0:
+ values["lut_whites"] = max(0, int(values["lut_whites"]) - 3)
+ elif values["lut_exposure"] > 0:
+ values["lut_exposure"] = round(max(0.0, float(values["lut_exposure"]) - 0.05), 2)
+ else:
+ values["lut_highlights"] = max(-35, int(values["lut_highlights"]) - 4)
+ if black > baseline_black + 0.012:
+ values["lut_blacks"] = min(0, int(values["lut_blacks"]) + 3)
+ values["lut_contrast"] = max(-12, int(values["lut_contrast"]) - 2)
+ return values
+
+
+def analyze_color_source(source: str | Path, settings: UISettings, mode: str, *,
+ duration_seconds: float = 0.0,
+ video_size: tuple[int, int] | None = None,
+ hdr: bool = False, controller=None, progress=None) -> dict[str, int | float]:
+ """Analyze the selected source and return editable Color Adjustment values."""
+ path = Path(source).resolve()
+ pixels = _source_pixels(path, mode, duration_seconds, video_size, controller, progress)
+ _check_cancel(controller)
+ if settings.lut_path:
+ lut = load_cube_lut(settings.lut_path)
+ sampled = np.empty_like(pixels)
+ for offset in range(0, len(pixels), 65_536):
+ _check_cancel(controller)
+ end = min(len(pixels), offset + 65_536)
+ sampled[offset:end] = sample_cube_lut(pixels[offset:end], lut)
+ else:
+ sampled = pixels
+ values = recommend_lut_adjustments(pixels, sampled,
+ allow_white_balance=not (settings.lut_path or hdr), hdr=hdr)
+ if progress is not None:
+ progress(1.0, "Auto color adjustment ready")
+ return values
diff --git a/src/desktop/bridge.py b/src/desktop/bridge.py
index 977d4ae..aeec991 100644
--- a/src/desktop/bridge.py
+++ b/src/desktop/bridge.py
@@ -20,17 +20,20 @@ from typing import Any
from PySide6.QtCore import QObject, QThreadPool, QTimer, QUrl, Signal, Slot, Property, QSettings, qVersion, QBuffer, QIODevice
from PySide6.QtGui import QGuiApplication, QImage, QPixmap
-from ..core.paths import CONFIG_PATH, OUTPUTS, LOGS, FFMPEG, FFPROBE, MPV, APP_TEMP
+from ..core.paths import ROOT, CONFIG_PATH, OUTPUTS, LOGS, FFMPEG, FFPROBE, MPV, APP_TEMP
from ..core.disk_paths import prepare_output_dir, supported_file as _is_supported_media_file
from ..core.cache_cleanup import cleanup_old_caches
from ..core import app_log
from ..core.runtime import prepare_runtime, NR_STYLES, UPSCALING_MODES, resolve_upscaling_mode, resolve_output_size
+from ..core.dlss_modes import DLSS_MODES, DLSS_PRESETS, UPSCALE_ENGINES, dlss_output_size
from ..core.ffmpeg import CODEC_CHOICES, ENCODING_QUALITIES, FIXED_QUALITY_CODECS, container_for_codec, hdr_mode_supported, probe_video
from ..core.naming import RENAME_MODES, validate_rename
from ..core.nr_composition import inspect_nr_mask, mask_status
from ..settings.models import (
CONTAINER_CHOICES, DEFAULT_SETTINGS, PREVIEW_ENCODING_CHOICES, UPSCALE_MODE_CHOICES,
- UPSCALE_PREVIEW_LENGTH_CHOICES, UISettings,
+ UPSCALE_PREVIEW_LENGTH_CHOICES, UISettings, IMAGE_STAGE_ORDER, VIDEO_STAGE_ORDER,
+ IMAGE_SCALING_FILTERS, VIDEO_SCALING_FILTERS, IMAGE_16BIT_FORMATS,
+ LUT_ADJUSTMENT_RANGES, LUT_RESOLUTIONS, SHARPENING_METHODS,
automatic_mask_choice, coerce_hdr_mode, live_effect_options, parse_automatic_mask, _validate,
)
from ..settings.storage import SETTINGS_STATE, load_settings, save_settings
@@ -38,7 +41,13 @@ from ..settings.presets import export_settings_preset, export_settings_preset_to
from .models import BatchListModel
from .image_provider import PreviewImageProvider
+from .coloring import load_cube_lut, save_cube_lut
+from .auto_color import analyze_color_source
+from .color_preview import (FastPreviewUnavailable, MAX_PREVIEW_PIXELS,
+ render_color_still_preview)
from .workers import JobWorker
+from .workflow import (enabled_stages, estimate_pipeline, preflight_source,
+ render_pipeline_batch, render_pipeline_preview)
from .state import (
PreviewState, IDLE, SCANNING_INPUTS, LOADING_METADATA, PREVIEW_PREPARING,
PREVIEW_RUNNING, PREVIEW_CANCELLING, BATCH_PREPARING, BATCH_RUNNING,
@@ -155,6 +164,9 @@ class AppBridge(QObject):
# selected item when Realtime Preview is enabled. Rename/output-only
# settings are intentionally excluded so they do not waste GPU work.
AUTO_PREVIEW_FIELDS = {
+ "image_stage_order", "video_stage_order", "image_enabled_stages", "video_enabled_stages",
+ "denoise_strength", "denoise_deblock", "denoise_temporal", "cas_sharpness", "sharpening_method",
+ "coloring_mode", "color_match_source", "color_match_reference", "lut_path",
"ai_gpu_uuid", "video_gpu_uuid",
"nr_style", "nr_intensity", "nr_passes",
"local_tone_strength", "local_structure_strength",
@@ -162,7 +174,10 @@ class AppBridge(QObject):
"nr_color_strength", "tone_preservation",
"face_skin_protection", "grain_preservation",
"shimmer_suppression", "mask_feather", "nr_mask",
- "upscaling_factor",
+ "upscaling_factor", "image_scaling_filter", "video_scaling_filter",
+ "nr_scale_method", "nr_dlss_mode", "nr_dlss_preset",
+ "upscale_image_engine", "upscale_image_dlss_mode", "upscale_image_dlss_preset",
+ "upscale_engine", "upscale_dlss_mode", "upscale_dlss_preset",
"preview_encoding",
"upscale_image_vsr_quality", "upscale_image_size_mode",
"upscale_image_scale_factor", "upscale_image_width",
@@ -178,8 +193,33 @@ class AppBridge(QObject):
"frame_interpolation_codec", "frame_interpolation_quality",
"frame_interpolation_hdr_mode",
"codec", "quality", "hdr_mode",
+ } | set(LUT_ADJUSTMENT_RANGES) | {"lut_resolution"}
+ PROCESSING_PREVIEW_FIELDS = {
+ "nr-image": {
+ "denoise_strength", "denoise_deblock", "cas_sharpness", "sharpening_method",
+ "image_scaling_filter", "upscaling_factor",
+ "coloring_mode", "color_match_source", "color_match_reference", "lut_path",
+ "upscale_image_dlss_mode", "upscale_image_dlss_preset",
+ "upscale_image_vsr_quality", "upscale_image_size_mode",
+ "upscale_image_scale_factor", "upscale_image_width",
+ "upscale_image_height", "upscale_image_aspect_lock",
+ } | set(LUT_ADJUSTMENT_RANGES) | {"lut_resolution"},
+ "nr-video": {
+ "denoise_strength", "denoise_deblock", "denoise_temporal", "cas_sharpness", "sharpening_method",
+ "video_scaling_filter", "upscaling_factor",
+ "lut_path",
+ "upscale_dlss_mode", "upscale_dlss_preset",
+ "upscale_vsr_enabled", "upscale_vsr_quality", "upscale_size_mode",
+ "upscale_scale_factor", "upscale_width", "upscale_height",
+ "upscale_aspect_lock", "upscale_hdr_enabled", "upscale_hdr_contrast",
+ "upscale_hdr_saturation", "upscale_hdr_middle_gray",
+ "upscale_hdr_peak_luminance", "upscale_hdr_precision",
+ } | set(LUT_ADJUSTMENT_RANGES) | {"lut_resolution"},
+ "upscale-image": {"upscale_image_engine", "upscale_image_dlss_mode", "upscale_image_dlss_preset"},
+ "upscale-video": {"upscale_engine", "upscale_dlss_mode", "upscale_dlss_preset"},
}
UPSCALE_RANGE_FIELDS = {
+ "upscale_engine", "upscale_dlss_mode", "upscale_dlss_preset",
"ai_gpu_uuid", "video_gpu_uuid", "preview_encoding",
"upscale_vsr_enabled", "upscale_vsr_quality",
"upscale_size_mode", "upscale_scale_factor",
@@ -189,6 +229,23 @@ class AppBridge(QObject):
"upscale_hdr_peak_luminance", "upscale_hdr_precision",
"upscale_codec", "upscale_quality",
}
+ # Neural Rendering settings that invalidate pre-rendered timeline spans.
+ # The manual clip length itself is excluded (older spans remain valid
+ # footage for their range), mirroring FI/upscale.
+ NR_RANGE_FIELDS = {
+ "video_stage_order", "video_enabled_stages",
+ "denoise_strength", "denoise_deblock", "denoise_temporal", "cas_sharpness", "sharpening_method",
+ "nr_scale_method", "nr_dlss_mode", "nr_dlss_preset",
+ "ai_gpu_uuid", "video_gpu_uuid", "preview_encoding",
+ "nr_style", "nr_intensity", "nr_passes",
+ "local_tone_strength", "local_structure_strength",
+ "skin_structure_strength", "automatic_mask",
+ "nr_color_strength", "tone_preservation",
+ "face_skin_protection", "grain_preservation",
+ "shimmer_suppression", "mask_feather", "nr_mask",
+ "lut_path",
+ "upscaling_factor", "video_scaling_filter", "codec", "quality", "hdr_mode",
+ } | set(LUT_ADJUSTMENT_RANGES) | {"lut_resolution"}
# UI State Signals
activeTabChanged = Signal()
@@ -215,6 +272,9 @@ class AppBridge(QObject):
sourceSizeChanged = Signal()
outputSizeChanged = Signal()
batchExportRequested = Signal(str)
+ exportPrefsChanged = Signal()
+ workflowStagesChanged = Signal()
+ estimateChanged = Signal()
# Settings Signals
settingsUpdated = Signal()
@@ -225,15 +285,21 @@ class AppBridge(QObject):
isLiveStartingChanged = Signal()
liveTelemetryChanged = Signal()
autoPreviewChanged = Signal()
+ lutSaveChanged = Signal()
+ lutAutoChanged = Signal()
def __init__(self, image_provider: PreviewImageProvider, parent: Any = None) -> None:
super().__init__(parent)
self._image_provider = image_provider
self._thread_pool = QThreadPool.globalInstance()
self._active_worker: JobWorker | None = None
+ self._active_preview_fast_color = False
self._live_worker: JobWorker | None = None
self._scan_worker: JobWorker | None = None
self._metadata_worker: JobWorker | None = None
+ self._lut_save_worker: JobWorker | None = None
+ self._lut_auto_worker: JobWorker | None = None
+ self._lut_save_status = ""
self._operation_state = IDLE
self._operation_id = 0
self._shutting_down = False
@@ -346,6 +412,12 @@ class AppBridge(QObject):
self._window_x = int(self._ui_settings.value("window/x", -1))
self._window_y = int(self._ui_settings.value("window/y", -1))
self._window_maximized = str(self._ui_settings.value("window/maximized", "false")).lower() in {"1", "true", "yes"}
+ # Export dialog path mode + custom folder: desktop prefs (QSettings),
+ # deliberately separate from render presets so machine-specific
+ # folder paths never leak into shared preset files.
+ _export_mode = str(self._ui_settings.value("export/destinationMode", "output"))
+ self._export_destination_mode = _export_mode if _export_mode in {"input", "output", "folder"} else "output"
+ self._export_folder = str(self._ui_settings.value("export/folder", "") or "")
self._auto_preview_timer = QTimer(self)
self._auto_preview_timer.setSingleShot(True)
@@ -407,6 +479,7 @@ class AppBridge(QObject):
self.outputInfoTextChanged.emit()
self.sourceSizeChanged.emit()
self.outputSizeChanged.emit()
+ self.estimateChanged.emit()
def _set_operation(self, state: str, message: str | None = None) -> int:
self._operation_state = state
@@ -425,6 +498,7 @@ class AppBridge(QObject):
self._operation_state = LIVE_RUNNING if self._is_live_running else IDLE
self._is_processing = False
self._active_worker = None
+ self._active_preview_fast_color = False
if message is not None:
self._status_message = message
self.statusMessageChanged.emit()
@@ -453,10 +527,18 @@ class AppBridge(QObject):
except (TypeError, ValueError):
return 3.0
+ def _nr_preview_length_seconds(self) -> float:
+ """Selected Neural Rendering preview clip length in seconds (3/5/10/20/30)."""
+ selected = self._settings.nr_preview_length
+ try:
+ return float(selected) if selected in PREVIEW_LENGTH_CHOICES else 3.0
+ except (TypeError, ValueError):
+ return 3.0
+
def _add_rendered_range(self, context_key: str, start_seconds: float, media_path: str,
length_seconds: float) -> None:
"""Record a rendered video preview span for the green timeline overlay."""
- if context_key not in {"fi-video", "upscale-video"}:
+ if context_key not in {"fi-video", "upscale-video", "nr-video"}:
return
ctx = self._contexts.get(context_key)
if ctx is None:
@@ -517,7 +599,9 @@ class AppBridge(QObject):
@activeTab.setter
def activeTab(self, tab: str) -> None:
- if tab not in {"neural-rendering", "upscale", "frame-interpolation", "live", "settings", "help"}:
+ if tab in {"upscale", "frame-interpolation"}:
+ tab = "neural-rendering"
+ if tab not in {"neural-rendering", "live", "settings", "help"}:
return
if self._active_tab != tab:
self._active_tab = tab
@@ -544,9 +628,285 @@ class AppBridge(QObject):
if self._nr_mode != mode:
self._nr_mode = mode
self.nrModeChanged.emit()
+ self.workflowStagesChanged.emit()
self._emit_context()
self._schedule_auto_preview(180)
+ @Property(list, notify=workflowStagesChanged)
+ def workflowStages(self) -> list[dict[str, object]]:
+ order = self._settings.image_stage_order if self._nr_mode == "Image" else self._settings.video_stage_order
+ enabled = self._settings.image_enabled_stages if self._nr_mode == "Image" else self._settings.video_enabled_stages
+ return [{"id": stage, "enabled": stage in enabled} for stage in order]
+
+ @Property(int, notify=settingsUpdated)
+ def denoiseStrength(self) -> int:
+ return self._settings.denoise_strength
+
+ @denoiseStrength.setter
+ def denoiseStrength(self, value: int) -> None:
+ self._save_setting(denoise_strength=int(value))
+
+ @Property(bool, notify=settingsUpdated)
+ def denoiseDeblock(self) -> bool:
+ return self._settings.denoise_deblock
+
+ @denoiseDeblock.setter
+ def denoiseDeblock(self, value: bool) -> None:
+ self._save_setting(denoise_deblock=bool(value))
+
+ @Property(int, notify=settingsUpdated)
+ def denoiseTemporal(self) -> int:
+ return self._settings.denoise_temporal
+
+ @denoiseTemporal.setter
+ def denoiseTemporal(self, value: int) -> None:
+ self._save_setting(denoise_temporal=int(value))
+
+ @Property(list, constant=True)
+ def sharpeningMethodChoices(self) -> list[str]:
+ return list(SHARPENING_METHODS)
+
+ @Property(str, notify=settingsUpdated)
+ def sharpeningMethod(self) -> str:
+ return self._settings.sharpening_method
+
+ @sharpeningMethod.setter
+ def sharpeningMethod(self, value: str) -> None:
+ self._save_setting(sharpening_method=value)
+
+ @Property(int, notify=settingsUpdated)
+ def casSharpness(self) -> int:
+ return self._settings.cas_sharpness
+
+ @casSharpness.setter
+ def casSharpness(self, value: int) -> None:
+ self._save_setting(cas_sharpness=int(value))
+
+ @Property(list, constant=True)
+ def coloringModeChoices(self) -> list[dict[str, str]]:
+ return [{"label": "Match Colors", "value": "Color Match"},
+ {"label": "Apply LUT", "value": "LUT"}]
+
+ @Property(str, notify=settingsUpdated)
+ def coloringMode(self) -> str:
+ return self._settings.coloring_mode
+
+ @coloringMode.setter
+ def coloringMode(self, value: str) -> None:
+ self._save_setting(coloring_mode=value)
+
+ @Property(list, constant=True)
+ def colorMatchSourceChoices(self) -> list[dict[str, str]]:
+ return [{"label": "Current Image", "value": "Input Image"},
+ {"label": "Selected Reference Image", "value": "Selected Image"}]
+
+ @Property(str, notify=settingsUpdated)
+ def colorMatchSource(self) -> str:
+ return self._settings.color_match_source
+
+ @colorMatchSource.setter
+ def colorMatchSource(self, value: str) -> None:
+ self._save_setting(color_match_source=value)
+
+ @Property(str, notify=settingsUpdated)
+ def colorMatchReference(self) -> str:
+ return self._settings.color_match_reference
+
+ @Slot(str)
+ def setColorMatchReference(self, file_url_or_path: str) -> None:
+ path = self._clean_path(file_url_or_path)
+ if path and (Path(path).suffix.lower() not in IMAGE_SUFFIXES or not Path(path).is_file()):
+ self._status_message = "Choose an existing reference image for Match Colors."
+ self.statusMessageChanged.emit()
+ self.settingsUpdated.emit()
+ return
+ self._save_setting(color_match_reference=path)
+
+ @Property(str, notify=settingsUpdated)
+ def lutFile(self) -> str:
+ return self._settings.lut_path
+
+ @Slot(str)
+ def setLutFile(self, file_url_or_path: str) -> None:
+ path = self._clean_path(file_url_or_path)
+ try:
+ if path:
+ load_cube_lut(path)
+ except ValueError as exc:
+ self._status_message = str(exc)
+ self.statusMessageChanged.emit()
+ self.settingsUpdated.emit()
+ return
+ self._save_setting(lut_path=path)
+
+ @Property(list, constant=True)
+ def lutResolutionChoices(self) -> list[dict[str, object]]:
+ return [{"label": f"{size}³", "value": size} for size in LUT_RESOLUTIONS]
+
+ @Property(int, notify=settingsUpdated)
+ def lutResolution(self) -> int:
+ return self._settings.lut_resolution
+
+ @lutResolution.setter
+ def lutResolution(self, value: int) -> None:
+ self._save_setting(lut_resolution=int(value))
+
+ @Property("QVariantMap", notify=settingsUpdated)
+ def lutAdjustmentValues(self) -> dict[str, float | int]:
+ return {key: getattr(self._settings, key) for key in LUT_ADJUSTMENT_RANGES}
+
+ @Slot(str, float)
+ def setLutAdjustment(self, name: str, value: float) -> None:
+ if name not in LUT_ADJUSTMENT_RANGES or not math.isfinite(value):
+ return
+ normalized = round(value, 2) if name == "lut_exposure" else int(round(value))
+ self._save_setting(**{name: normalized})
+
+ @Slot()
+ def resetLutAdjustments(self) -> None:
+ values = {key: getattr(DEFAULT_SETTINGS, key) for key in LUT_ADJUSTMENT_RANGES}
+ values["lut_resolution"] = DEFAULT_SETTINGS.lut_resolution
+ self._save_setting(**values)
+
+ @Property(bool, notify=lutAutoChanged)
+ def lutAutoBusy(self) -> bool:
+ return self._lut_auto_worker is not None
+
+ def _finish_lut_auto(self, worker: JobWorker, message: str) -> None:
+ if self._lut_auto_worker is not worker:
+ return
+ self._lut_auto_worker = None
+ self.lutAutoChanged.emit()
+ if self._shutting_down:
+ return
+ self._status_message = message
+ self.statusMessageChanged.emit()
+ self._log(message)
+
+ @Slot()
+ def autoAdjustLut(self) -> None:
+ if self._lut_auto_worker is not None or self._shutting_down:
+ return
+ if self._active_tab != "neural-rendering" or self._operation_state != IDLE:
+ return
+ context_key = self._context_key()
+ mode = "Image" if context_key == "nr-image" else "Video"
+ if mode == "Image" and self._settings.coloring_mode != "LUT":
+ return
+ source = self._queue_for_context(context_key).selected_path()
+ if not source or not Path(source).is_file():
+ self._status_message = "Select an image or video before using Auto color."
+ self.statusMessageChanged.emit()
+ return
+
+ snapshot = self._settings
+ context = self._contexts[context_key]
+ source_path = os.path.normcase(os.path.abspath(source))
+ generation = context.generation
+ worker = JobWorker(
+ analyze_color_source, source, snapshot, mode,
+ duration_seconds=context.duration_seconds,
+ video_size=(context.source_width, context.source_height) if mode == "Video" else None,
+ hdr=context.source_hdr,
+ )
+ self._lut_auto_worker = worker
+ self.lutAutoChanged.emit()
+ self._status_message = f"Analyzing {mode.lower()} color…"
+ self.statusMessageChanged.emit()
+
+ def finished(values: dict[str, int | float]) -> None:
+ if self._lut_auto_worker is not worker:
+ return
+ self._lut_auto_worker = None
+ self.lutAutoChanged.emit()
+ if self._shutting_down:
+ return
+ current_source = self._queue_for_context(context_key).selected_path() or ""
+ current_source = os.path.normcase(os.path.abspath(current_source)) if current_source else ""
+ controls_unchanged = (self._settings.lut_path == snapshot.lut_path
+ and all(getattr(self._settings, key) == getattr(snapshot, key)
+ for key in LUT_ADJUSTMENT_RANGES))
+ if (self._context_key() != context_key or self._active_tab != "neural-rendering"
+ or self._contexts[context_key].generation != generation
+ or current_source != source_path or not controls_unchanged):
+ self._status_message = "Auto color skipped because the input or color controls changed."
+ self.statusMessageChanged.emit()
+ return
+ if not self._save_setting(**values):
+ return
+ self._status_message = "Auto color adjustments applied. You can fine-tune every slider."
+ self.statusMessageChanged.emit()
+ self._log(self._status_message)
+ if self.canPreview:
+ if self._auto_preview_enabled:
+ self._schedule_auto_preview(90)
+ else:
+ self.renderPreview()
+
+ worker.signals.finished.connect(finished)
+ worker.signals.failed.connect(
+ lambda error: self._finish_lut_auto(worker, f"Auto color failed: {error}"))
+ worker.signals.cancelled.connect(
+ lambda: self._finish_lut_auto(worker, "Auto color cancelled."))
+ self._thread_pool.start(worker)
+
+ @Property(bool, notify=lutSaveChanged)
+ def lutSaveBusy(self) -> bool:
+ return self._lut_save_worker is not None
+
+ @Property(str, notify=lutSaveChanged)
+ def lutSaveStatus(self) -> str:
+ return self._lut_save_status
+
+ def _finish_lut_save(self, message: str) -> None:
+ self._lut_save_worker = None
+ self._lut_save_status = message
+ self.lutSaveChanged.emit()
+ self._status_message = message
+ self.statusMessageChanged.emit()
+ self._log(message)
+
+ @Slot(str)
+ def saveLut(self, file_url_or_path: str) -> None:
+ if self._lut_save_worker is not None:
+ return
+ target = self._clean_path(file_url_or_path)
+ if not target:
+ return
+ snapshot = self._settings
+ worker = JobWorker(save_cube_lut, target, snapshot.lut_path or None, snapshot)
+ self._lut_save_worker = worker
+ self._lut_save_status = f"Saving {snapshot.lut_resolution}³ LUT…"
+ self.lutSaveChanged.emit()
+ worker.signals.finished.connect(lambda path: self._finish_lut_save(f"Saved LUT to {path}"))
+ worker.signals.failed.connect(lambda error: self._finish_lut_save(f"LUT export failed: {error}"))
+ worker.signals.cancelled.connect(lambda: self._finish_lut_save("LUT export cancelled."))
+ self._thread_pool.start(worker)
+
+ @Slot(str, bool)
+ def setWorkflowStageEnabled(self, stage: str, value: bool) -> None:
+ allowed = IMAGE_STAGE_ORDER if self._nr_mode == "Image" else VIDEO_STAGE_ORDER
+ if stage not in allowed:
+ return
+ field = "image_enabled_stages" if self._nr_mode == "Image" else "video_enabled_stages"
+ active = set(getattr(self._settings, field))
+ if value:
+ active.add(stage)
+ else:
+ active.discard(stage)
+ order = self._settings.image_stage_order if self._nr_mode == "Image" else self._settings.video_stage_order
+ self._save_setting(**{field: tuple(item for item in order if item in active)})
+
+ @Slot(str, int)
+ def moveWorkflowStage(self, stage: str, target_index: int) -> None:
+ field = "image_stage_order" if self._nr_mode == "Image" else "video_stage_order"
+ order = list(getattr(self._settings, field))
+ if stage not in order or not 0 <= target_index < len(order):
+ return
+ order.remove(stage)
+ order.insert(target_index, stage)
+ self._save_setting(**{field: tuple(order)})
+
@Property(str, notify=upscaleModeChanged)
def upscaleMode(self) -> str:
return self._upscale_mode
@@ -572,6 +932,15 @@ class AppBridge(QObject):
if str(value) in UPSCALE_PREVIEW_LENGTH_CHOICES:
self._save_setting(upscale_preview_length=str(value))
+ @Property(str, notify=settingsUpdated)
+ def nrPreviewLength(self) -> str:
+ return self._settings.nr_preview_length
+
+ @nrPreviewLength.setter
+ def nrPreviewLength(self, value: str) -> None:
+ if str(value) in PREVIEW_LENGTH_CHOICES:
+ self._save_setting(nr_preview_length=str(value))
+
@Property(bool, notify=isProcessingChanged)
def isProcessing(self) -> bool:
return self._is_processing
@@ -737,6 +1106,10 @@ class AppBridge(QObject):
def operationState(self) -> str:
return self._operation_state
+ @Property(bool, notify=operationStateChanged)
+ def fastColorPreviewActive(self) -> bool:
+ return self._active_preview_fast_color
+
@Property(bool, notify=operationStateChanged)
def canModifyQueue(self) -> bool:
return self._operation_state == IDLE and not self._shutting_down
@@ -840,6 +1213,34 @@ class AppBridge(QObject):
self._focus_preview = value
self.layoutChanged.emit()
+ @Property(str, notify=exportPrefsChanged)
+ def exportDestinationMode(self) -> str:
+ return self._export_destination_mode
+
+ @exportDestinationMode.setter
+ def exportDestinationMode(self, value: str) -> None:
+ value = str(value)
+ if value not in {"input", "output", "folder"} or value == self._export_destination_mode:
+ return
+ self._export_destination_mode = value
+ self._ui_settings.setValue("export/destinationMode", value)
+ self._ui_settings.sync()
+ self.exportPrefsChanged.emit()
+
+ @Property(str, notify=exportPrefsChanged)
+ def exportFolder(self) -> str:
+ return self._export_folder
+
+ @exportFolder.setter
+ def exportFolder(self, value: str) -> None:
+ cleaned = self._clean_path(value) if value else ""
+ if cleaned == self._export_folder:
+ return
+ self._export_folder = cleaned
+ self._ui_settings.setValue("export/folder", cleaned)
+ self._ui_settings.sync()
+ self.exportPrefsChanged.emit()
+
@Property(bool, notify=autoPreviewChanged)
def autoPreviewEnabled(self) -> bool:
return self._auto_preview_enabled
@@ -877,7 +1278,10 @@ class AppBridge(QObject):
snapshot = tuple(
getattr(self._settings, field.name, None)
for field in _dataclass_fields(self._settings)
- if not (key == "upscale-video" and field.name == "upscale_preview_length")
+ if not (
+ (key == "upscale-video" and field.name == "upscale_preview_length")
+ or (key == "nr-video" and field.name == "nr_preview_length")
+ )
)
except Exception:
snapshot = ()
@@ -885,7 +1289,21 @@ class AppBridge(QObject):
except Exception:
return ()
- def _schedule_auto_preview(self, delay_ms: int = 360) -> None:
+ def _can_fast_color_preview(self, context_key: str, *, clip_seconds: float | None = None) -> bool:
+ if clip_seconds is not None or context_key not in {"nr-image", "nr-video"}:
+ return False
+ context = self._contexts[context_key]
+ pixels = context.source_width * context.source_height
+ if not 0 < pixels <= MAX_PREVIEW_PIXELS:
+ return False
+ mode = "Image" if context_key == "nr-image" else "Video"
+ if mode == "Image" and self._settings.coloring_mode != "LUT":
+ return False
+ if mode == "Video" and context.source_hdr:
+ return False
+ return enabled_stages(self._settings, mode) == ("coloring",)
+
+ def _schedule_auto_preview(self, delay_ms: int = 360, *, throttle: bool = False) -> None:
"""Debounce an automatic preview for the currently selected media.
Slider drags can emit dozens of values per second; a single GPU preview
@@ -897,7 +1315,10 @@ class AppBridge(QObject):
disabled for fi-video even when the global switch is on, so settings
tweaks and tab switches never trigger automatic renders there.
"""
- if self._context_key() == "fi-video":
+ if self._context_key() == "fi-video" or (
+ self._context_key() == "nr-video" and
+ "frame_generation" in enabled_stages(self._settings, "Video")
+ ):
self._auto_preview_pending = False
try:
self._auto_preview_timer.stop()
@@ -938,17 +1359,20 @@ class AppBridge(QObject):
self._auto_preview_pending = True
if self._operation_state in {PREVIEW_PREPARING, PREVIEW_RUNNING}:
- self._invalidate_preview_generation()
- worker = self._active_worker
- if worker is not None:
- try:
- worker.controller.stop()
- except Exception:
- pass
- self._operation_state = PREVIEW_CANCELLING
- self._status_message = "Updating realtime preview…"
- self.operationStateChanged.emit()
- self.statusMessageChanged.emit()
+ if not (throttle and self._active_preview_fast_color):
+ self._invalidate_preview_generation()
+ worker = self._active_worker
+ if worker is not None:
+ try:
+ worker.controller.stop()
+ except Exception:
+ pass
+ self._operation_state = PREVIEW_CANCELLING
+ self._status_message = "Updating realtime preview…"
+ self.operationStateChanged.emit()
+ self.statusMessageChanged.emit()
+ if throttle and self._auto_preview_timer.isActive():
+ return
self._auto_preview_timer.start(max(80, int(delay_ms)))
def _run_auto_preview(self) -> None:
@@ -1095,6 +1519,31 @@ class AppBridge(QObject):
def nrScaleChoices(self) -> list[dict[str, float]]:
return [{"label": mode["label"], "value": factor} for factor, mode in UPSCALING_MODES.items()]
+ @Property(list, constant=True)
+ def imageScalingFilterChoices(self) -> list[str]:
+ return list(IMAGE_SCALING_FILTERS)
+
+ @Property(list, constant=True)
+ def videoScalingFilterChoices(self) -> list[str]:
+ return list(VIDEO_SCALING_FILTERS)
+
+ @Property(list, constant=True)
+ def dlssModeChoices(self) -> list[dict[str, str]]:
+ labels = {
+ "DLAA": "DLAA 1.0×", "Quality": "Quality 1.5×",
+ "Balanced": "Balanced ~1.72×", "Performance": "Performance 2.0×",
+ "Ultra Performance": "Ultra Performance 3.0×",
+ }
+ return [{"label": labels[mode], "value": mode} for mode in DLSS_MODES]
+
+ @Property(list, constant=True)
+ def dlssPresetChoices(self) -> list[str]:
+ return list(DLSS_PRESETS)
+
+ @Property(list, constant=True)
+ def upscaleEngineChoices(self) -> list[str]:
+ return list(UPSCALE_ENGINES)
+
@Property(list, constant=True)
def imageFormatChoices(self) -> list[str]:
return ["PNG", "JPEG", "WebP", "AVIF", "TIFF"]
@@ -1135,6 +1584,10 @@ class AppBridge(QObject):
def upscalePreviewLengthChoices(self) -> list[dict[str, str]]:
return [{"label": f"{value}s", "value": value} for value in PREVIEW_LENGTH_CHOICES]
+ @Property(list, constant=True)
+ def nrPreviewLengthChoices(self) -> list[dict[str, str]]:
+ return [{"label": f"{value}s", "value": value} for value in PREVIEW_LENGTH_CHOICES]
+
@Property(list, constant=True)
def previewEncodingChoices(self) -> list[str]:
return list(PREVIEW_ENCODING_CHOICES)
@@ -1303,7 +1756,7 @@ class AppBridge(QObject):
changed["upscale_hdr_enabled"] = False
candidate = replace(self._settings, **changed)
- if not (candidate.upscale_vsr_enabled or candidate.upscale_hdr_enabled):
+ if candidate.upscale_engine != "DLSS" and not (candidate.upscale_vsr_enabled or candidate.upscale_hdr_enabled):
self._status_message = "Upscale Video requires VSR or RTX Video HDR to remain enabled."
self.statusMessageChanged.emit()
self.settingsUpdated.emit()
@@ -1319,12 +1772,52 @@ class AppBridge(QObject):
self._settings = candidate
SETTINGS_STATE.current = self._settings
+ keep_nr_video_output = (
+ self._context_key() == "nr-video"
+ and self._auto_preview_enabled
+ and self._runtime_state == "Ready"
+ and self._contexts["nr-video"].has_output
+ and "frame_generation" not in enabled_stages(self._settings, "Video")
+ )
+ if keep_nr_video_output and set(changed) & (
+ self.PROCESSING_PREVIEW_FIELDS["nr-video"] | {"video_stage_order", "video_enabled_stages"}
+ ):
+ self._contexts["nr-video"].last_auto_fingerprint = ()
+ if any(key in changed for key in ("image_stage_order", "image_enabled_stages")):
+ self._clear_output_preview("nr-image")
+ if (not keep_nr_video_output
+ and any(key in changed for key in ("video_stage_order", "video_enabled_stages"))):
+ self._clear_output_preview("nr-video")
+ if (self._context_key() == "nr-video"
+ and "frame_generation" in enabled_stages(self._settings, "Video")
+ and any(key in self.AUTO_PREVIEW_FIELDS for key in changed)):
+ self._clear_output_preview("nr-video")
+ if self._operation_state in {PREVIEW_PREPARING, PREVIEW_RUNNING}:
+ self._invalidate_preview_generation()
+ if self._active_worker is not None:
+ self._active_worker.controller.stop()
+ coloring_changes = set(LUT_ADJUSTMENT_RANGES) | {"lut_path", "lut_resolution"}
+ keep_coloring_output = (self._auto_preview_enabled
+ and set(changed).issubset(coloring_changes)
+ and self._can_fast_color_preview(self._context_key()))
+ for context_key, fields in self.PROCESSING_PREVIEW_FIELDS.items():
+ if any(field in changed for field in fields):
+ if ((keep_coloring_output and context_key == self._context_key())
+ or (keep_nr_video_output and context_key == "nr-video")):
+ # Keep the last frame painted until its replacement is
+ # ready; the fingerprint still marks it as stale.
+ self._contexts[context_key].last_auto_fingerprint = ()
+ else:
+ self._clear_output_preview(context_key)
if self._is_live_running and any(field in self.LIVE_EFFECT_FIELDS for field in changed):
self._live_effects_dirty = True
if self._is_live_running and any(field in self.LIVE_RESTART_FIELDS for field in changed):
self._status_message = "Setting saved; this change applies the next time Live is started."
self.statusMessageChanged.emit()
self.settingsUpdated.emit()
+ self.estimateChanged.emit()
+ if any(key in changed for key in ("image_stage_order", "video_stage_order", "image_enabled_stages", "video_enabled_stages")):
+ self.workflowStagesChanged.emit()
if "ai_gpu_uuid" in changed:
self.runtimeStateChanged.emit()
self.operationStateChanged.emit()
@@ -1335,8 +1828,11 @@ class AppBridge(QObject):
self._clear_rendered_ranges("fi-video")
if any(field in self.UPSCALE_RANGE_FIELDS for field in changed):
self._clear_rendered_ranges("upscale-video")
+ if any(field in self.NR_RANGE_FIELDS | self.UPSCALE_RANGE_FIELDS | self.FI_RANGE_FIELDS for field in changed):
+ self._clear_rendered_ranges("nr-video")
if any(field in self.AUTO_PREVIEW_FIELDS for field in changed):
- self._schedule_auto_preview()
+ delay = 90 if keep_coloring_output else 360
+ self._schedule_auto_preview(delay, throttle=keep_coloring_output)
return True
def _flush_settings(self) -> None:
@@ -1373,6 +1869,46 @@ class AppBridge(QObject):
except ValueError:
pass
+ @Property(str, notify=settingsUpdated)
+ def imageScalingFilter(self) -> str:
+ return self._settings.image_scaling_filter
+
+ @imageScalingFilter.setter
+ def imageScalingFilter(self, val: str) -> None:
+ self._save_setting(image_scaling_filter=val)
+
+ @Property(str, notify=settingsUpdated)
+ def videoScalingFilter(self) -> str:
+ return self._settings.video_scaling_filter
+
+ @videoScalingFilter.setter
+ def videoScalingFilter(self, val: str) -> None:
+ self._save_setting(video_scaling_filter=val)
+
+ @Property(str, notify=settingsUpdated)
+ def nrScaleMethod(self) -> str:
+ return self._settings.nr_scale_method
+
+ @nrScaleMethod.setter
+ def nrScaleMethod(self, val: str) -> None:
+ self._save_setting(nr_scale_method=val)
+
+ @Property(str, notify=settingsUpdated)
+ def nrDlssMode(self) -> str:
+ return self._settings.nr_dlss_mode
+
+ @nrDlssMode.setter
+ def nrDlssMode(self, val: str) -> None:
+ self._save_setting(nr_dlss_mode=val)
+
+ @Property(str, notify=settingsUpdated)
+ def nrDlssPreset(self) -> str:
+ return self._settings.nr_dlss_preset
+
+ @nrDlssPreset.setter
+ def nrDlssPreset(self, val: str) -> None:
+ self._save_setting(nr_dlss_preset=val)
+
@Property(float, notify=settingsUpdated)
def nrIntensity(self) -> float:
return self._settings.nr_intensity
@@ -1609,7 +2145,10 @@ class AppBridge(QObject):
@imageFormat.setter
def imageFormat(self, val: str) -> None:
- self._save_setting(image_format=val)
+ values = {"image_format": val}
+ if val not in IMAGE_16BIT_FORMATS and self._settings.image_bit_depth == 16:
+ values["image_bit_depth"] = 8
+ self._save_setting(**values)
@Property(int, notify=settingsUpdated)
def imageQuality(self) -> int:
@@ -1619,6 +2158,14 @@ class AppBridge(QObject):
def imageQuality(self, val: int) -> None:
self._save_setting(image_quality=int(val))
+ @Property(int, notify=settingsUpdated)
+ def imageBitDepth(self) -> int:
+ return self._settings.image_bit_depth
+
+ @imageBitDepth.setter
+ def imageBitDepth(self, val: int) -> None:
+ self._save_setting(image_bit_depth=int(val))
+
@Property(str, notify=settingsUpdated)
def imageRenameMode(self) -> str:
return self._settings.image_rename_mode
@@ -1682,6 +2229,30 @@ class AppBridge(QObject):
self._save_setting(video_custom_suffix=val)
# Upscale Image & Video
+ @Property(str, notify=settingsUpdated)
+ def upscaleImageEngine(self) -> str:
+ return self._settings.upscale_image_engine
+
+ @upscaleImageEngine.setter
+ def upscaleImageEngine(self, val: str) -> None:
+ self._save_setting(upscale_image_engine=val)
+
+ @Property(str, notify=settingsUpdated)
+ def upscaleImageDlssMode(self) -> str:
+ return self._settings.upscale_image_dlss_mode
+
+ @upscaleImageDlssMode.setter
+ def upscaleImageDlssMode(self, val: str) -> None:
+ self._save_setting(upscale_image_dlss_mode=val)
+
+ @Property(str, notify=settingsUpdated)
+ def upscaleImageDlssPreset(self) -> str:
+ return self._settings.upscale_image_dlss_preset
+
+ @upscaleImageDlssPreset.setter
+ def upscaleImageDlssPreset(self, val: str) -> None:
+ self._save_setting(upscale_image_dlss_preset=val)
+
@Property(int, notify=settingsUpdated)
def upscaleImageVsrQuality(self) -> int:
return self._settings.upscale_image_vsr_quality
@@ -1756,15 +2327,31 @@ class AppBridge(QObject):
def upscaleImageQuality(self, val: int) -> None:
self._save_setting(upscale_image_quality=int(val))
- @Property(bool, notify=settingsUpdated)
- def upscaleImagePreserveMetadata(self) -> bool:
- return self._settings.upscale_image_preserve_metadata
+ # Upscale Video
+ @Property(str, notify=settingsUpdated)
+ def upscaleEngine(self) -> str:
+ return self._settings.upscale_engine
- @upscaleImagePreserveMetadata.setter
- def upscaleImagePreserveMetadata(self, val: bool) -> None:
- self._save_setting(upscale_image_preserve_metadata=bool(val))
+ @upscaleEngine.setter
+ def upscaleEngine(self, val: str) -> None:
+ self._save_setting(upscale_engine=val)
+
+ @Property(str, notify=settingsUpdated)
+ def upscaleDlssMode(self) -> str:
+ return self._settings.upscale_dlss_mode
+
+ @upscaleDlssMode.setter
+ def upscaleDlssMode(self, val: str) -> None:
+ self._save_setting(upscale_dlss_mode=val)
+
+ @Property(str, notify=settingsUpdated)
+ def upscaleDlssPreset(self) -> str:
+ return self._settings.upscale_dlss_preset
+
+ @upscaleDlssPreset.setter
+ def upscaleDlssPreset(self, val: str) -> None:
+ self._save_setting(upscale_dlss_preset=val)
- # Upscale Video
@Property(bool, notify=settingsUpdated)
def upscaleVsrEnabled(self) -> bool:
return self._settings.upscale_vsr_enabled
@@ -2049,6 +2636,12 @@ class AppBridge(QObject):
def _active_render_configuration_valid(self) -> bool:
try:
_validate(self._settings)
+ if self._active_tab == "neural-rendering":
+ context = self._context()
+ if context.source_width > 0 and context.source_height > 0:
+ estimate_pipeline(context.source_width, context.source_height,
+ context.source_fps, context.source_hdr,
+ self._settings, self._nr_mode)
if self._active_tab == "upscale" and self._upscale_mode == "Video":
video_upscale_options_from_settings(self._settings).validate(for_render=True)
elif self._active_tab == "upscale" and self._upscale_mode == "Image":
@@ -2057,10 +2650,16 @@ class AppBridge(QObject):
except Exception:
return False
- @Property(str, notify=settingsUpdated)
+ @Property(str, notify=estimateChanged)
def renderValidationMessage(self) -> str:
try:
_validate(self._settings)
+ if self._active_tab == "neural-rendering":
+ context = self._context()
+ if context.source_width > 0 and context.source_height > 0:
+ estimate_pipeline(context.source_width, context.source_height,
+ context.source_fps, context.source_hdr,
+ self._settings, self._nr_mode)
if self._active_tab == "upscale" and self._upscale_mode == "Video":
video_upscale_options_from_settings(self._settings).validate(for_render=True)
elif self._active_tab == "upscale" and self._upscale_mode == "Image":
@@ -2069,7 +2668,7 @@ class AppBridge(QObject):
except Exception as exc:
return str(exc)
- @Property(str, notify=settingsUpdated)
+ @Property(str, notify=estimateChanged)
def outputEstimate(self) -> str:
context = self._context()
width, height = context.source_width, context.source_height
@@ -2077,8 +2676,10 @@ class AppBridge(QObject):
return ""
try:
if self._active_tab == "neural-rendering":
- ow, oh = resolve_output_size(width, height, self._settings.upscaling_factor)
- return f"{width}×{height} → {ow}×{oh}"
+ result = estimate_pipeline(width, height, context.source_fps, context.source_hdr,
+ self._settings, self._nr_mode)
+ fps = f" | {result.fps:g} FPS" if self._nr_mode == "Video" and result.fps else ""
+ return f"{width}×{height} → {result.width}×{result.height}{fps}"
if self._active_tab == "upscale" and self._upscale_mode == "Image":
ow, oh = image_upscale_output_size(width, height, image_upscale_options_from_settings(self._settings))
return f"{width}×{height} → {ow}×{oh}"
@@ -2124,6 +2725,7 @@ class AppBridge(QObject):
SETTINGS_STATE.current = self._settings
self._clear_rendered_ranges("fi-video")
self._clear_rendered_ranges("upscale-video")
+ self._clear_rendered_ranges("nr-video")
if self._upscale_mode != DEFAULT_SETTINGS.upscale_mode:
self._upscale_mode = DEFAULT_SETTINGS.upscale_mode
self.upscaleModeChanged.emit()
@@ -2132,6 +2734,7 @@ class AppBridge(QObject):
self._live_effects_dirty = True
self._flush_settings()
self.settingsUpdated.emit()
+ self.workflowStagesChanged.emit()
self.runtimeStateChanged.emit()
self._preset_status = "All settings were reset to factory defaults."
self.presetStatusChanged.emit()
@@ -2145,17 +2748,33 @@ class AppBridge(QObject):
"live": "live_",
}
TAB_RESET_NEURAL_FIELDS = (
+ "image_stage_order", "video_stage_order",
+ "image_enabled_stages", "video_enabled_stages",
+ "denoise_strength", "denoise_deblock", "denoise_temporal", "cas_sharpness", "sharpening_method",
+ "coloring_mode", "color_match_source", "color_match_reference", "lut_path",
+ "lut_resolution", *LUT_ADJUSTMENT_RANGES,
"nr_style", "nr_intensity", "nr_passes",
"local_tone_strength", "local_structure_strength",
"skin_structure_strength", "automatic_mask",
"nr_color_strength", "tone_preservation",
"face_skin_protection", "grain_preservation",
"shimmer_suppression", "mask_feather", "nr_mask",
- "upscaling_factor",
+ "upscaling_factor", "image_scaling_filter", "video_scaling_filter",
+ "nr_scale_method", "nr_dlss_mode", "nr_dlss_preset",
"codec", "quality", "hdr_mode",
- "image_format", "image_quality",
+ "image_format", "image_quality", "image_bit_depth",
"image_rename_mode", "image_custom_suffix",
"video_rename_mode", "video_custom_suffix",
+ "nr_preview_length",
+ "upscale_image_engine", "upscale_image_dlss_mode", "upscale_image_dlss_preset",
+ "upscale_image_vsr_quality", "upscale_image_size_mode", "upscale_image_scale_factor",
+ "upscale_image_width", "upscale_image_height", "upscale_image_aspect_lock",
+ "upscale_engine", "upscale_dlss_mode", "upscale_dlss_preset",
+ "upscale_vsr_enabled", "upscale_vsr_quality", "upscale_size_mode", "upscale_scale_factor",
+ "upscale_width", "upscale_height", "upscale_aspect_lock", "upscale_hdr_enabled",
+ "upscale_hdr_contrast", "upscale_hdr_saturation", "upscale_hdr_middle_gray",
+ "upscale_hdr_peak_luminance", "upscale_hdr_precision",
+ "frame_interpolation_target_fps", "frame_interpolation_engine",
)
TAB_RESET_LABELS = {
"neural-rendering": "Neural Rendering",
@@ -2241,6 +2860,9 @@ class AppBridge(QObject):
imported = _validate(imported)
self._settings = imported
SETTINGS_STATE.current = self._settings
+ self._clear_output_preview("nr-image")
+ self._clear_output_preview("nr-video")
+ self._clear_rendered_ranges("nr-video")
if self._upscale_mode != imported.upscale_mode:
self._upscale_mode = imported.upscale_mode
self.upscaleModeChanged.emit()
@@ -2249,6 +2871,7 @@ class AppBridge(QObject):
self._live_effects_dirty = True
self._flush_settings()
self.settingsUpdated.emit()
+ self.workflowStagesChanged.emit()
self.runtimeStateChanged.emit()
self._preset_status = f"Imported preset '{name}' successfully."
self.presetStatusChanged.emit()
@@ -2660,6 +3283,21 @@ class AppBridge(QObject):
self._image_provider.clear(f"input-{key}")
self._image_provider.clear(f"output-{key}")
self._image_provider.clear(f"poster-{key}")
+ self.splitPosition = 0.5
+ if key == self._context_key():
+ self._emit_context()
+
+ def _clear_output_preview(self, key: str) -> None:
+ """Drop an output made with a different scale method, mode, or preset."""
+ context = self._contexts[key]
+ if not context.has_output:
+ return
+ context.output_url = ""
+ context.output_info = ""
+ context.output_width = context.output_height = 0
+ context.output_is_video = False
+ context.last_auto_fingerprint = ()
+ self._image_provider.clear(f"output-{key}")
if key == self._context_key():
self._emit_context()
@@ -2695,6 +3333,12 @@ class AppBridge(QObject):
context = self._contexts[context_key]
context.selected_path = str(path)
context.selected_row = row
+ context.source_width = 0
+ context.source_height = 0
+ context.source_aspect_ratio = None
+ context.source_fps = 0.0
+ context.source_hdr = False
+ context.duration_seconds = 0.0
context.output_url = ""
context.output_is_video = False
context.output_info = ""
@@ -2705,6 +3349,9 @@ class AppBridge(QObject):
context.last_playhead_seconds = 0.0
context.rendered_ranges = []
context.poster_url = ""
+ # New source: recenter the Split comparison divider so it never
+ # inherits a dragged offset from the previous image.
+ self.splitPosition = 0.5
self._preview_generation += 1
generation = self._preview_generation
context.generation = generation
@@ -2778,6 +3425,7 @@ class AppBridge(QObject):
ctx.source_height = height
ctx.source_aspect_ratio = (width / height) if width and height else None
ctx.source_fps = float(result.get("fps") or 0.0)
+ ctx.source_hdr = bool((result.get("meta") or {}).get("hdr"))
ctx.duration_seconds = float(result.get("duration") or 0.0)
dimensions = f"{width}×{height}" if width and height else ""
if result.get("kind") == "image":
@@ -2913,6 +3561,17 @@ class AppBridge(QObject):
if not self._save_setting(**{mode_field: rename_mode, suffix_field: custom_suffix}):
return self._batch_export_error(self._status_message)
+ # Remember this run's Export Path choices so the next dialog open
+ # (including after restart) restores them.
+ self._export_destination_mode = destination_mode
+ if destination_mode == "folder":
+ self._export_folder = folder
+ self._ui_settings.setValue("export/destinationMode", destination_mode)
+ if destination_mode == "folder":
+ self._ui_settings.setValue("export/folder", folder)
+ self._ui_settings.sync()
+ self.exportPrefsChanged.emit()
+
self._flush_settings()
queue.reset_all_states()
self._overall_progress = 0.0
@@ -2923,9 +3582,11 @@ class AppBridge(QObject):
try:
if context_key == "nr-image":
- worker = self._nr_image_batch_worker(paths, settings, output_dir, same_as_input)
+ worker = JobWorker(render_pipeline_batch, paths, settings, "Image",
+ output_dir=output_dir, same_as_input=same_as_input)
elif context_key == "nr-video":
- worker = self._nr_video_batch_worker(paths, settings, output_dir, same_as_input)
+ worker = JobWorker(render_pipeline_batch, paths, settings, "Video",
+ output_dir=output_dir, same_as_input=same_as_input)
elif context_key == "upscale-image":
worker = self._upscale_image_batch_worker(paths, settings, output_dir, same_as_input)
elif context_key == "upscale-video":
@@ -3054,8 +3715,12 @@ class AppBridge(QObject):
mask_feather=settings.mask_feather,
nr_mask=settings.nr_mask,
upscaling_factor=settings.upscaling_factor,
+ scale_method=settings.nr_scale_method,
+ dlss_mode=settings.nr_dlss_mode,
+ dlss_preset=settings.nr_dlss_preset,
output_format=settings.image_format,
quality=settings.image_quality,
+ preserve_metadata=False,
rename_mode=settings.image_rename_mode,
custom_suffix=settings.image_custom_suffix,
)
@@ -3082,6 +3747,9 @@ class AppBridge(QObject):
mask_feather=settings.mask_feather,
nr_mask=settings.nr_mask,
upscaling_factor=settings.upscaling_factor,
+ scale_method=settings.nr_scale_method,
+ dlss_mode=settings.nr_dlss_mode,
+ dlss_preset=settings.nr_dlss_preset,
codec=settings.codec,
container=container_for_codec(settings.codec),
quality=settings.quality,
@@ -3218,7 +3886,7 @@ class AppBridge(QObject):
@Slot(float)
def renderPreviewAt(self, position_ms: float = 0.0) -> None:
- """Explicit Preview: render the parked frame or selected Upscale clip."""
+ """Explicit Preview: render the parked frame or selected clip length."""
if self.canPreview:
# A pending realtime frame must not overwrite a manual clip as
# soon as it finishes (or erase its green timeline range).
@@ -3228,8 +3896,13 @@ class AppBridge(QObject):
self._scrub_preview_timer.stop()
start_seconds, frame_index = self._quantize_playhead(position_ms)
self.notePlayheadMs(position_ms)
- clip_seconds = (self._upscale_preview_length_seconds()
- if self._context_key() == "upscale-video" else None)
+ key = self._context_key()
+ if key == "upscale-video":
+ clip_seconds = self._upscale_preview_length_seconds()
+ elif key == "nr-video":
+ clip_seconds = self._nr_preview_length_seconds()
+ else:
+ clip_seconds = None
self._render_preview_impl(start_seconds, frame_index, clip_seconds=clip_seconds)
@Slot(float)
@@ -3251,8 +3924,10 @@ class AppBridge(QObject):
return
if self._context_key() not in {"nr-video", "upscale-video"}:
return
+ if self._context_key() == "nr-video" and "frame_generation" in enabled_stages(self._settings, "Video"):
+ return
ctx = self._context()
- if not ctx.has_output or not ctx.output_is_video:
+ if not ctx.has_output:
return
try:
source = self._active_queue().selected_path()
@@ -3279,7 +3954,7 @@ class AppBridge(QObject):
pass
self._operation_state = PREVIEW_CANCELLING
self.operationStateChanged.emit()
- self._scrub_preview_timer.start(750)
+ self._scrub_preview_timer.start(120 if self._can_fast_color_preview("nr-video") else 750)
def _fire_scrub_preview(self) -> None:
"""Launch the debounced scrub-refresh render, if still applicable."""
@@ -3304,7 +3979,7 @@ class AppBridge(QObject):
self._scrub_pending_pos = None
return
ctx = self._context()
- if not ctx.has_output or not ctx.output_is_video:
+ if not ctx.has_output:
self._scrub_pending_pos = None
return
pos_ms, self._scrub_pending_pos = self._scrub_pending_pos, None
@@ -3374,6 +4049,7 @@ class AppBridge(QObject):
# opened the render (Input, Output, or 2-Up) and the finished output
# swaps atomically into it. No tab is ever switched programmatically.
settings = self._settings
+ fast_color = self._can_fast_color_preview(context_key, clip_seconds=clip_seconds)
# Fingerprint of what this render is built from (selected source +
# settings snapshot). Stored on success so later tab/mode switches
# can skip the re-render while nothing changed.
@@ -3402,6 +4078,7 @@ class AppBridge(QObject):
stamp_label = f" @ {start_seconds:.2f}s"
else:
stamp_label = ""
+ self._active_preview_fast_color = fast_color
operation_id = self._set_operation(PREVIEW_PREPARING, f"Rendering preview{stamp_label}…")
# Keep the last completed preview visible while the next realtime
# generation is rendering. The output is swapped atomically only
@@ -3410,29 +4087,20 @@ class AppBridge(QObject):
try:
if context_key == "nr-image":
- opts = ImageConversionOptions(
- ai_gpu_uuid=settings.ai_gpu_uuid,
- nr_style=settings.nr_style,
- nr_intensity=settings.nr_intensity,
- nr_passes=settings.nr_passes,
- local_tone_strength=settings.local_tone_strength,
- local_structure_strength=settings.local_structure_strength,
- skin_structure_strength=settings.skin_structure_strength,
- automatic_mask=settings.automatic_mask,
- nr_color_strength=settings.nr_color_strength,
- tone_preservation=settings.tone_preservation,
- face_skin_protection=settings.face_skin_protection,
- grain_preservation=settings.grain_preservation,
- mask_feather=settings.mask_feather,
- nr_mask=settings.nr_mask,
- upscaling_factor=settings.upscaling_factor,
- output_format="PNG",
- quality=100,
- )
- def task(controller=None, progress=None):
- return render_image_preview(
- source, opts, controller=controller, progress=progress,
- )
+ if fast_color:
+ def task(controller=None, progress=None):
+ try:
+ return render_color_still_preview(
+ source, settings, "Image", controller=controller, progress=progress)
+ except FastPreviewUnavailable:
+ return render_pipeline_preview(
+ source, settings, "Image", output_dir=self._preview_cache,
+ controller=controller, progress=progress)
+ else:
+ def task(controller=None, progress=None):
+ return render_pipeline_preview(
+ source, settings, "Image", output_dir=self._preview_cache,
+ controller=controller, progress=progress)
result_kind = "image"
elif context_key == "upscale-image":
opts = image_upscale_options_from_settings(settings)
@@ -3443,38 +4111,26 @@ class AppBridge(QObject):
)
result_kind = "image"
elif context_key == "nr-video":
- opts = ConversionOptions(
- ai_gpu_uuid=settings.ai_gpu_uuid,
- video_gpu_uuid=settings.video_gpu_uuid,
- nr_style=settings.nr_style,
- nr_intensity=settings.nr_intensity,
- nr_passes=settings.nr_passes,
- local_tone_strength=settings.local_tone_strength,
- local_structure_strength=settings.local_structure_strength,
- skin_structure_strength=settings.skin_structure_strength,
- automatic_mask=settings.automatic_mask,
- nr_color_strength=settings.nr_color_strength,
- tone_preservation=settings.tone_preservation,
- face_skin_protection=settings.face_skin_protection,
- grain_preservation=settings.grain_preservation,
- shimmer_suppression=settings.shimmer_suppression,
- mask_feather=settings.mask_feather,
- nr_mask=settings.nr_mask,
- upscaling_factor=settings.upscaling_factor,
- codec=settings.codec,
- container=container_for_codec(settings.codec),
- quality=settings.quality,
- preserve_hdr=settings.hdr_mode,
- )
- def task(controller=None, progress=None):
- return process_video_preview(
- source, opts, preview_frames=1,
- preview_encoding=settings.preview_encoding,
- progress=progress, output_dir=self._preview_cache,
- controller=controller, ephemeral_preview=False,
- start_seconds=start_seconds, frame_index=frame_index,
- )
- result_kind = "video"
+ if fast_color:
+ video_size = (context.source_width, context.source_height)
+ def task(controller=None, progress=None):
+ try:
+ return render_color_still_preview(
+ source, settings, "Video", start_seconds=start_seconds,
+ video_size=video_size, controller=controller, progress=progress)
+ except FastPreviewUnavailable:
+ return render_pipeline_preview(
+ source, settings, "Video", output_dir=self._preview_cache,
+ controller=controller, progress=progress,
+ start_seconds=start_seconds)
+ result_kind = "video_still"
+ else:
+ def task(controller=None, progress=None):
+ return render_pipeline_preview(
+ source, settings, "Video", output_dir=self._preview_cache,
+ controller=controller, progress=progress,
+ start_seconds=start_seconds, clip_seconds=clip_seconds)
+ result_kind = "video"
elif context_key == "upscale-video":
opts = video_upscale_options_from_settings(settings)
opts.validate(for_render=True)
@@ -3536,8 +4192,10 @@ class AppBridge(QObject):
return
ctx = self._contexts[context_key]
media, status = result
+ actual_kind = ("video" if result_kind == "video_still" and isinstance(media, (str, Path))
+ else result_kind)
rendered_ok = False
- if result_kind == "image":
+ if actual_kind in {"image", "video_still"}:
if media is not None:
image_id = f"output-{context_key}"
self._image_provider.set_image(image_id, media)
@@ -3548,6 +4206,12 @@ class AppBridge(QObject):
f"Enhanced preview | {ctx.output_width}×{ctx.output_height}"
if ctx.output_width and ctx.output_height else "Enhanced preview"
)
+ if actual_kind == "video_still":
+ ctx.preview_source_seconds = max(0.0, float(start_seconds or 0.0))
+ ctx.preview_source_frame = frame_index
+ self._clear_rendered_ranges(context_key)
+ ctx.output_info = (f"Preview f{frame_index}/{_total} @ {start_seconds:.2f}s"
+ if _total > 0 else f"Preview @ {start_seconds:.2f}s")
rendered_ok = True
else:
if media and Path(str(media)).is_file():
@@ -3568,6 +4232,11 @@ class AppBridge(QObject):
self._add_rendered_range(context_key, start_seconds, str(media), clip_seconds)
else:
self._clear_rendered_ranges(context_key)
+ elif context_key == "nr-video":
+ if clip_seconds is not None:
+ self._add_rendered_range(context_key, start_seconds, str(media), clip_seconds)
+ else:
+ self._clear_rendered_ranges(context_key)
if start_seconds > 0.05 and _total > 0:
ctx.output_info = f"Preview f{frame_index}/{_total} @ {start_seconds:.2f}s | {Path(str(media)).name}"
elif start_seconds > 0.05:
@@ -3917,7 +4586,8 @@ class AppBridge(QObject):
save_settings(CONFIG_PATH, self._settings)
except Exception as exc:
self._log(f"Failed to save settings during shutdown: {exc}")
- for worker in (self._active_worker, self._scan_worker, self._metadata_worker, self._live_worker):
+ for worker in (self._active_worker, self._scan_worker, self._metadata_worker,
+ self._live_worker, self._lut_save_worker, self._lut_auto_worker):
if worker is not None:
try:
worker.controller.stop()
@@ -3974,6 +4644,12 @@ class AppBridge(QObject):
if folder.exists():
os.startfile(folder)
+ @Slot()
+ def openThirdPartyNotices(self) -> None:
+ notices = ROOT / "THIRD-PARTY-NOTICES.txt"
+ if notices.is_file():
+ os.startfile(notices)
+
@Slot(str)
def copyToClipboard(self, text: str) -> None:
clipboard = QGuiApplication.clipboard()
diff --git a/src/desktop/cas_sharpening.py b/src/desktop/cas_sharpening.py
new file mode 100644
index 0000000..af73566
--- /dev/null
+++ b/src/desktop/cas_sharpening.py
@@ -0,0 +1,235 @@
+"""File-backed sharpening stage with FidelityFX CAS and NVIDIA NVSharpen.
+
+The CAS core below is a CPU implementation of the default no-scaling path in
+``native (dev)/FidelityFX-SDK-v1.1.4/sdk/include/FidelityFX/gpu/cas/ffx_cas.h``.
+It uses the SDK's sharpness constant, cross-neighbour soft min/max and green
+channel weight. The SDK's D3D12/Vulkan dispatcher is designed for a GPU render
+graph; this file-backed stage applies that pixel math to decoded RGB frames
+and blends the result by the user-facing percentage. NVIDIA NVSharpen is
+implemented separately in ``nis_sharpening.py`` and selected here at runtime.
+"""
+
+# CAS algorithm derived from FidelityFX SDK 1.1.4.
+# Copyright (C) 2024 Advanced Micro Devices, Inc.
+# See AMD-FidelityFX-CAS-LICENSE.txt in this directory.
+
+from __future__ import annotations
+
+from fractions import Fraction
+from pathlib import Path
+from typing import Callable
+
+import av
+import numpy as np
+
+from ..core import ffmpeg
+from ..core.jobs import Cancelled, JobController
+from ..neural_rendering.image.decoder import decode_image
+from ..neural_rendering.image.encoder import _encode_image
+from ..neural_rendering.image.models import ImageConversionOptions
+from ..settings.models import UISettings
+from .nis_sharpening import sharpen_rgb as nis_sharpen_rgb
+
+
+def _linearize(value: np.ndarray, transfer: str) -> np.ndarray:
+ if transfer == "srgb":
+ return np.where(value <= 0.04045, value / 12.92,
+ ((value + 0.055) / 1.055) ** 2.4)
+ if transfer == "bt709":
+ return np.where(value < 0.081, value / 4.5,
+ ((value + 0.099) / 1.099) ** (1.0 / 0.45))
+ return value
+
+
+def _encode_transfer(value: np.ndarray, transfer: str) -> np.ndarray:
+ if transfer == "srgb":
+ return np.where(value <= 0.0031308, value * 12.92,
+ 1.055 * np.power(value, 1.0 / 2.4) - 0.055)
+ if transfer == "bt709":
+ return np.where(value < 0.018, value * 4.5,
+ 1.099 * np.power(value, 0.45) - 0.099)
+ return value
+
+
+def sharpen_rgb(pixels: np.ndarray, sharpness: int, *, transfer: str = "srgb",
+ alpha: np.ndarray | None = None,
+ controller: JobController | None = None) -> np.ndarray:
+ """Apply the SDK's sharpen-only CAS filter to 8/16-bit RGB pixels.
+
+ 0% is an application-level bypass. In the SDK, sharpness=0 still applies
+ its baseline filter, so the filtered result is blended by the UI strength
+ for a smooth transition from an untouched input to SDK maximum sharpness.
+ Alpha is not filtered. Semi-transparent pixels and their opaque neighbours
+ are left alone to keep hidden RGB from causing edge halos.
+ """
+ if pixels.ndim != 3 or pixels.shape[2] != 3 or pixels.dtype not in (np.uint8, np.uint16):
+ raise ValueError("CAS requires an 8-bit or 16-bit RGB image.")
+ if isinstance(sharpness, bool) or not isinstance(sharpness, int) or not 0 <= sharpness <= 100:
+ raise ValueError("CAS sharpness must be an integer from 0 to 100.")
+ if alpha is not None and (alpha.shape != pixels.shape[:2] or alpha.dtype != pixels.dtype):
+ raise ValueError("CAS alpha must match the RGB pixels.")
+ if transfer not in {"srgb", "bt709", "linear"}:
+ raise ValueError("Unsupported CAS transfer function.")
+ if sharpness == 0 or min(pixels.shape[:2]) < 2:
+ return pixels.copy()
+
+ height, width = pixels.shape[:2]
+ maximum = float(np.iinfo(pixels.dtype).max)
+ mix = sharpness / 100.0
+ peak = -1.0 / (8.0 - 3.0 * sharpness / 100.0) # ffxCasSetup()
+ result = np.empty_like(pixels)
+ tile = 256 # Keep 4K/16-bit intermediates bounded while retaining a 1px halo.
+
+ for y in range(0, height, tile):
+ for x in range(0, width, tile):
+ if controller is not None and controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ bottom, right = min(height, y + tile), min(width, x + tile)
+ y0, y1 = max(0, y - 1), min(height, bottom + 1)
+ x0, x1 = max(0, x - 1), min(width, right + 1)
+ border = ((int(y == 0), int(bottom == height)),
+ (int(x == 0), int(right == width)))
+ block = np.pad(pixels[y0:y1, x0:x1], (*border, (0, 0)), mode="edge")
+ block = block.astype(np.float32) / maximum
+ block = _linearize(block, transfer)
+ b = block[:-2, 1:-1]
+ d = block[1:-1, :-2]
+ e = block[1:-1, 1:-1]
+ f = block[1:-1, 2:]
+ h = block[2:, 1:-1]
+
+ minimum = np.minimum(np.minimum(np.minimum(d, e), f), np.minimum(b, h))
+ maximum_rgb = np.maximum(np.maximum(np.maximum(d, e), f), np.maximum(b, h))
+ # The SDK computes each channel's amplification, then uses only
+ # green's weight for all output channels.
+ green_min = minimum[..., 1]
+ green_max = maximum_rgb[..., 1]
+ amplification = np.sqrt(np.clip(
+ np.minimum(green_min, 1.0 - green_max) /
+ np.maximum(green_max, np.finfo(np.float32).tiny), 0.0, 1.0))
+ weight = amplification * peak
+ if alpha is not None:
+ a = np.pad(alpha[y0:y1, x0:x1], border, mode="edge")
+ fully_opaque = ((a[1:-1, 1:-1] == maximum) &
+ (a[:-2, 1:-1] == maximum) &
+ (a[1:-1, :-2] == maximum) &
+ (a[1:-1, 2:] == maximum) &
+ (a[2:, 1:-1] == maximum))
+ weight = np.where(fully_opaque, weight, 0.0)
+ filtered = np.clip((e + weight[..., None] * (b + d + f + h)) /
+ (1.0 + 4.0 * weight[..., None]), 0.0, 1.0)
+ filtered = e + mix * (filtered - e)
+ filtered = np.clip(_encode_transfer(filtered, transfer), 0.0, 1.0)
+ result[y:bottom, x:right] = np.rint(filtered * maximum).astype(pixels.dtype)
+ return result
+
+
+def _selected_sharpen(pixels: np.ndarray, settings: UISettings, *, transfer: str,
+ alpha: np.ndarray | None = None,
+ controller: JobController | None = None) -> np.ndarray:
+ if settings.sharpening_method == "NVIDIA NIS":
+ return nis_sharpen_rgb(pixels, settings.cas_sharpness,
+ alpha=alpha, controller=controller)
+ if settings.sharpening_method == "AMD CAS":
+ return sharpen_rgb(pixels, settings.cas_sharpness, transfer=transfer,
+ alpha=alpha, controller=controller)
+ raise ValueError(f"Unknown sharpening method: {settings.sharpening_method!r}.")
+
+
+def sharpen_image(source: Path, settings: UISettings, directory: Path,
+ controller: JobController, progress: Callable) -> Path:
+ if settings.cas_sharpness == 0:
+ progress(1.0, "Sharpening complete")
+ return source
+ decoded = decode_image(source)
+ progress(0.1, "Sharpening image")
+ rgba = decoded.rgba
+ rgba[..., :3] = _selected_sharpen(rgba[..., :3], settings, transfer="srgb",
+ alpha=decoded.alpha, controller=controller)
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ output = directory / "sharpened.tiff"
+ progress(0.85, "Saving sharpened image")
+ _encode_image(output, rgba,
+ ImageConversionOptions(output_format="TIFF", preserve_metadata=False),
+ {}, generate_preview=False, controller=controller,
+ has_transparency=decoded.alpha is not None)
+ progress(1.0, "Sharpening complete")
+ return output
+
+
+def sharpen_video(source: Path, settings: UISettings, directory: Path,
+ controller: JobController, progress: Callable) -> Path:
+ if settings.cas_sharpness == 0:
+ progress(1.0, "Sharpening complete")
+ return source
+ metadata = ffmpeg.probe_video(source, count_mode="metadata", controller=controller)
+ if metadata.get("hdr"):
+ raise ValueError("Sharpening requires SDR video at this position. Move it before HDR conversion.")
+ transfer = {"iec61966-2-1": "srgb", "linear": "linear"}.get(
+ metadata.get("color_transfer"), "bt709")
+ output = directory / "sharpened.mkv"
+ input_container = av.open(str(source))
+ output_container = None
+ try:
+ input_stream = input_container.streams.video[0]
+ input_stream.thread_type = "AUTO"
+ rate = input_stream.average_rate or Fraction(30, 1)
+ time_base = input_stream.time_base or Fraction(1, max(1, round(float(rate))))
+ output_container = av.open(str(output), mode="w")
+ output_stream = output_container.add_stream("ffv1", rate=rate)
+ output_stream.width = input_stream.width
+ output_stream.height = input_stream.height
+ output_stream.pix_fmt = "gbrp10le"
+ if input_stream.sample_aspect_ratio is not None:
+ output_stream.sample_aspect_ratio = input_stream.sample_aspect_ratio
+ output_stream.time_base = time_base
+ output_stream.codec_context.time_base = time_base
+ output_stream.codec_context.colorspace = 0 # GBR
+ output_stream.codec_context.color_range = 2 # full range
+ output_stream.codec_context.color_primaries = input_stream.codec_context.color_primaries or 1
+ output_stream.codec_context.color_trc = input_stream.codec_context.color_trc or 1
+ output_stream.metadata.update(input_stream.metadata)
+ output_stream.codec_context.open()
+ estimated = int(metadata.get("frames") or 0)
+ if estimated <= 0:
+ estimated = max(1, round(float(metadata.get("duration") or 0) * float(rate)))
+ count = 0
+ last_pts: int | None = None
+ frame_step = max(1, round(Fraction(1, 1) / rate / time_base))
+ for frame in input_container.decode(input_stream):
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ if (frame.width, frame.height) != (output_stream.width, output_stream.height):
+ raise ValueError("Video dimensions changed during sharpening.")
+ rgb = frame.to_ndarray(format="rgb48le")
+ filtered = _selected_sharpen(rgb, settings, transfer=transfer,
+ controller=controller)
+ processed = av.VideoFrame.from_ndarray(filtered, format="rgb48le")
+ processed = processed.reformat(format="gbrp10le")
+ pts = (round(Fraction(frame.pts) * (frame.time_base or time_base) / time_base)
+ if frame.pts is not None else (last_pts + frame_step if last_pts is not None else 0))
+ if last_pts is not None and pts <= last_pts:
+ raise ValueError("Source timestamps are not strictly increasing; Sharpening cannot preserve this video timing.")
+ processed.pts = pts
+ processed.time_base = time_base
+ processed.color_primaries = output_stream.codec_context.color_primaries
+ processed.color_trc = output_stream.codec_context.color_trc
+ processed.colorspace = 0
+ processed.color_range = 2
+ for packet in output_stream.encode(processed):
+ output_container.mux(packet)
+ last_pts = pts
+ count += 1
+ if count == 1 or count % 12 == 0:
+ progress(min(0.95, count / estimated), "Sharpening video")
+ if not count:
+ raise ValueError("The input contains no decodable video frames.")
+ for packet in output_stream.encode():
+ output_container.mux(packet)
+ finally:
+ if output_container is not None:
+ output_container.close()
+ input_container.close()
+ progress(1.0, "Sharpening complete")
+ return output
diff --git a/src/desktop/color_preview.py b/src/desktop/color_preview.py
new file mode 100644
index 0000000..1108ae9
--- /dev/null
+++ b/src/desktop/color_preview.py
@@ -0,0 +1,164 @@
+"""Low-latency, full-resolution still previews for the Coloring LUT card.
+
+The export pipeline bakes a .cube and writes lossless intermediates. A still
+preview can evaluate the same grading function at the source pixels directly:
+this avoids the cube bake, intermediate files, and video encoder. The source
+frame and its unadjusted LUT sample are reused while sliders move.
+"""
+
+from __future__ import annotations
+
+import subprocess
+import threading
+from dataclasses import dataclass
+from pathlib import Path
+
+import numpy as np
+
+from ..core.jobs import Cancelled
+from ..core.paths import FFMPEG
+from ..neural_rendering.image.decoder import decode_image
+from ..settings.models import UISettings
+from .coloring import grade_lut_rgb, load_cube_lut, sample_cube_lut
+
+
+MAX_PREVIEW_PIXELS = 8_500_000
+_MAX_CACHE_BYTES = 320 * 1024 * 1024
+_lock = threading.RLock()
+
+
+@dataclass
+class _CachedFrame:
+ key: tuple
+ rgba: np.ndarray
+ rgb: np.ndarray
+ lut_key: tuple | None = None
+ sampled: np.ndarray | None = None
+
+
+_cached_frame: _CachedFrame | None = None
+
+
+class FastPreviewUnavailable(ValueError):
+ """Use the file-backed preview when this source cannot use the RAM path."""
+
+
+def _source_key(source: str | Path, mode: str, start_seconds: float,
+ size: tuple[int, int] | None) -> tuple:
+ path = Path(source).resolve()
+ stat = path.stat()
+ return (str(path), stat.st_mtime_ns, stat.st_size, mode,
+ round(float(start_seconds), 6) if mode == "Video" else 0,
+ size if mode == "Video" else None)
+
+
+def _video_frame(path: Path, start_seconds: float, size: tuple[int, int]) -> np.ndarray:
+ width, height = size
+ if width <= 0 or height <= 0 or width * height > MAX_PREVIEW_PIXELS:
+ raise FastPreviewUnavailable("Video dimensions are unavailable for the fast preview.")
+ # Match the seek used by the lossless clip extractor. ffmpeg converts the
+ # decoded frame to 16-bit RGBA, so 10-bit source color is not truncated.
+ start = max(0.0, float(start_seconds) - 0.002)
+ fast_seek = max(0.0, start - 2.0)
+ accurate_seek = max(0.0, start - fast_seek)
+ command = [str(FFMPEG), "-hide_banner", "-loglevel", "error",
+ "-ss", f"{fast_seek:.6f}", "-i", str(path),
+ "-ss", f"{accurate_seek:.6f}", "-frames:v", "1", "-an",
+ "-f", "rawvideo", "-pix_fmt", "rgba64le", "pipe:1"]
+ result = subprocess.run(
+ command, capture_output=True, timeout=30, check=False,
+ creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0),
+ )
+ if result.returncode != 0:
+ raise RuntimeError(result.stderr.decode("utf-8", "replace").strip()
+ or "Could not decode the preview frame.")
+ if len(result.stdout) != width * height * 8:
+ raise FastPreviewUnavailable("Decoded frame dimensions differ from the source metadata.")
+ return np.frombuffer(result.stdout, dtype="<u2").reshape(height, width, 4)
+
+
+def _frame(key: tuple, size: tuple[int, int] | None) -> _CachedFrame:
+ global _cached_frame
+ with _lock:
+ if _cached_frame is not None and _cached_frame.key == key:
+ return _cached_frame
+ path = Path(key[0])
+ rgba = decode_image(path).rgba if key[3] == "Image" else _video_frame(path, key[4], size)
+ if rgba.shape[0] * rgba.shape[1] > MAX_PREVIEW_PIXELS:
+ raise FastPreviewUnavailable("This image is too large for the in-memory preview.")
+ maximum = np.iinfo(rgba.dtype).max
+ rgb = rgba[..., :3].astype(np.float32) / float(maximum)
+ frame = _CachedFrame(key, rgba, rgb)
+ if rgba.nbytes + rgb.nbytes <= _MAX_CACHE_BYTES:
+ with _lock:
+ _cached_frame = frame
+ return frame
+
+
+def _lut_sample(frame: _CachedFrame, path: str) -> np.ndarray:
+ if not path:
+ return frame.rgb
+ lut_path = Path(path).resolve()
+ stat = lut_path.stat()
+ key = (str(lut_path), stat.st_mtime_ns, stat.st_size)
+ with _lock:
+ if frame.lut_key == key and frame.sampled is not None:
+ return frame.sampled
+ lut = load_cube_lut(lut_path)
+ # Keep temporary trilinear arrays bounded for large source frames.
+ sampled = np.empty_like(frame.rgb)
+ flattened_input = frame.rgb.reshape(-1, 3)
+ flattened_output = sampled.reshape(-1, 3)
+ for offset in range(0, len(flattened_input), 262_144):
+ end = min(len(flattened_input), offset + 262_144)
+ flattened_output[offset:end] = sample_cube_lut(flattened_input[offset:end], lut)
+ if frame.rgba.nbytes + frame.rgb.nbytes + sampled.nbytes <= _MAX_CACHE_BYTES:
+ with _lock:
+ frame.lut_key = key
+ frame.sampled = sampled
+ return sampled
+
+
+def render_color_still_preview(source: str | Path, settings: UISettings, mode: str,
+ *, start_seconds: float = 0.0,
+ video_size: tuple[int, int] | None = None,
+ controller=None, progress=None) -> tuple[np.ndarray, str]:
+ """Grade an image or one video frame in memory at source resolution.
+
+ The selected export LUT resolution affects .cube sampling, not this
+ evaluation. Evaluating the grading function directly is at least as
+ accurate as sampling its baked 33/65/129-point approximation.
+ """
+ if mode not in {"Image", "Video"}:
+ raise ValueError("Unsupported coloring preview mode.")
+ if mode == "Video" and video_size is None:
+ raise ValueError("Video dimensions are required for the fast preview.")
+ key = _source_key(source, mode, start_seconds, video_size)
+ if controller is not None and controller.cancel.is_set():
+ raise Cancelled("Preview superseded by newer settings.")
+ frame = _frame(key, video_size)
+ if progress is not None:
+ progress(0.35, "Coloring: source frame ready")
+ if controller is not None and controller.cancel.is_set():
+ raise Cancelled("Preview superseded by newer settings.")
+ if settings.lut_mix == 0 and settings.lut_path:
+ load_cube_lut(settings.lut_path)
+ sampled = frame.rgb if settings.lut_mix == 0 else _lut_sample(frame, settings.lut_path)
+ if controller is not None and controller.cancel.is_set():
+ raise Cancelled("Preview superseded by newer settings.")
+ maximum = np.iinfo(frame.rgba.dtype).max
+ result = np.empty_like(frame.rgba)
+ source_rgb = frame.rgb.reshape(-1, 3)
+ sampled_rgb = sampled.reshape(-1, 3)
+ output_pixels = result.reshape(-1, 4)
+ for offset in range(0, len(source_rgb), 262_144):
+ if controller is not None and controller.cancel.is_set():
+ raise Cancelled("Preview superseded by newer settings.")
+ end = min(len(source_rgb), offset + 262_144)
+ graded = grade_lut_rgb(source_rgb[offset:end], sampled_rgb[offset:end], settings)
+ output_pixels[offset:end, :3] = np.rint(
+ np.clip(graded, 0.0, 1.0) * maximum).astype(frame.rgba.dtype)
+ result[..., 3] = frame.rgba[..., 3]
+ if progress is not None:
+ progress(1.0, "Coloring preview complete")
+ return result, ""
diff --git a/src/desktop/coloring.py b/src/desktop/coloring.py
new file mode 100644
index 0000000..c1c4273
--- /dev/null
+++ b/src/desktop/coloring.py
@@ -0,0 +1,315 @@
+"""Perceptual color matching and 3D .cube LUT grading for images and video."""
+
+from __future__ import annotations
+
+import os
+import tempfile
+from dataclasses import dataclass
+from functools import lru_cache
+from pathlib import Path
+
+import cv2
+import numpy as np
+
+from ..settings.models import LUT_ADJUSTMENT_RANGES, UISettings
+
+
+@dataclass(frozen=True)
+class CubeLUT:
+ size: int
+ domain_min: np.ndarray
+ domain_max: np.ndarray
+ # .cube entries are stored with red changing fastest, then green, then blue.
+ values: np.ndarray # [blue, green, red, output channel]
+
+
+@lru_cache(maxsize=1)
+def identity_cube_lut() -> CubeLUT:
+ """Use the original colors as the base when no .cube file is selected."""
+ levels = np.asarray((0.0, 1.0), dtype=np.float32)
+ blue, green, red = np.meshgrid(levels, levels, levels, indexing="ij")
+ values = np.stack((red, green, blue), axis=-1)
+ return CubeLUT(2, np.zeros(3, dtype=np.float32),
+ np.ones(3, dtype=np.float32), values)
+
+
+def load_cube_lut(file_path: str | Path) -> CubeLUT:
+ """Read a 3D .cube file, caching by path and modification time."""
+ path = Path(file_path).resolve()
+ if path.suffix.casefold() != ".cube":
+ raise ValueError("Choose a .cube LUT file.")
+ try:
+ stat = path.stat()
+ except OSError as exc:
+ raise ValueError(f"LUT file is unavailable: {path}") from exc
+ if not path.is_file() or stat.st_size > 128 * 1024 * 1024:
+ raise ValueError("LUT must be an existing .cube file smaller than 128 MiB.")
+ return _load_cube_cached(str(path), stat.st_mtime_ns, stat.st_size)
+
+
+@lru_cache(maxsize=4)
+def _load_cube_cached(path: str, mtime_ns: int, file_size: int) -> CubeLUT:
+ del mtime_ns, file_size # Cache keys make an edited LUT reload on the next render.
+ size: int | None = None
+ domain_min = np.zeros(3, dtype=np.float32)
+ domain_max = np.ones(3, dtype=np.float32)
+ entries: np.ndarray | None = None
+ row_count = 0
+ try:
+ with Path(path).open("r", encoding="utf-8-sig") as stream:
+ for line_number, raw in enumerate(stream, 1):
+ line = raw.partition("#")[0].strip()
+ if not line:
+ continue
+ words = line.split()
+ key = words[0].upper()
+ if key == "TITLE":
+ continue
+ if key == "LUT_3D_SIZE":
+ if size is not None or len(words) != 2:
+ raise ValueError("Invalid LUT_3D_SIZE declaration.")
+ size = int(words[1])
+ if not 2 <= size <= 129:
+ raise ValueError("3D LUT size must be between 2 and 129.")
+ entries = np.empty((size ** 3, 3), dtype=np.float32)
+ continue
+ if key == "LUT_1D_SIZE":
+ raise ValueError("Select a 3D .cube LUT; 1D LUTs are not supported.")
+ if key in {"DOMAIN_MIN", "DOMAIN_MAX"}:
+ if len(words) != 4:
+ raise ValueError(f"Invalid {key} declaration.")
+ values = np.asarray([float(value) for value in words[1:]], dtype=np.float32)
+ if not np.all(np.isfinite(values)):
+ raise ValueError(f"Invalid {key} values.")
+ if key == "DOMAIN_MIN":
+ domain_min = values
+ else:
+ domain_max = values
+ continue
+ if key == "LUT_3D_INPUT_RANGE":
+ if len(words) != 3:
+ raise ValueError("Invalid LUT_3D_INPUT_RANGE declaration.")
+ domain_min = np.full(3, float(words[1]), dtype=np.float32)
+ domain_max = np.full(3, float(words[2]), dtype=np.float32)
+ continue
+ if size is None or len(words) != 3:
+ raise ValueError(f"Invalid 3D LUT entry on line {line_number}.")
+ values = tuple(float(value) for value in words)
+ if not all(np.isfinite(value) for value in values):
+ raise ValueError(f"Nonfinite 3D LUT entry on line {line_number}.")
+ if row_count >= size ** 3:
+ raise ValueError("The 3D LUT contains more entries than declared.")
+ assert entries is not None
+ entries[row_count] = values
+ row_count += 1
+ except (OSError, UnicodeError, OverflowError) as exc:
+ raise ValueError(f"Cannot read .cube LUT: {path}") from exc
+ if size is None or row_count != size ** 3:
+ raise ValueError("The 3D LUT has an incorrect number of color entries.")
+ if np.any(domain_max <= domain_min):
+ raise ValueError("3D LUT DOMAIN_MAX must exceed DOMAIN_MIN on every channel.")
+ assert entries is not None
+ values = entries.reshape(size, size, size, 3)
+ if not np.all(np.isfinite(domain_min)) or not np.all(np.isfinite(domain_max)) or not np.all(np.isfinite(values)):
+ raise ValueError("3D LUT contains values outside the supported numeric range.")
+ return CubeLUT(size, domain_min, domain_max, values)
+
+
+def sample_cube_lut(rgb: np.ndarray, lut: CubeLUT) -> np.ndarray:
+ """Sample a 3D LUT at floating point RGB coordinates without quantization."""
+ coords = np.clip((rgb - lut.domain_min) / (lut.domain_max - lut.domain_min), 0.0, 1.0) * (lut.size - 1)
+ low = np.floor(coords).astype(np.intp)
+ high = np.minimum(low + 1, lut.size - 1)
+ fraction = coords - low
+ r0, g0, b0 = (low[..., channel] for channel in range(3))
+ r1, g1, b1 = (high[..., channel] for channel in range(3))
+ fr, fg, fb = (fraction[..., channel, None] for channel in range(3))
+ table = lut.values
+ c00 = table[b0, g0, r0] * (1 - fr) + table[b0, g0, r1] * fr
+ c01 = table[b0, g1, r0] * (1 - fr) + table[b0, g1, r1] * fr
+ c10 = table[b1, g0, r0] * (1 - fr) + table[b1, g0, r1] * fr
+ c11 = table[b1, g1, r0] * (1 - fr) + table[b1, g1, r1] * fr
+ return (c00 * (1 - fg) + c01 * fg) * (1 - fb) + (c10 * (1 - fg) + c11 * fg) * fb
+
+
+def has_lut_adjustments(settings: UISettings) -> bool:
+ return any(getattr(settings, key) != (100 if key == "lut_mix" else 0)
+ for key in LUT_ADJUSTMENT_RANGES)
+
+
+def _smoothstep(low: float, high: float, value: np.ndarray) -> np.ndarray:
+ t = np.clip((value - low) / (high - low), 0.0, 1.0)
+ return t * t * (3.0 - 2.0 * t)
+
+
+def grade_lut_rgb(identity: np.ndarray, sampled: np.ndarray, settings: UISettings) -> np.ndarray:
+ """Grade display-referred LUT output and blend it with the input RGB."""
+ mix = settings.lut_mix / 100.0
+ if mix == 0:
+ return np.clip(identity, 0.0, 1.0)
+ if not has_lut_adjustments(settings):
+ return sampled
+
+ rgb = np.clip(sampled, 0.0, 1.0).astype(np.float32, copy=True)
+ if settings.lut_exposure or settings.lut_temperature or settings.lut_tint:
+ linear = np.where(rgb <= 0.04045, rgb / 12.92, ((rgb + 0.055) / 1.055) ** 2.4)
+ warmth = settings.lut_temperature / 100.0
+ tint = settings.lut_tint / 100.0
+ gains = np.asarray((1.0 + 0.2 * warmth + 0.075 * tint,
+ 1.0 - 0.15 * tint,
+ 1.0 - 0.2 * warmth + 0.075 * tint), dtype=np.float32)
+ linear = np.maximum(linear * gains * (2.0 ** settings.lut_exposure), 0.0)
+ rgb = np.where(linear <= 0.0031308, linear * 12.92,
+ 1.055 * np.power(linear, 1.0 / 2.4) - 0.055)
+ rgb = np.clip(rgb, 0.0, 1.0)
+
+ if settings.lut_contrast:
+ rgb = np.clip((rgb - 0.5) * (1.0 + settings.lut_contrast / 100.0) + 0.5, 0.0, 1.0)
+ if any((settings.lut_shadows, settings.lut_highlights, settings.lut_whites, settings.lut_blacks)):
+ luma = np.dot(rgb, np.asarray((0.2126, 0.7152, 0.0722), dtype=np.float32))
+ shift = (settings.lut_shadows / 100.0 * 0.32 * (1.0 - luma) ** 2
+ + settings.lut_highlights / 100.0 * 0.32 * luma ** 2
+ + settings.lut_whites / 100.0 * 0.18 * _smoothstep(0.62, 1.0, luma)
+ + settings.lut_blacks / 100.0 * 0.18 * (1.0 - _smoothstep(0.0, 0.38, luma)))
+ rgb = np.clip(rgb + shift[..., None], 0.0, 1.0)
+ if settings.lut_midtones:
+ rgb = np.power(rgb, 2.0 ** (-settings.lut_midtones / 100.0))
+ if settings.lut_hue:
+ # Rotate chroma in YIQ while keeping its luminance component.
+ angle = np.deg2rad(settings.lut_hue)
+ cosine, sine = np.cos(angle), np.sin(angle)
+ y = rgb[..., 0] * 0.299 + rgb[..., 1] * 0.587 + rgb[..., 2] * 0.114
+ i = rgb[..., 0] * 0.596 - rgb[..., 1] * 0.274 - rgb[..., 2] * 0.322
+ q = rgb[..., 0] * 0.211 - rgb[..., 1] * 0.523 + rgb[..., 2] * 0.312
+ rotated_i = i * cosine - q * sine
+ rotated_q = i * sine + q * cosine
+ rgb = np.stack((y + 0.956 * rotated_i + 0.621 * rotated_q,
+ y - 0.272 * rotated_i - 0.647 * rotated_q,
+ y - 1.106 * rotated_i + 1.703 * rotated_q), axis=-1)
+ rgb = np.clip(rgb, 0.0, 1.0)
+ if settings.lut_saturation or settings.lut_vibrance:
+ luma = np.dot(rgb, np.asarray((0.2126, 0.7152, 0.0722), dtype=np.float32))[..., None]
+ chroma = np.max(rgb, axis=-1, keepdims=True) - np.min(rgb, axis=-1, keepdims=True)
+ factor = (1.0 + settings.lut_saturation / 100.0
+ + settings.lut_vibrance / 100.0 * (1.0 - chroma) ** 2)
+ rgb = np.clip(luma + (rgb - luma) * np.maximum(0.0, factor), 0.0, 1.0)
+ return np.clip(identity * (1.0 - mix) + rgb * mix, 0.0, 1.0)
+
+
+def _graded_cube_slices(source: CubeLUT, settings: UISettings, size: int):
+ levels = np.linspace(0.0, 1.0, size, dtype=np.float32)
+ red = np.tile(levels, size)
+ green = np.repeat(levels, size)
+ for blue in levels:
+ identity = np.column_stack((red, green, np.full_like(red, blue)))
+ sampled = sample_cube_lut(identity, source)
+ yield grade_lut_rgb(identity, sampled, settings).reshape(size, size, 3)
+
+
+def compose_cube_lut(source: CubeLUT, settings: UISettings, size: int) -> CubeLUT:
+ """Bake the selected LUT and grading controls into a standard RGB cube."""
+ if size not in (33, 65, 129):
+ raise ValueError("LUT resolution must be 33, 65, or 129.")
+ values = np.empty((size, size, size, 3), dtype=np.float32)
+ for index, plane in enumerate(_graded_cube_slices(source, settings, size)):
+ values[index] = plane
+ return CubeLUT(size, np.zeros(3, dtype=np.float32),
+ np.ones(3, dtype=np.float32), values)
+
+
+def save_cube_lut(destination: str | Path, source_path: str | Path | None,
+ settings: UISettings, *, controller=None, progress=None) -> Path:
+ """Write a baked .cube atomically, keeping memory bounded at 129³."""
+ source = load_cube_lut(source_path) if source_path else identity_cube_lut()
+ size = settings.lut_resolution
+ if size not in (33, 65, 129):
+ raise ValueError("LUT resolution must be 33, 65, or 129.")
+ target = Path(destination).expanduser().resolve()
+ if target.suffix.casefold() != ".cube":
+ target = target.with_suffix(".cube")
+ if not target.parent.is_dir():
+ raise ValueError("Choose an existing folder for the saved LUT.")
+ fd, temporary = tempfile.mkstemp(prefix=target.stem + ".", suffix=".tmp", dir=target.parent)
+ try:
+ with os.fdopen(fd, "w", encoding="ascii", newline="\n") as stream:
+ stream.write('TITLE "Visual Enhancer Graded LUT"\n')
+ stream.write(f"LUT_3D_SIZE {size}\nDOMAIN_MIN 0 0 0\nDOMAIN_MAX 1 1 1\n")
+ for index, plane in enumerate(_graded_cube_slices(source, settings, size)):
+ if controller is not None and controller.cancel.is_set():
+ from ..core.jobs import Cancelled
+ raise Cancelled("LUT export cancelled.")
+ np.savetxt(stream, plane.reshape(-1, 3), fmt="%.7f")
+ if progress is not None:
+ progress((index + 1) / size, "Saving LUT")
+ os.replace(temporary, target)
+ finally:
+ if os.path.exists(temporary):
+ os.unlink(temporary)
+ return target
+
+
+def apply_cube_lut(rgba: np.ndarray, lut: CubeLUT) -> np.ndarray:
+ """Apply trilinear RGB interpolation in chunks, preserving source alpha and depth."""
+ result = np.empty_like(rgba)
+ result[..., 3] = rgba[..., 3]
+ maximum = float(np.iinfo(rgba.dtype).max)
+ rows_per_chunk = max(1, 262_144 // max(1, rgba.shape[1]))
+ for top in range(0, rgba.shape[0], rows_per_chunk):
+ bottom = min(rgba.shape[0], top + rows_per_chunk)
+ rgb = rgba[top:bottom, :, :3].astype(np.float32) / maximum
+ color = sample_cube_lut(rgb, lut)
+ result[top:bottom, :, :3] = np.rint(np.clip(color, 0.0, 1.0) * maximum).astype(rgba.dtype)
+ return result
+
+
+def _lab_statistics(rgba: np.ndarray) -> tuple[np.ndarray, np.ndarray] | None:
+ """Measure visible pixels on a bounded preview, regardless of image size."""
+ height, width = rgba.shape[:2]
+ scale = min(1.0, 512.0 / max(height, width))
+ if scale < 1.0:
+ sample = cv2.resize(rgba, (max(1, round(width * scale)),
+ max(1, round(height * scale))), interpolation=cv2.INTER_AREA)
+ else:
+ sample = rgba
+ maximum = float(np.iinfo(sample.dtype).max)
+ visible = sample[..., 3] > maximum * 0.05
+ if not np.any(visible):
+ return None
+ rgb = sample[..., :3].astype(np.float32) / maximum
+ lab = cv2.cvtColor(rgb, cv2.COLOR_RGB2Lab)
+ pixels = lab[visible]
+ # Trim sparse highlights and deep shadows so isolated pixels do not
+ # determine the grade of the entire image.
+ lower, upper = np.percentile(pixels, (2, 98), axis=0)
+ pixels = np.clip(pixels, lower, upper)
+ return pixels.mean(axis=0), pixels.std(axis=0)
+
+
+def match_image_colors(rgba: np.ndarray, reference_rgba: np.ndarray) -> np.ndarray:
+ """Match Lab channel distributions while keeping detail and alpha intact.
+
+ The transform is measured from each image independently, then applied in
+ row chunks so large and high bit depth images do not need a full size Lab
+ working copy. The bounded contrast ratio avoids destructive flat areas.
+ """
+ source_stats = _lab_statistics(rgba)
+ reference_stats = _lab_statistics(reference_rgba)
+ if source_stats is None or reference_stats is None:
+ return rgba.copy()
+ source_mean, source_std = source_stats
+ target_mean, target_std = reference_stats
+ ratio = np.clip(target_std / np.maximum(source_std, 1.0), 0.5, 2.0)
+ result = np.empty_like(rgba)
+ result[..., 3] = rgba[..., 3]
+ maximum = float(np.iinfo(rgba.dtype).max)
+ rows = max(1, 1_000_000 // max(1, rgba.shape[1]))
+ for top in range(0, rgba.shape[0], rows):
+ bottom = min(rgba.shape[0], top + rows)
+ rgb = rgba[top:bottom, :, :3].astype(np.float32) / maximum
+ lab = cv2.cvtColor(rgb, cv2.COLOR_RGB2Lab)
+ lab = (lab - source_mean) * ratio + target_mean
+ lab[..., 0] = np.clip(lab[..., 0], 0.0, 100.0)
+ lab[..., 1:] = np.clip(lab[..., 1:], -127.0, 127.0)
+ matched = cv2.cvtColor(lab.astype(np.float32), cv2.COLOR_Lab2RGB)
+ result[top:bottom, :, :3] = np.rint(np.clip(matched, 0.0, 1.0) * maximum).astype(rgba.dtype)
+ return result
diff --git a/src/desktop/denoising.py b/src/desktop/denoising.py
new file mode 100644
index 0000000..b2a9aa1
--- /dev/null
+++ b/src/desktop/denoising.py
@@ -0,0 +1,155 @@
+"""Quality-first, lossless intermediate denoising for ordered image/video stages."""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import Callable
+
+import cv2
+import numpy as np
+import tifffile
+
+from ..core import ffmpeg
+from ..core.jobs import Cancelled, JobController
+from ..core.paths import FFMPEG
+from ..neural_rendering.image.decoder import decode_image
+from ..neural_rendering.image.encoder import _encode_image
+from ..neural_rendering.image.models import ImageConversionOptions
+from ..settings.models import UISettings
+
+
+def _filters(settings: UISettings, *, video: bool, small: bool = False) -> str:
+ """Run deblocking before NLM, so patch matching sees fewer 8×8 seams."""
+ filters = ["format=gbrp10le" if video else "format=gbrp16le"]
+ if settings.denoise_deblock and not small:
+ # Weak edge-aware deblocking avoids flattening legitimate drawn lines.
+ filters.append("deblock=filter=weak:block=8:alpha=0.05:beta=0.03:gamma=0.03:delta=0.03")
+ if settings.denoise_strength:
+ level = settings.denoise_strength
+ strength = 1.0 + 0.01 * level + 0.0014 * level * level
+ patch = 3 if small else 7
+ search = 7 if small else 21
+ filters.append(f"nlmeans=s={strength:.2f}:p={patch}:r={search}")
+ if video and settings.denoise_temporal:
+ # Adaptive temporal averaging rejects sufficiently different neighbours
+ # at moving edges and scene changes. Keep the default threshold gentle.
+ threshold_a = 0.006 + 0.00026 * settings.denoise_temporal
+ threshold_b = threshold_a * 2.0
+ window = 9 if settings.denoise_temporal > 65 else 5
+ thresholds = ":".join(
+ f"{plane}{suffix}={value:.5f}"
+ for plane in range(3)
+ for suffix, value in (("a", threshold_a), ("b", threshold_b))
+ )
+ filters.append(f"atadenoise=s={window}:{thresholds}")
+ filters.append("format=gbrp10le" if video else "format=rgb48le")
+ return ",".join(filters)
+
+
+def denoise_image(source: Path, settings: UISettings, directory: Path,
+ controller: JobController, progress: Callable,
+ run_command: Callable) -> Path:
+ if not settings.denoise_strength and not settings.denoise_deblock:
+ progress(1.0, "Denoising complete")
+ return source
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ decoded = decode_image(source)
+ height, width = decoded.rgba.shape[:2]
+ output = directory / "denoised.tiff"
+ small = min(width, height) < 16
+ original_rgb = np.ascontiguousarray(decoded.rgba[..., :3])
+ progress(0.15, "Cleaning image noise")
+ if decoded.rgba.dtype == np.uint8:
+ # OpenCV's Lab-space colored NLM keeps fine luma detail better than a
+ # single RGB strength. Equal luma/chroma settings avoid color smearing.
+ filtered_rgb = original_rgb
+ if settings.denoise_deblock and not small:
+ filtered_rgb = _ffmpeg_image_filter(
+ filtered_rgb, directory, controller, run_command,
+ "format=gbrp16le,deblock=filter=weak:block=8:alpha=0.05:beta=0.03:gamma=0.03:delta=0.03,format=rgb48le",
+ )
+ if settings.denoise_strength:
+ level = settings.denoise_strength
+ luma = 1.0 + 0.024 * level + 0.0008 * level * level
+ chroma = luma
+ bgr = cv2.cvtColor(filtered_rgb, cv2.COLOR_RGB2BGR)
+ cleaned = cv2.fastNlMeansDenoisingColored(
+ bgr, None, luma, chroma, 3 if small else 7, 7 if small else 21,
+ )
+ filtered_rgb = cv2.cvtColor(cleaned, cv2.COLOR_BGR2RGB)
+ else:
+ # The colored OpenCV variant is 8-bit only. FFmpeg's 16-bit NLM avoids
+ # reducing genuine high-depth image samples to 8-bit for this stage.
+ filtered_rgb = _ffmpeg_image_filter(
+ original_rgb, directory, controller, run_command,
+ _filters(settings, video=False, small=small),
+ )
+ rgba = decoded.rgba.copy()
+ rgba[..., :3] = filtered_rgb
+ if decoded.alpha is not None:
+ # Retain colors on nonopaque pixels so denoising cannot pull invisible
+ # background colors across a transparency boundary.
+ rgba[decoded.alpha < np.iinfo(rgba.dtype).max, :3] = decoded.rgba[
+ decoded.alpha < np.iinfo(rgba.dtype).max, :3]
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ progress(0.85, "Saving denoised image")
+ _encode_image(output, rgba,
+ ImageConversionOptions(output_format="TIFF", preserve_metadata=False),
+ {}, generate_preview=False, controller=controller,
+ has_transparency=decoded.alpha is not None)
+ progress(1.0, "Denoising complete")
+ return output
+
+
+def _ffmpeg_image_filter(rgb: np.ndarray, directory: Path,
+ controller: JobController, run_command: Callable,
+ filter_graph: str) -> np.ndarray:
+ height, width = rgb.shape[:2]
+ input_path = directory / "denoise-input.tiff"
+ filtered_path = directory / "denoise-filtered.tiff"
+ tifffile.imwrite(input_path, rgb, photometric="rgb", compression=None, metadata=None)
+ run_command(
+ [str(FFMPEG), "-hide_banner", "-loglevel", "error", "-y",
+ "-i", str(input_path), "-vf", filter_graph,
+ "-frames:v", "1", str(filtered_path)],
+ controller, "Image denoising",
+ )
+ filtered_bgr = cv2.imread(str(filtered_path), cv2.IMREAD_UNCHANGED)
+ if (filtered_bgr is None or filtered_bgr.dtype != np.uint16
+ or filtered_bgr.shape != (height, width, 3)):
+ raise RuntimeError("Image denoising returned invalid 16-bit RGB pixels.")
+ filtered_rgb = cv2.cvtColor(filtered_bgr, cv2.COLOR_BGR2RGB)
+ if rgb.dtype == np.uint8:
+ return ((filtered_rgb.astype(np.uint32) + 128) // 257).astype(np.uint8)
+ return filtered_rgb
+
+
+def denoise_video(source: Path, settings: UISettings, directory: Path,
+ controller: JobController, progress: Callable,
+ run_command: Callable) -> Path:
+ if not (settings.denoise_strength or settings.denoise_deblock or settings.denoise_temporal):
+ progress(1.0, "Denoising complete")
+ return source
+ metadata = ffmpeg.probe_video(source, count_mode="metadata", controller=controller)
+ width, height = int(metadata["width"]), int(metadata["height"])
+ color_args: list[str] = []
+ for key, flag in (("color_primaries", "-color_primaries"),
+ ("color_transfer", "-color_trc")):
+ value = metadata.get(key)
+ if value and value != "unknown":
+ color_args.extend((flag, str(value)))
+ output = directory / "denoised.mkv"
+ progress(0.1, "Cleaning video noise")
+ run_command(
+ [str(FFMPEG), "-hide_banner", "-loglevel", "error", "-y",
+ "-i", str(source), "-map", "0:v:0", "-map_metadata", "0", "-an",
+ "-vf", _filters(settings, video=True, small=min(width, height) < 16),
+ "-c:v", "ffv1", "-level", "3", "-pix_fmt", "gbrp10le",
+ "-fps_mode", "passthrough", *color_args, "-color_range", "pc",
+ str(output)],
+ controller, "Video denoising",
+ )
+ progress(1.0, "Denoising complete")
+ return output
diff --git a/src/desktop/image_provider.py b/src/desktop/image_provider.py
index 020304f..88f301a 100644
--- a/src/desktop/image_provider.py
+++ b/src/desktop/image_provider.py
@@ -159,6 +159,10 @@ class PreviewImageProvider(QQuickImageProvider):
@staticmethod
def _numpy_to_qimage(arr: np.ndarray) -> QImage:
+ if arr.dtype == np.uint16 and arr.ndim == 3 and arr.shape[2] == 4:
+ h, w, _ = arr.shape
+ contiguous = np.ascontiguousarray(arr)
+ return QImage(contiguous.data, w, h, 8 * w, QImage.Format.Format_RGBA64).copy()
if arr.ndim == 2:
h, w = arr.shape
return QImage(arr.data, w, h, w, QImage.Format.Format_Grayscale8).copy()
diff --git a/src/desktop/nis_sharpening.py b/src/desktop/nis_sharpening.py
new file mode 100644
index 0000000..5930b20
--- /dev/null
+++ b/src/desktop/nis_sharpening.py
@@ -0,0 +1,151 @@
+"""NVIDIA Image Scaling SDK 1.0.3 NVSharpen-only math for RGB media.
+
+This is a vectorized CPU port of the ``NIS_SCALER=0`` path in
+``native (dev)/NVIDIAImageScaling/NIS/NIS_Scaler.h``. It uses the SDK's
+``NVSharpenUpdateConfig`` parameters, four directional USM filters,
+edge detection and anti-ringing limiter. No NIS scaling code is used.
+"""
+
+# NVSharpen algorithm adapted from NVIDIA Image Scaling SDK 1.0.3.
+# Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
+# See NVIDIA-NIS-LICENSE.txt in this directory.
+
+from __future__ import annotations
+
+import numpy as np
+
+from ..core.jobs import Cancelled, JobController
+
+
+def _configuration(sharpness: int) -> tuple[float, float, float, float, float, float]:
+ """The SDR constants from NVScalerUpdateConfig / NVSharpenUpdateConfig."""
+ slider = sharpness / 100.0 - 0.5
+ max_scale = 1.25 if slider >= 0.0 else 1.75
+ min_scale = 1.25 if slider >= 0.0 else 1.0
+ limit_scale = 1.25 if slider >= 0.0 else 1.0
+ strength_min = max(0.0, 0.4 + slider * min_scale * 1.2)
+ strength_max = 1.6 + slider * max_scale * 1.8
+ limit_min = max(0.1, 0.14 + slider * limit_scale * 0.32)
+ limit_max = 0.5 + slider * limit_scale * 0.6
+ return (0.45, 1.0 / (0.9 - 0.45), strength_min,
+ strength_max - strength_min, limit_min, limit_max - limit_min)
+
+
+def _lti(samples: tuple[np.ndarray, ...]) -> np.ndarray:
+ a, b, c, d, e = samples
+ a_min = np.minimum(np.minimum(a, b), c)
+ a_max = np.maximum(np.maximum(a, b), c)
+ b_min = np.minimum(np.minimum(c, d), e)
+ b_max = np.maximum(np.maximum(c, d), e)
+ a_contrast = a_max - a_min
+ b_contrast = b_max - b_min
+ ratio = np.maximum(a_contrast, b_contrast) / (
+ np.minimum(a_contrast, b_contrast) + np.float32(1.0 / 255.0))
+ return 1.0 - np.clip((ratio - 2.0) / 8.0, 0.0, 1.0)
+
+
+def _directional_usm(samples: tuple[np.ndarray, ...], strength: np.ndarray,
+ limit: np.ndarray) -> np.ndarray:
+ usm = (-0.6001 * samples[1] + 1.2002 * samples[2]
+ - 0.6001 * samples[3])
+ usm = np.clip(usm * strength, -limit, limit)
+ return usm * _lti(samples)
+
+
+def _edge_weights(p: list[list[np.ndarray]]) -> tuple[np.ndarray, ...]:
+ """GetEdgeMap(p, 1, 1) from the SDK's NVSharpen path."""
+ g0 = np.abs(p[1][1] + p[1][2] + p[1][3]
+ - p[3][1] - p[3][2] - p[3][3])
+ g45 = np.abs(p[2][1] + p[1][1] + p[1][2]
+ - p[3][2] - p[3][3] - p[2][3])
+ g90 = np.abs(p[1][1] + p[2][1] + p[3][1]
+ - p[1][3] - p[2][3] - p[3][3])
+ g135 = np.abs(p[2][1] + p[3][1] + p[3][2]
+ - p[1][2] - p[1][3] - p[2][3])
+
+ axis_max = np.maximum(g0, g90)
+ axis_min = np.minimum(g0, g90)
+ diagonal_max = np.maximum(g45, g135)
+ diagonal_min = np.minimum(g45, g135)
+ total = axis_max + diagonal_max
+ axis_fraction = np.divide(axis_max, total, out=np.zeros_like(total),
+ where=total > 0)
+ diagonal_fraction = 1.0 - axis_fraction
+ detect_ratio = 2.0 * 1127.0 / 1024.0
+ threshold = 64.0 / 1024.0
+ axis_detected = ((axis_max > axis_min * detect_ratio) &
+ (axis_max > threshold) & (axis_max > diagonal_min))
+ diagonal_detected = ((diagonal_max > diagonal_min * detect_ratio) &
+ (diagonal_max > threshold) & (diagonal_max > axis_min))
+ both = axis_detected & diagonal_detected
+ axis_factor = np.where(both, axis_fraction, 1.0)
+ diagonal_factor = np.where(both, diagonal_fraction, 1.0)
+ return (np.where(axis_detected & (g0 >= g90), axis_factor, 0.0),
+ np.where(axis_detected & (g0 < g90), axis_factor, 0.0),
+ np.where(diagonal_detected & (g45 >= g135), diagonal_factor, 0.0),
+ np.where(diagonal_detected & (g45 < g135), diagonal_factor, 0.0))
+
+
+def sharpen_rgb(pixels: np.ndarray, sharpness: int, *,
+ alpha: np.ndarray | None = None,
+ controller: JobController | None = None) -> np.ndarray:
+ """Apply SDK NVSharpen without resizing 8/16-bit display-referred RGB."""
+ if pixels.ndim != 3 or pixels.shape[2] != 3 or pixels.dtype not in (np.uint8, np.uint16):
+ raise ValueError("NIS requires an 8-bit or 16-bit RGB image.")
+ if isinstance(sharpness, bool) or not isinstance(sharpness, int) or not 0 <= sharpness <= 100:
+ raise ValueError("NIS sharpness must be an integer from 0 to 100.")
+ if alpha is not None and (alpha.shape != pixels.shape[:2] or alpha.dtype != pixels.dtype):
+ raise ValueError("NIS alpha must match the RGB pixels.")
+ if sharpness == 0 or min(pixels.shape[:2]) < 2:
+ return pixels.copy()
+
+ height, width = pixels.shape[:2]
+ maximum = float(np.iinfo(pixels.dtype).max)
+ start_y, scale_y, strength_min, strength_scale, limit_min, limit_scale = _configuration(sharpness)
+ result = np.empty_like(pixels)
+ tile = 256
+ for y in range(0, height, tile):
+ for x in range(0, width, tile):
+ if controller is not None and controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ bottom, right = min(height, y + tile), min(width, x + tile)
+ tile_height, tile_width = bottom - y, right - x
+ y0, y1 = max(0, y - 2), min(height, bottom + 2)
+ x0, x1 = max(0, x - 2), min(width, right + 2)
+ border = ((max(0, 2 - y), max(0, bottom + 2 - height)),
+ (max(0, 2 - x), max(0, right + 2 - width)))
+ block = np.pad(pixels[y0:y1, x0:x1], (*border, (0, 0)), mode="edge")
+ block = block.astype(np.float32) / maximum
+ luma = (np.float32(0.2126) * block[..., 0]
+ + np.float32(0.7152) * block[..., 1]
+ + np.float32(0.0722) * block[..., 2])
+ p = [[luma[i:i + tile_height, j:j + tile_width]
+ for j in range(5)] for i in range(5)]
+
+ scale = 1.0 - np.clip((p[2][2] - start_y) * scale_y, 0.0, 1.0)
+ strength = scale * strength_scale + strength_min
+ limit = (scale * limit_scale + limit_min) * p[2][2]
+ directions = (
+ (p[0][2], p[1][2], p[2][2], p[3][2], p[4][2]),
+ (p[2][0], p[2][1], p[2][2], p[2][3], p[2][4]),
+ (p[1][1], 0.5 * (p[2][1] + p[1][2]), p[2][2],
+ 0.5 * (p[3][2] + p[2][3]), p[3][3]),
+ (p[3][1], 0.5 * (p[3][2] + p[2][1]), p[2][2],
+ 0.5 * (p[2][3] + p[1][2]), p[1][3]),
+ )
+ weights = _edge_weights(p)
+ usm = np.zeros_like(p[2][2])
+ for samples, weight in zip(directions, weights):
+ usm += _directional_usm(samples, strength, limit) * weight
+
+ center = block[2:-2, 2:-2]
+ if alpha is not None:
+ a = np.pad(alpha[y0:y1, x0:x1], border, mode="edge")
+ opaque = np.ones((tile_height, tile_width), dtype=bool)
+ for dy in range(5):
+ for dx in range(5):
+ opaque &= a[dy:dy + tile_height, dx:dx + tile_width] == maximum
+ usm = np.where(opaque, usm, 0.0)
+ sharpened = np.clip(center + usm[..., None], 0.0, 1.0)
+ result[y:bottom, x:right] = np.rint(sharpened * maximum).astype(pixels.dtype)
+ return result
diff --git a/src/desktop/preview_cache.py b/src/desktop/preview_cache.py
new file mode 100644
index 0000000..4692329
--- /dev/null
+++ b/src/desktop/preview_cache.py
@@ -0,0 +1,135 @@
+"""Persistent, lossless intermediate files for Neural Rendering previews.
+
+Keys describe the source and every processing card before the cached output.
+Each entry is a directory containing a completed artifact and a small JSON
+manifest. Rendering happens in the normal job directory; a completed directory
+is moved into the cache, so cancellation never exposes a partial result.
+"""
+
+from __future__ import annotations
+
+import hashlib
+import json
+import os
+import shutil
+import tempfile
+import threading
+from pathlib import Path
+from typing import Any
+
+from ..core.paths import PREVIEW_CACHE
+
+
+CACHE_SCHEMA = 1
+_LOCK = threading.RLock()
+
+
+def file_identity(path: str | Path) -> dict[str, Any]:
+ """Cheap identity for large media and external settings files."""
+ resolved = Path(path).resolve()
+ stat = resolved.stat()
+ return {
+ "path": os.path.normcase(str(resolved)),
+ "size": stat.st_size,
+ "mtime_ns": stat.st_mtime_ns,
+ "ctime_ns": stat.st_ctime_ns,
+ "device": stat.st_dev,
+ "inode": stat.st_ino,
+ }
+
+
+def optional_file_identity(path: str | Path) -> dict[str, Any] | None:
+ try:
+ return file_identity(path)
+ except OSError:
+ return None
+
+
+def cache_key(payload: dict[str, Any]) -> str:
+ serialized = json.dumps({"schema": CACHE_SCHEMA, **payload}, sort_keys=True,
+ separators=(",", ":"), ensure_ascii=False, allow_nan=False)
+ return hashlib.sha256(serialized.encode("utf-8")).hexdigest()
+
+
+class PreviewStageCache:
+ def __init__(self, root: Path = PREVIEW_CACHE) -> None:
+ self.root = Path(root)
+ self.used_keys: set[str] = set()
+ try:
+ self.root.mkdir(parents=True, exist_ok=True)
+ except OSError:
+ pass
+
+ def _entry(self, key: str) -> Path:
+ return self.root / key
+
+ def lookup(self, key: str, previous: Path | None = None) -> Path | None:
+ entry = self._entry(key)
+ with _LOCK:
+ try:
+ manifest = json.loads((entry / "manifest.json").read_text(encoding="utf-8"))
+ if manifest.get("schema") != CACHE_SCHEMA or manifest.get("key") != key:
+ return None
+ if manifest.get("alias") is True:
+ if previous is None or not previous.is_file():
+ return None
+ result = previous
+ else:
+ name = manifest.get("artifact")
+ if not isinstance(name, str) or not name or Path(name).name != name:
+ return None
+ result = entry / name
+ if not result.is_file() or result.stat().st_size != manifest.get("size"):
+ return None
+ os.utime(entry, None)
+ self.used_keys.add(key)
+ return result
+ except (OSError, ValueError, TypeError, KeyError):
+ return None
+
+ def publish(self, key: str, directory: Path, result: Path,
+ previous: Path | None = None) -> Path:
+ """Publish one finished stage without copying potentially huge video."""
+ try:
+ alias = previous is not None and result.resolve() == previous.resolve()
+ if alias:
+ artifact = None
+ size = 0
+ else:
+ if not result.is_file() or result.stat().st_size <= 0:
+ return result
+ if result.parent.resolve() != directory.resolve():
+ return result
+ artifact = result.name
+ size = result.stat().st_size
+ manifest = {"schema": CACHE_SCHEMA, "key": key, "alias": alias,
+ "artifact": artifact, "size": size}
+ (directory / "manifest.json").write_text(
+ json.dumps(manifest, sort_keys=True, separators=(",", ":")), encoding="utf-8")
+ with _LOCK:
+ self.root.mkdir(parents=True, exist_ok=True)
+ existing = self.lookup(key, previous)
+ if existing is not None:
+ return existing
+ entry = self._entry(key)
+ if entry.exists():
+ shutil.rmtree(entry)
+ try:
+ directory.rename(entry)
+ except OSError:
+ # Test/custom cache locations can be on another volume.
+ # Copy into the destination volume, then rename there.
+ incoming = Path(tempfile.mkdtemp(prefix=".incoming-", dir=self.root))
+ try:
+ shutil.copytree(directory, incoming, dirs_exist_ok=True)
+ incoming.rename(entry)
+ finally:
+ if incoming.exists():
+ shutil.rmtree(incoming, ignore_errors=True)
+ os.utime(entry, None)
+ self.used_keys.add(key)
+ return previous if alias else entry / artifact
+ except OSError:
+ # Cache storage is optional; the completed job file still feeds the
+ # remainder of this preview when the disk/cache is unavailable.
+ return result
diff --git a/src/desktop/qml/Main.qml b/src/desktop/qml/Main.qml
index bf724e4..510ff2a 100644
--- a/src/desktop/qml/Main.qml
+++ b/src/desktop/qml/Main.qml
@@ -99,7 +99,7 @@ Window {
// disabled Shortcut never consumes the key — TextInput keeps native
// Ctrl+V / Delete / Space behavior while editing.
readonly property bool isTextEditing: activeFocusItem instanceof TextInput || activeFocusItem instanceof TextEdit
- readonly property bool isBatchTab: typeof backend !== "undefined" && backend ? (backend.activeTab === "neural-rendering" || backend.activeTab === "upscale" || backend.activeTab === "frame-interpolation") : false
+ readonly property bool isBatchTab: typeof backend !== "undefined" && backend ? backend.activeTab === "neural-rendering" : false
readonly property bool isLiveTab: typeof backend !== "undefined" && backend ? backend.activeTab === "live" : false
// True when keyboard focus sits on any tab-focusable control (custom
// AppButton/Switch/CheckBox/ComboBox/Slider/IconButton expose
@@ -171,16 +171,12 @@ Window {
if (typeof backend === "undefined" || !backend) return 0
var tab = backend.activeTab
if (tab === "neural-rendering") return 0
- if (tab === "upscale") return 1
- if (tab === "frame-interpolation") return 2
- if (tab === "live") return 3
- if (tab === "settings") return 4
- if (tab === "help") return 5
+ if (tab === "live") return 1
+ if (tab === "settings") return 2
+ if (tab === "help") return 3
return 0
}
NeuralRenderingView { appBridge: typeof backend !== "undefined" ? backend : null }
- UpscaleView { appBridge: typeof backend !== "undefined" ? backend : null }
- FrameInterpolationView { appBridge: typeof backend !== "undefined" ? backend : null }
LiveView { appBridge: typeof backend !== "undefined" ? backend : null }
SettingsView { appBridge: typeof backend !== "undefined" ? backend : null }
AboutView { appBridge: typeof backend !== "undefined" ? backend : null }
diff --git a/src/desktop/qml/components/ColoringControls.qml b/src/desktop/qml/components/ColoringControls.qml
new file mode 100644
index 0000000..8f2aba4
--- /dev/null
+++ b/src/desktop/qml/components/ColoringControls.qml
@@ -0,0 +1,216 @@
+import QtQuick
+import QtQuick.Dialogs
+import ".."
+import "../controls"
+
+Column {
+ id: root
+ property var appBridge: null
+ property string lutPanel: "Color Adjustment"
+ readonly property bool isImage: appBridge ? appBridge.nrMode === "Image" : true
+ width: parent ? parent.width : 320
+ spacing: 12
+
+ AppComboBox {
+ width: parent.width
+ label: "Method"
+ model: root.isImage ? (appBridge ? appBridge.coloringModeChoices : [])
+ : [{label: "Apply LUT", value: "LUT"}]
+ currentValue: root.isImage ? (appBridge ? appBridge.coloringMode : "Color Match") : "LUT"
+ onActivated: value => {
+ if (value === "LUT") root.lutPanel = "Color Adjustment"
+ if (appBridge && root.isImage) appBridge.coloringMode = value
+ }
+ }
+
+ Column {
+ width: parent.width
+ spacing: 12
+ visible: root.isImage && appBridge && appBridge.coloringMode === "Color Match"
+
+ AppComboBox {
+ width: parent.width
+ label: "Match Colors From"
+ model: appBridge ? appBridge.colorMatchSourceChoices : []
+ currentValue: appBridge ? appBridge.colorMatchSource : "Input Image"
+ onActivated: value => { if (appBridge) appBridge.colorMatchSource = value }
+ }
+
+ AppFilePicker {
+ width: parent.width
+ visible: appBridge && appBridge.colorMatchSource === "Selected Image"
+ label: "Selected Reference Image"
+ placeholderText: "Choose a reference image"
+ selectedPath: appBridge ? appBridge.colorMatchReference : ""
+ nameFilters: ["Images (*.png *.jpg *.jpeg *.webp *.tif *.tiff *.bmp *.avif *.heic *.heif *.svg *.dng *.cr2 *.nef *.arw)",
+ "All Files (*.*)"]
+ onPathChanged: path => {
+ if (appBridge) appBridge.setColorMatchReference(path)
+ Qt.callLater(syncPath)
+ }
+ }
+ }
+
+ Column {
+ width: parent.width
+ visible: !root.isImage || (appBridge && appBridge.coloringMode === "LUT")
+ spacing: 12
+
+ AppSegmentedControl {
+ width: parent.width
+ model: ["Color Adjustment", "LUT File"]
+ currentValue: root.lutPanel
+ onActivated: value => { root.lutPanel = value }
+ }
+
+ AppFilePicker {
+ width: parent.width
+ visible: root.lutPanel === "LUT File"
+ label: "LUT File (.cube)"
+ placeholderText: "Choose a 3D .cube LUT"
+ selectedPath: appBridge ? appBridge.lutFile : ""
+ nameFilters: ["3D LUT Files (*.cube)", "All Files (*.*)"]
+ onPathChanged: path => {
+ if (appBridge) appBridge.setLutFile(path)
+ Qt.callLater(syncPath)
+ }
+ }
+
+ Column {
+ width: parent.width
+ spacing: 12
+ visible: root.lutPanel === "Color Adjustment"
+
+ Item {
+ width: parent.width
+ height: resolutionControl.implicitHeight
+
+ AppComboBox {
+ id: resolutionControl
+ objectName: "coloring-lut-resolution"
+ width: parent.width - resetButton.width - 8
+ height: implicitHeight
+ anchors.left: parent.left
+ label: "LUT Resolution"
+ model: appBridge ? appBridge.lutResolutionChoices : []
+ currentValue: appBridge ? appBridge.lutResolution : 33
+ onActivated: value => { if (appBridge) appBridge.lutResolution = value }
+ }
+
+ AppButton {
+ id: resetButton
+ objectName: "coloring-reset-adjustments"
+ width: 92
+ anchors.right: parent.right
+ anchors.bottom: parent.bottom
+ text: "Reset"
+ iconName: "reset"
+ onClicked: { if (appBridge) appBridge.resetLutAdjustments() }
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "LUT Strength"
+ from: 0; to: 200; stepSize: 1; precision: 0; defaultValue: 100; unit: "%"
+ value: appBridge ? appBridge.lutAdjustmentValues.lut_mix : 100
+ onValueModified: v => { if (appBridge) appBridge.setLutAdjustment("lut_mix", v) }
+ }
+
+ AppButton {
+ objectName: "coloring-auto-adjustments"
+ width: parent.width
+ text: appBridge && appBridge.lutAutoBusy ? "Analyzing…" : "Auto"
+ iconName: "quality_enhance"
+ enabled: appBridge && !!appBridge.previewInputUrl
+ && appBridge.canModifyQueue && !appBridge.lutAutoBusy
+ onClicked: { if (appBridge) appBridge.autoAdjustLut() }
+ }
+
+ Text {
+ text: "Light"
+ font.family: Theme.fontFamily
+ font.pixelSize: Theme.fontSizeLabel
+ font.weight: Font.DemiBold
+ color: Theme.textPrimary
+ }
+
+ Repeater {
+ model: [
+ {key: "lut_exposure", label: "Exposure", from: -3, to: 3, step: 0.05, precision: 2, unit: "EV"},
+ {key: "lut_contrast", label: "Contrast", from: -100, to: 100, step: 1, precision: 0, unit: "%"},
+ {key: "lut_highlights", label: "Highlights", from: -100, to: 100, step: 1, precision: 0, unit: "%"},
+ {key: "lut_shadows", label: "Shadows", from: -100, to: 100, step: 1, precision: 0, unit: "%"},
+ {key: "lut_whites", label: "Whites", from: -100, to: 100, step: 1, precision: 0, unit: "%"},
+ {key: "lut_blacks", label: "Blacks", from: -100, to: 100, step: 1, precision: 0, unit: "%"},
+ {key: "lut_midtones", label: "Midtones", from: -100, to: 100, step: 1, precision: 0, unit: "%"}
+ ]
+ delegate: AppSlider {
+ required property var modelData
+ width: root.width
+ label: modelData.label
+ from: modelData.from; to: modelData.to; stepSize: modelData.step
+ precision: modelData.precision; unit: modelData.unit; defaultValue: 0
+ value: appBridge ? appBridge.lutAdjustmentValues[modelData.key] : 0
+ onValueModified: v => { if (appBridge) appBridge.setLutAdjustment(modelData.key, v) }
+ }
+ }
+
+ Text {
+ text: "Color"
+ font.family: Theme.fontFamily
+ font.pixelSize: Theme.fontSizeLabel
+ font.weight: Font.DemiBold
+ color: Theme.textPrimary
+ }
+
+ Repeater {
+ model: [
+ {key: "lut_temperature", label: "Temperature", from: -100, to: 100, unit: ""},
+ {key: "lut_tint", label: "Tint", from: -100, to: 100, unit: ""},
+ {key: "lut_hue", label: "Hue Shift", from: -180, to: 180, unit: "°"},
+ {key: "lut_vibrance", label: "Vibrance", from: -100, to: 100, unit: "%"},
+ {key: "lut_saturation", label: "Saturation", from: -100, to: 100, unit: "%"}
+ ]
+ delegate: AppSlider {
+ required property var modelData
+ width: root.width
+ label: modelData.label
+ from: modelData.from; to: modelData.to; stepSize: 1
+ precision: 0; unit: modelData.unit; defaultValue: 0
+ value: appBridge ? appBridge.lutAdjustmentValues[modelData.key] : 0
+ onValueModified: v => { if (appBridge) appBridge.setLutAdjustment(modelData.key, v) }
+ }
+ }
+ }
+
+ AppButton {
+ width: parent.width
+ text: appBridge && appBridge.lutSaveBusy ? "Saving LUT…" : "Save LUT"
+ iconName: "export"
+ variant: "primary"
+ enabled: appBridge && !appBridge.lutSaveBusy
+ && (root.lutPanel === "Color Adjustment" || !!appBridge.lutFile)
+ onClicked: lutSaveDialog.open()
+ }
+
+ Text {
+ width: parent.width
+ visible: appBridge && appBridge.lutSaveStatus !== ""
+ text: appBridge ? appBridge.lutSaveStatus : ""
+ wrapMode: Text.WordWrap
+ font.family: Theme.fontFamily
+ font.pixelSize: Theme.fontSizeSmall
+ color: Theme.textSecondary
+ }
+ }
+
+ FileDialog {
+ id: lutSaveDialog
+ title: "Save Graded 3D LUT"
+ fileMode: FileDialog.SaveFile
+ defaultSuffix: "cube"
+ nameFilters: ["3D LUT Files (*.cube)"]
+ onAccepted: { if (appBridge && selectedFile) appBridge.saveLut(selectedFile.toString()) }
+ }
+}
diff --git a/src/desktop/qml/components/DenoisingControls.qml b/src/desktop/qml/components/DenoisingControls.qml
new file mode 100644
index 0000000..949ef0e
--- /dev/null
+++ b/src/desktop/qml/components/DenoisingControls.qml
@@ -0,0 +1,37 @@
+import QtQuick
+import "../controls"
+
+Column {
+ id: root
+ property var appBridge: null
+ readonly property bool isImage: appBridge ? appBridge.nrMode === "Image" : true
+ width: parent ? parent.width : 320
+ spacing: 12
+
+ AppSlider {
+ objectName: "denoising-strength"
+ width: parent.width
+ label: "Noise Reduction"
+ from: 0; to: 100; stepSize: 1; precision: 0; defaultValue: 50; unit: "%"
+ value: root.appBridge ? root.appBridge.denoiseStrength : 50
+ onValueModified: v => { if (root.appBridge) root.appBridge.denoiseStrength = Math.round(v) }
+ }
+
+ AppCheckBox {
+ objectName: "denoising-deblock"
+ label: "Compression Artifact Cleanup"
+ checked: root.appBridge ? root.appBridge.denoiseDeblock : true
+ onToggled: v => { if (root.appBridge) root.appBridge.denoiseDeblock = v }
+ }
+
+ AppSlider {
+ objectName: "denoising-temporal"
+ visible: !root.isImage
+ width: parent.width
+ label: "Temporal Noise Reduction"
+ from: 0; to: 100; stepSize: 1; precision: 0; defaultValue: 30; unit: "%"
+ value: root.appBridge ? root.appBridge.denoiseTemporal : 30
+ onValueModified: v => { if (root.appBridge) root.appBridge.denoiseTemporal = Math.round(v) }
+ }
+
+}
diff --git a/src/desktop/qml/components/DlssSuperResolutionControls.qml b/src/desktop/qml/components/DlssSuperResolutionControls.qml
new file mode 100644
index 0000000..de539da
--- /dev/null
+++ b/src/desktop/qml/components/DlssSuperResolutionControls.qml
@@ -0,0 +1,43 @@
+import QtQuick
+import ".."
+import "../controls"
+
+Column {
+ id: root
+ property var appBridge: null
+ readonly property bool isImage: appBridge ? appBridge.nrMode === "Image" : true
+ width: parent ? parent.width : 320
+ spacing: 12
+
+ AppComboBox {
+ width: parent.width
+ label: "DLSS Mode"
+ model: appBridge ? appBridge.dlssModeChoices : []
+ currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageDlssMode : "Quality")
+ : (appBridge ? appBridge.upscaleDlssMode : "Quality")
+ onActivated: v => {
+ if (appBridge) {
+ if (root.isImage)
+ appBridge.upscaleImageDlssMode = v;
+ else
+ appBridge.upscaleDlssMode = v;
+ }
+ }
+ }
+
+ AppComboBox {
+ width: parent.width
+ label: "DLSS Preset"
+ model: appBridge ? appBridge.dlssPresetChoices : []
+ currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageDlssPreset : "Default")
+ : (appBridge ? appBridge.upscaleDlssPreset : "Default")
+ onActivated: v => {
+ if (appBridge) {
+ if (root.isImage)
+ appBridge.upscaleImageDlssPreset = v;
+ else
+ appBridge.upscaleDlssPreset = v;
+ }
+ }
+ }
+}
diff --git a/src/desktop/qml/components/ExportDialog.qml b/src/desktop/qml/components/ExportDialog.qml
index 616cdc0..9ad59a2 100644
--- a/src/desktop/qml/components/ExportDialog.qml
+++ b/src/desktop/qml/components/ExportDialog.qml
@@ -17,8 +17,8 @@ QQC2.Dialog {
function openForContext(key) {
if (!appBridge) return
contextKey = key
- destinationMode = "output"
- selectedFolder = ""
+ destinationMode = appBridge.exportDestinationMode ? appBridge.exportDestinationMode : "output"
+ selectedFolder = appBridge.exportFolder || ""
errorMessage = ""
if (key === "nr-image") {
renameMode = appBridge.imageRenameMode
diff --git a/src/desktop/qml/components/ExportSettingsControls.qml b/src/desktop/qml/components/ExportSettingsControls.qml
new file mode 100644
index 0000000..0e2e4fe
--- /dev/null
+++ b/src/desktop/qml/components/ExportSettingsControls.qml
@@ -0,0 +1,112 @@
+import QtQuick
+import ".."
+import "../controls"
+
+Column {
+ id: root
+ property var appBridge: null
+ readonly property bool isImage: appBridge ? appBridge.nrMode === "Image" : true
+ width: parent ? parent.width : 320
+ spacing: 12
+
+ Column {
+ visible: root.isImage
+ width: parent.width
+ spacing: 12
+ AppComboBox {
+ width: parent.width
+ label: "Output Format"
+ model: appBridge ? appBridge.imageFormatChoices : []
+ currentValue: appBridge ? appBridge.imageFormat : "PNG"
+ onActivated: v => {
+ if (appBridge)
+ appBridge.imageFormat = v;
+ }
+ }
+ AppComboBox {
+ objectName: "imageBitDepthSelector"
+ width: parent.width
+ label: "Bit Depth"
+ model: appBridge && ["PNG", "TIFF"].indexOf(appBridge.imageFormat) >= 0
+ ? [{label: "8 Bit", value: 8}, {label: "16 Bit", value: 16}]
+ : [{label: "8 Bit", value: 8}]
+ currentValue: appBridge ? appBridge.imageBitDepth : 8
+ onActivated: v => {
+ if (appBridge)
+ appBridge.imageBitDepth = v;
+ }
+ }
+ AppSlider {
+ visible: appBridge && ["JPEG", "WebP", "AVIF"].indexOf(appBridge.imageFormat) >= 0
+ width: parent.width
+ label: "Image Quality"
+ from: 1
+ to: 100
+ stepSize: 1
+ precision: 0
+ defaultValue: 95
+ value: appBridge ? appBridge.imageQuality : 95
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.imageQuality = Math.round(v);
+ }
+ }
+ }
+
+ Column {
+ visible: !root.isImage
+ width: parent.width
+ spacing: 12
+ AppComboBox {
+ width: parent.width
+ label: "Video Codec"
+ model: appBridge ? appBridge.codecChoices : []
+ currentValue: appBridge ? appBridge.videoCodec : "H.264 (NVIDIA NVENC)"
+ onActivated: v => {
+ if (appBridge)
+ appBridge.videoCodec = v;
+ }
+ }
+ AppComboBox {
+ width: parent.width
+ label: "Container (automatic)"
+ model: appBridge ? appBridge.containerChoices : []
+ currentValue: appBridge ? appBridge.videoContainer : "MP4"
+ enabled: false
+ }
+ AppComboBox {
+ width: parent.width
+ label: "Encoding Quality"
+ visible: !appBridge || appBridge.fixedQualityCodecs.indexOf(appBridge.videoCodec) < 0
+ model: appBridge ? appBridge.encodingQualityChoices : []
+ currentValue: appBridge ? appBridge.videoQuality : "Auto (Default)"
+ onActivated: v => {
+ if (appBridge)
+ appBridge.videoQuality = v;
+ }
+ }
+ Text {
+ visible: appBridge && appBridge.fixedQualityCodecs.indexOf(appBridge.videoCodec) >= 0
+ text: "Encoding Quality: Fixed by codec"
+ color: Theme.textSecondary
+ font.pixelSize: Theme.fontSizeSmall
+ }
+ AppCheckBox {
+ label: "Preserve / Export 10-bit HDR"
+ checked: appBridge ? appBridge.videoHdrMode : false
+ enabled: appBridge ? appBridge.videoHdrSupported : false
+ onToggled: v => {
+ if (appBridge)
+ appBridge.videoHdrMode = v;
+ }
+ }
+ Text {
+ visible: appBridge && appBridge.renderValidationMessage !== ""
+ width: parent.width
+ wrapMode: Text.Wrap
+ text: appBridge ? appBridge.renderValidationMessage : ""
+ color: Theme.danger
+ font.pixelSize: Theme.fontSizeSmall
+ }
+ }
+}
diff --git a/src/desktop/qml/components/FrameGenerationControls.qml b/src/desktop/qml/components/FrameGenerationControls.qml
new file mode 100644
index 0000000..84bba59
--- /dev/null
+++ b/src/desktop/qml/components/FrameGenerationControls.qml
@@ -0,0 +1,42 @@
+import QtQuick
+import QtQuick.Dialogs
+import ".."
+import "../controls"
+
+Column {
+ id: root
+ property var appBridge: null
+ readonly property bool isImage: appBridge ? appBridge.nrMode === "Image" : true
+ width: parent ? parent.width : 320
+ spacing: 12
+ AppComboBox {
+ width: parent.width
+ label: "Target Output Frame Rate"
+ model: appBridge ? appBridge.fiFpsChoices : []
+ currentValue: appBridge ? appBridge.fiTargetFps : "60"
+ onActivated: v => {
+ if (appBridge)
+ appBridge.fiTargetFps = v;
+ }
+ }
+
+ AppSegmentedControl {
+ width: parent.width
+ label: "DLSS-G Engine"
+ model: appBridge ? appBridge.fiEngineChoices : []
+ currentValue: appBridge ? appBridge.fiEngine : "Auto"
+ onActivated: v => {
+ if (appBridge)
+ appBridge.fiEngine = v;
+ }
+ }
+
+ Text {
+ width: parent.width
+ text: appBridge ? appBridge.outputEstimate : ""
+ wrapMode: Text.Wrap
+ font.family: Theme.monoFontFamily
+ font.pixelSize: Theme.fontSizeSmall
+ color: Theme.textMuted
+ }
+}
diff --git a/src/desktop/qml/components/HeaderBar.qml b/src/desktop/qml/components/HeaderBar.qml
index 46f5df2..76e21b9 100644
--- a/src/desktop/qml/components/HeaderBar.qml
+++ b/src/desktop/qml/components/HeaderBar.qml
@@ -127,8 +127,6 @@ Rectangle {
spacing: 4
readonly property var tabs: [
{ id:"neural-rendering", full:"Neural Rendering", short:"Neural", icon:"neural_rendering" },
- { id:"upscale", full:"Upscale", short:"Upscale", icon:"upscale" },
- { id:"frame-interpolation", full:"Frame Interpolation", short:"Interp", icon:"frame_interpolation" },
{ id:"live", full:"Live", short:"Live", icon:"live_video" },
{ id:"settings", full:"Settings", short:"Settings", icon:"settings" },
{ id:"help", full:"Help", short:"Help", icon:"help" }
diff --git a/src/desktop/qml/components/MediaViewport.qml b/src/desktop/qml/components/MediaViewport.qml
index 5d74770..2ec8fb2 100644
--- a/src/desktop/qml/components/MediaViewport.qml
+++ b/src/desktop/qml/components/MediaViewport.qml
@@ -7,8 +7,10 @@ import "../controls"
Rectangle {
id: viewport
+ objectName: "mediaViewport"
property var appBridge: null
property string viewMode: "split"
+ property bool originalPeekHeld: false
property real zoomFactor: 1.0
property real panX: 0
property real panY: 0
@@ -32,22 +34,28 @@ Rectangle {
readonly property bool hasInput: appBridge ? appBridge.previewInputUrl !== "" : false
readonly property bool hasOutput: appBridge ? appBridge.hasOutputPreview : false
readonly property bool isVideo: appBridge ? (appBridge.previewInputIsVideo || appBridge.previewOutputIsVideo) : false
- readonly property bool showingOutput: viewport.showVideoOutput && viewport.hasOutput && appBridge && appBridge.previewOutputIsVideo
- readonly property bool showingTwoUp: viewport.videoTwoUp && viewport.isVideo && viewport.hasOutput && appBridge && appBridge.previewOutputIsVideo
+ readonly property bool hasStillVideoOutput: viewport.isVideo && viewport.hasOutput && appBridge && !appBridge.previewOutputIsVideo
+ readonly property bool showingOutput: viewport.showVideoOutput && viewport.isVideo && viewport.hasOutput
+ // Keep the chosen comparison layout while an invalidated video preview
+ // is replaced. The output pane can show its loading state meanwhile.
+ readonly property bool showingTwoUp: viewport.videoTwoUp && viewport.isVideo
// Output mirror gate: input masters the timeline in every layout while a
// video preview exists; the output pane follows clamped to its duration.
readonly property bool mirrorOutput: viewport.isVideo && viewport.hasOutput && appBridge && appBridge.previewOutputIsVideo
- // Scrub-realtime eligibility: Realtime on + an existing video preview, in
+ // Scrub-realtime eligibility: Realtime on + an existing preview, in
// any layout. The transport always masters the input timeline (even on
// the Output tab), so every scrub addresses input frames and refreshes
// the preview at the settled playhead. The Preview button stays the
- // manual render path. Frame Interpolation and a rendered Upscale clip
- // use green timeline spans, so scrubbing those clips never starts a
- // one-frame realtime render over the processed range.
+ // manual render path. Frame Interpolation, a rendered Upscale clip, and
+ // a rendered Neural Rendering clip use green timeline spans, so
+ // scrubbing those clips never starts a one-frame realtime render over
+ // the processed range.
readonly property bool isFITab: appBridge && appBridge.activeTab === "frame-interpolation"
readonly property var renderedPreviewRanges: appBridge ? appBridge.previewRenderedRanges : []
- readonly property bool hasRangePlayback: viewport.isFITab || (appBridge && appBridge.activeTab === "upscale" && appBridge.upscaleMode === "Video" && viewport.renderedPreviewRanges.length > 0)
- readonly property bool scrubRefreshEligible: appBridge && appBridge.autoPreviewEnabled && !viewport.hasRangePlayback && viewport.hasOutput && appBridge.previewOutputIsVideo
+ readonly property bool isNRVideoTab: appBridge && appBridge.activeTab === "neural-rendering"
+ && appBridge.nrMode === "Video" && viewport.renderedPreviewRanges.length > 0
+ readonly property bool hasRangePlayback: viewport.isFITab || viewport.isNRVideoTab || (appBridge && appBridge.activeTab === "upscale" && appBridge.upscaleMode === "Video" && viewport.renderedPreviewRanges.length > 0)
+ readonly property bool scrubRefreshEligible: appBridge && appBridge.autoPreviewEnabled && !viewport.hasRangePlayback && viewport.isVideo && viewport.hasOutput
// Pre-rendered span containing timeline second sec, newest first wins
// so re-rendered spans resolve to the latest clip. Null when outside all
// green spans (or when ranges are unavailable).
@@ -89,16 +97,20 @@ Rectangle {
if (viewport.fiPinned && viewport.fiPinned.url) return viewport.fiPinned.url
return appBridge.previewInputIsVideo ? appBridge.previewInputUrl : ""
}
- readonly property var activePlayer: showingOutput ? outputPlayer : inputPlayer
+ readonly property var activePlayer: showingOutput && !hasStillVideoOutput ? outputPlayer : inputPlayer
readonly property real playheadMs: viewport.isVideo ? inputPlayer.position : (activePlayer ? activePlayer.position : 0)
readonly property real inputDurationMs: appBridge ? appBridge.sourceDuration * 1000.0 : 0
readonly property real inputFps: appBridge && appBridge.sourceFps > 0 ? appBridge.sourceFps : 30.0
readonly property bool inputReady: inputPlayer.duration > 0 && (inputPlayer.mediaStatus === MediaPlayer.LoadedMedia || inputPlayer.mediaStatus === MediaPlayer.BufferedMedia)
- readonly property bool outputReady: outputPlayer.duration > 0 && (outputPlayer.mediaStatus === MediaPlayer.LoadedMedia || outputPlayer.mediaStatus === MediaPlayer.BufferedMedia)
- readonly property bool activeReady: showingOutput ? outputReady : inputReady
+ readonly property bool outputReady: viewport.hasOutput && (hasStillVideoOutput || (outputPlayer.duration > 0 && (outputPlayer.mediaStatus === MediaPlayer.LoadedMedia || outputPlayer.mediaStatus === MediaPlayer.BufferedMedia)))
+ readonly property bool activeReady: showingOutput && !hasStillVideoOutput ? outputReady : inputReady
readonly property int sourceWidth: appBridge && appBridge.sourceWidth > 0 ? appBridge.sourceWidth : 1
readonly property int sourceHeight: appBridge && appBridge.sourceHeight > 0 ? appBridge.sourceHeight : 1
- readonly property real fitScale: Math.max(0.0001, Math.min(canvas.width / sourceWidth, canvas.height / sourceHeight))
+ readonly property bool twoUpLayout: showingTwoUp || (!isVideo && viewMode === "sideBySide")
+ readonly property real comparisonPaneWidth: Math.max(1, (canvas.width - 4) / 2)
+ readonly property real fitWidth: Math.max(1, twoUpLayout ? comparisonPaneWidth - (isVideo ? 0 : 8) : canvas.width)
+ readonly property real fitHeight: Math.max(1, twoUpLayout && !isVideo ? canvas.height - 8 : canvas.height)
+ readonly property real fitScale: Math.max(0.0001, Math.min(fitWidth / sourceWidth, fitHeight / sourceHeight))
readonly property real displayScale: fitScale * zoomFactor
function resetPan() { panX = 0; panY = 0 }
@@ -109,8 +121,8 @@ Rectangle {
resetPan()
}
function clampPan() {
- var overX = Math.max(0, sourceWidth * displayScale - canvas.width) / 2
- var overY = Math.max(0, sourceHeight * displayScale - canvas.height) / 2
+ var overX = Math.max(0, sourceWidth * displayScale - fitWidth) / 2
+ var overY = Math.max(0, sourceHeight * displayScale - fitHeight) / 2
panX = Math.max(-overX, Math.min(overX, panX))
panY = Math.max(-overY, Math.min(overY, panY))
}
@@ -121,6 +133,12 @@ Rectangle {
onSourceWidthChanged: fitToWindow()
onSourceHeightChanged: fitToWindow()
+ onFitScaleChanged: Qt.callLater(clampPan)
+ onViewModeChanged: originalPeekHeld = false
+ onHasOutputChanged: { if (!hasOutput) originalPeekHeld = false }
+ onIsVideoChanged: originalPeekHeld = false
+ onActiveFocusChanged: { if (!activeFocus) originalPeekHeld = false }
+ onVisibleChanged: { if (!visible) originalPeekHeld = false }
// Previews always land in place: the viewer stays on whichever tab
// opened the render (Input, Output, or 2-Up). No tab is ever switched
@@ -334,10 +352,20 @@ Rectangle {
} else if (event.key === Qt.Key_Left) { videoTransport.stepFrames(-1); event.accepted = true }
else if (event.key === Qt.Key_Right) { videoTransport.stepFrames(1); event.accepted = true }
} else {
+ if (event.key === Qt.Key_Space && viewport.viewMode === "single" && viewport.hasOutput) {
+ viewport.originalPeekHeld = true
+ event.accepted = true
+ }
if (event.key === Qt.Key_0) { viewport.fitToWindow(); event.accepted = true }
if (event.key === Qt.Key_1) { viewport.actualPixels(); event.accepted = true }
}
}
+ Keys.onReleased: (event) => {
+ if (event.key === Qt.Key_Space && viewport.originalPeekHeld) {
+ if (!event.isAutoRepeat) viewport.originalPeekHeld = false
+ event.accepted = true
+ }
+ }
Rectangle {
id: toolbar
@@ -349,14 +377,15 @@ Rectangle {
Row {
anchors.left: parent.left; anchors.leftMargin: 10; anchors.verticalCenter: parent.verticalCenter; spacing: 8
AppSegmentedControl {
+ objectName: "imageComparisonSelector"
visible: !viewport.isVideo
width: 250
model: [{label:"Split",value:"split"},{label:"2-Up",value:"sideBySide"},{label:"Output",value:"single"}]
currentValue: viewport.viewMode
- onActivated: (v) => viewport.viewMode = v
+ onActivated: (v) => { viewport.viewMode = v; viewport.forceActiveFocus() }
}
AppSegmentedControl {
- visible: viewport.isVideo && viewport.hasOutput && appBridge && appBridge.previewOutputIsVideo
+ visible: viewport.isVideo && (viewport.hasOutput || viewport.videoTwoUp)
width: 225
model: [{label:"Input",value:"input"},{label:"Output",value:"output"},{label:"2-Up",value:"twoup"}]
currentValue: viewport.videoTwoUp ? "twoup" : (viewport.showVideoOutput ? "output" : "input")
@@ -379,13 +408,13 @@ Rectangle {
}
Row {
- visible: !viewport.isVideo
+ visible: !viewport.isVideo || viewport.showingTwoUp
anchors.right: parent.right; anchors.rightMargin: 10; anchors.verticalCenter: parent.verticalCenter; spacing: 6
AppIconButton { iconName: "fit_to_window"; buttonSize: 26; tooltipText: "Fit to window"; onClicked: viewport.fitToWindow() }
AppIconButton { iconName: "actual_size"; buttonSize: 26; tooltipText: "Actual pixels"; onClicked: viewport.actualPixels() }
Text { text: Math.round(viewport.displayScale * Math.max(1.0, Screen.devicePixelRatio) * 100) + "%"; color: Theme.textPrimary; font.family: Theme.monoFontFamily; anchors.verticalCenter: parent.verticalCenter }
- AppIconButton { iconName: "zoom_out"; tooltipText: "Zoom out"; onClicked: viewport.changeZoom(0.8) }
- AppIconButton { iconName: "zoom_in"; tooltipText: "Zoom in"; onClicked: viewport.changeZoom(1.25) }
+ AppIconButton { objectName: "previewZoomOut"; iconName: "zoom_out"; tooltipText: "Zoom out"; onClicked: viewport.changeZoom(0.8) }
+ AppIconButton { objectName: "previewZoomIn"; iconName: "zoom_in"; tooltipText: "Zoom in"; onClicked: viewport.changeZoom(1.25) }
AppIconButton {
iconName: appBridge && appBridge.focusPreview ? "exit_fullscreen" : "focus_preview"
tooltipText: appBridge && appBridge.focusPreview ? "Exit focus preview" : "Focus preview"
@@ -416,23 +445,55 @@ Rectangle {
fillMode: Image.PreserveAspectFit; cache: false; asynchronous: true; smooth: true
}
- // Single-pane surfaces double as 2-Up panes: only their geometry
- // changes, so players never re-link outputs (no repaint stall).
- VideoOutput {
- id: inputSurface
- objectName: "inputSurface"
+ // Each player keeps the same output while its clipped pane changes
+ // size. In 2-Up, both surfaces share the same zoom and pan.
+ Item {
+ id: inputVideoPane
+ objectName: "inputVideoPane"
anchors.top: parent.top; anchors.bottom: parent.bottom; anchors.left: parent.left
- width: viewport.showingTwoUp ? (parent.width - 4) / 2 : parent.width
+ width: viewport.showingTwoUp ? viewport.comparisonPaneWidth : parent.width
visible: viewport.isVideo && (!viewport.showingOutput || viewport.showingTwoUp)
- fillMode: VideoOutput.PreserveAspectFit
+ clip: true
+ VideoOutput {
+ id: inputSurface
+ objectName: "inputSurface"
+ width: parent.width; height: parent.height
+ transformOrigin: Item.TopLeft
+ scale: viewport.showingTwoUp ? viewport.zoomFactor : 1.0
+ x: (parent.width - width * scale) / 2 + (viewport.showingTwoUp ? viewport.panX : 0)
+ y: (parent.height - height * scale) / 2 + (viewport.showingTwoUp ? viewport.panY : 0)
+ fillMode: VideoOutput.PreserveAspectFit
+ }
}
- VideoOutput {
- id: outputSurface
- objectName: "outputSurface"
+ Item {
+ id: outputVideoPane
+ objectName: "outputVideoPane"
anchors.top: parent.top; anchors.bottom: parent.bottom; anchors.right: parent.right
- width: viewport.showingTwoUp ? (parent.width - 4) / 2 : parent.width
+ width: viewport.showingTwoUp ? viewport.comparisonPaneWidth : parent.width
visible: viewport.isVideo && (viewport.showingOutput || viewport.showingTwoUp)
- fillMode: VideoOutput.PreserveAspectFit
+ clip: true
+ VideoOutput {
+ id: outputSurface
+ objectName: "outputSurface"
+ visible: appBridge && appBridge.previewOutputIsVideo
+ width: parent.width; height: parent.height
+ transformOrigin: Item.TopLeft
+ scale: viewport.showingTwoUp ? viewport.zoomFactor : 1.0
+ x: (parent.width - width * scale) / 2 + (viewport.showingTwoUp ? viewport.panX : 0)
+ y: (parent.height - height * scale) / 2 + (viewport.showingTwoUp ? viewport.panY : 0)
+ fillMode: VideoOutput.PreserveAspectFit
+ }
+ Image {
+ objectName: "outputStillFrame"
+ visible: viewport.hasStillVideoOutput
+ source: visible && appBridge ? appBridge.previewOutputUrl : ""
+ width: parent.width; height: parent.height
+ transformOrigin: Item.TopLeft
+ scale: viewport.showingTwoUp ? viewport.zoomFactor : 1.0
+ x: (parent.width - width * scale) / 2 + (viewport.showingTwoUp ? viewport.panX : 0)
+ y: (parent.height - height * scale) / 2 + (viewport.showingTwoUp ? viewport.panY : 0)
+ fillMode: Image.PreserveAspectFit; cache: false; smooth: true
+ }
}
// 2-Up comparison chrome: pane badges + output loading placeholder.
@@ -477,7 +538,7 @@ Rectangle {
id: peekArea
anchors.fill: parent
z: 4
- visible: viewport.isVideo && viewport.hasOutput && appBridge && appBridge.previewOutputIsVideo && !viewport.showingTwoUp
+ visible: viewport.isVideo && viewport.hasOutput && !viewport.showingTwoUp
acceptedButtons: Qt.LeftButton
hoverEnabled: true
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
@@ -587,13 +648,15 @@ Rectangle {
onPositionChanged: (m) => {
if (pressed) setSplit(m.x, m.y)
}
+ onDoubleClicked: { if (appBridge) appBridge.splitPosition = 0.5 }
}
}
}
Image {
+ objectName: "singleOutputImage"
anchors.fill: parent
- visible: viewport.hasOutput && viewport.viewMode === "single"
+ visible: viewport.hasOutput && viewport.viewMode === "single" && !viewport.originalPeekHeld
source: appBridge ? appBridge.previewOutputUrl : ""
fillMode: Image.Stretch; cache: false; smooth: true
}
@@ -622,16 +685,56 @@ Rectangle {
visible: !viewport.isVideo && viewport.viewMode === "sideBySide"
Rectangle {
width: (parent.width - 4) / 2; height: parent.height; color: Theme.bgBase
- Image { anchors.fill: parent; anchors.margins: 4; source: appBridge ? appBridge.previewInputUrl : ""; fillMode: Image.PreserveAspectFit; cache: false }
+ clip: true
+ Image {
+ objectName: "inputComparisonImage"
+ width: parent.width - 8; height: parent.height - 8
+ transformOrigin: Item.TopLeft; scale: viewport.zoomFactor
+ x: 4 + (parent.width - 8 - width * scale) / 2 + viewport.panX
+ y: 4 + (parent.height - 8 - height * scale) / 2 + viewport.panY
+ source: appBridge ? appBridge.previewInputUrl : ""; fillMode: Image.PreserveAspectFit; cache: false
+ }
AppBadge { anchors.left: parent.left; anchors.top: parent.top; anchors.margins: 10; text: "INPUT" }
}
Rectangle {
width: (parent.width - 4) / 2; height: parent.height; color: Theme.bgBase
- Image { anchors.fill: parent; anchors.margins: 4; source: appBridge ? appBridge.previewOutputUrl : ""; fillMode: Image.PreserveAspectFit; cache: false }
+ clip: true
+ Image {
+ objectName: "outputComparisonImage"
+ width: parent.width - 8; height: parent.height - 8
+ transformOrigin: Item.TopLeft; scale: viewport.zoomFactor
+ x: 4 + (parent.width - 8 - width * scale) / 2 + viewport.panX
+ y: 4 + (parent.height - 8 - height * scale) / 2 + viewport.panY
+ source: appBridge ? appBridge.previewOutputUrl : ""; fillMode: Image.PreserveAspectFit; cache: false
+ }
AppBadge { anchors.left: parent.left; anchors.top: parent.top; anchors.margins: 10; text: viewport.hasOutput ? "OUTPUT" : "NO OUTPUT"; variant: viewport.hasOutput ? "accent" : "neutral" }
}
}
+ MouseArea {
+ id: comparisonPanArea
+ objectName: "comparisonPanArea"
+ anchors.fill: parent; z: 1
+ visible: viewport.twoUpLayout
+ acceptedButtons: Qt.LeftButton | Qt.MiddleButton
+ cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor
+ property real pressX: 0; property real pressY: 0
+ property real originPanX: 0; property real originPanY: 0
+ onPressed: (mouse) => {
+ pressX = mouse.x; pressY = mouse.y
+ originPanX = viewport.panX; originPanY = viewport.panY
+ viewport.forceActiveFocus()
+ }
+ onPositionChanged: (mouse) => {
+ if (!pressed) return
+ viewport.panX = originPanX + mouse.x - pressX
+ viewport.panY = originPanY + mouse.y - pressY
+ viewport.clampPan()
+ }
+ onDoubleClicked: viewport.fitToWindow()
+ onWheel: (wheel) => { viewport.changeZoom(wheel.angleDelta.y > 0 ? 1.12 : 0.89); wheel.accepted = true }
+ }
+
// Right-click catcher for the preview context menu. RightButton ONLY
// and stacked BELOW the interactive layers, so hover/cursor behavior
// (split divider, pan hand, peek pointer) is untouched: none of the
@@ -701,14 +804,6 @@ Rectangle {
}
}
- Rectangle {
- anchors.centerIn: parent
- visible: appBridge && (appBridge.operationState === "PreviewPreparing" || appBridge.operationState === "PreviewRunning" || appBridge.operationState === "LoadingMetadata")
- width: Math.min(parent.width - 40, 300); height: 64; radius: Theme.radiusLarge
- color: Theme.bgSurface; border.color: Theme.accent
- Text { anchors.centerIn: parent; text: appBridge ? appBridge.statusMessage : "Working..."; color: Theme.textPrimary; font.family: Theme.fontFamily; elide: Text.ElideRight; width: parent.width - 24; horizontalAlignment: Text.AlignHCenter }
- }
-
// Preview right-click menu: Clear single / Clear all / Show in Explorer
// (current selection only). Compact dark styling hugging items closely on all 4 sides.
// Clear actions honor canModifyQueue (dimmed while busy); Show in Explorer only needs loaded input.
diff --git a/src/desktop/qml/components/NeuralModelControls.qml b/src/desktop/qml/components/NeuralModelControls.qml
new file mode 100644
index 0000000..ed232ab
--- /dev/null
+++ b/src/desktop/qml/components/NeuralModelControls.qml
@@ -0,0 +1,270 @@
+import QtQuick
+import QtQuick.Dialogs
+import ".."
+import "../controls"
+
+Column {
+ id: root
+ property var appBridge: null
+ readonly property bool isImage: appBridge ? appBridge.nrMode === "Image" : true
+ width: parent ? parent.width : 320
+ spacing: 12
+ AppSegmentedControl {
+ width: parent.width
+ label: "NR Style"
+ model: appBridge ? appBridge.nrStyleChoices : []
+ currentValue: appBridge ? appBridge.nrStyle : "Default"
+ onActivated: v => {
+ if (appBridge)
+ appBridge.nrStyle = v;
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "NR Intensity"
+ from: 0.0
+ to: 2.0
+ stepSize: 0.05
+ defaultValue: 1.0
+ value: appBridge ? appBridge.nrIntensity : 1.0
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.nrIntensity = v;
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "NR Passes"
+ from: 1
+ to: 4
+ stepSize: 1
+ precision: 0
+ defaultValue: 1
+ value: appBridge ? appBridge.nrPasses : 1
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.nrPasses = Math.round(v);
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "Local Tone Strength"
+ from: 0.0
+ to: 2.0
+ stepSize: 0.05
+ defaultValue: 1.0
+ value: appBridge ? appBridge.localToneStrength : 1.0
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.localToneStrength = v;
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "Local Structure Strength"
+ from: 0.0
+ to: 2.0
+ stepSize: 0.05
+ defaultValue: 1.0
+ value: appBridge ? appBridge.localStructureStrength : 1.0
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.localStructureStrength = v;
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "Skin Structure Strength"
+ from: -1.0
+ to: 2.0
+ stepSize: 0.05
+ defaultValue: -1.0
+ value: appBridge ? appBridge.skinStructureStrength : -1.0
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.skinStructureStrength = v;
+ }
+ }
+
+ AppSwitch {
+ label: "Automatic Mask"
+ checked: appBridge ? appBridge.automaticMask : false
+ onToggled: c => {
+ if (appBridge)
+ appBridge.automaticMask = c;
+ }
+ }
+
+ AppSlider {
+ visible: !root.isImage
+ width: parent.width
+ label: "Shimmer Suppression"
+ from: 0.0
+ to: 1.0
+ stepSize: 0.05
+ defaultValue: 0.70
+ value: appBridge ? appBridge.shimmerSuppression : 0.70
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.shimmerSuppression = v;
+ }
+ }
+
+ Text {
+ width: parent.width
+ text: "Composition & Masking"
+ font.family: Theme.fontFamily
+ font.pixelSize: Theme.fontSizeSubtitle
+ color: Theme.textSecondary
+ }
+ // Detail-Only Preset Button
+ Row {
+ width: parent.width
+ spacing: 8
+
+ AppButton {
+ text: "Apply Detail-Only Preset"
+ iconName: "quality_enhance"
+ width: parent.width
+ buttonHeight: 28
+ onClicked: {
+ if (appBridge)
+ appBridge.applyDetailOnly();
+ }
+ }
+ }
+
+ // Sliders
+ AppSlider {
+ width: parent.width
+ label: "NR Color Strength"
+ from: 0.0
+ to: 1.0
+ stepSize: 0.05
+ defaultValue: 1.0
+ value: appBridge ? appBridge.nrColorStrength : 1.0
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.nrColorStrength = v;
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "Tone Preservation"
+ from: 0.0
+ to: 1.0
+ stepSize: 0.05
+ defaultValue: 0.0
+ value: appBridge ? appBridge.tonePreservation : 0.0
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.tonePreservation = v;
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "Face / Skin Protection"
+ from: 0.0
+ to: 1.0
+ stepSize: 0.05
+ defaultValue: 0.0
+ value: appBridge ? appBridge.faceSkinProtection : 0.0
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.faceSkinProtection = v;
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "Grain Preservation"
+ from: 0.0
+ to: 1.0
+ stepSize: 0.05
+ defaultValue: 0.0
+ value: appBridge ? appBridge.grainPreservation : 0.0
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.grainPreservation = v;
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "Mask Feather"
+ unit: "px"
+ from: 0
+ to: 128
+ stepSize: 1
+ precision: 0
+ defaultValue: 0
+ value: appBridge ? appBridge.maskFeather : 0
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.maskFeather = Math.round(v);
+ }
+ }
+
+ // Custom NR Mask Box
+ Rectangle {
+ width: parent.width
+ height: 64
+ radius: Theme.radiusMedium
+ color: Theme.bgInput
+ border.color: Theme.borderSubtle
+ border.width: 1
+
+ Column {
+ anchors.centerIn: parent
+ spacing: 4
+
+ Row {
+ anchors.horizontalCenter: parent.horizontalCenter
+ spacing: 8
+
+ AppButton {
+ text: "Load Custom Mask..."
+ iconName: "load_mask"
+ buttonHeight: 24
+ onClicked: maskDialog.open()
+ }
+
+ AppButton {
+ text: "Clear Mask"
+ iconName: "clear_mask"
+ buttonHeight: 24
+ onClicked: {
+ if (appBridge)
+ appBridge.clearCustomMask();
+ }
+ }
+ }
+
+ Text {
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: appBridge ? appBridge.customMaskStatus : "No mask loaded"
+ font.family: Theme.monoFontFamily
+ font.pixelSize: Theme.fontSizeSmall
+ color: Theme.textMuted
+ }
+ }
+ }
+
+ FileDialog {
+ id: maskDialog
+ title: "Select Custom NR Mask"
+ nameFilters: ["Image Files (*.png *.jpg *.jpeg *.webp *.tiff *.bmp)", "All Files (*.*)"]
+ onAccepted: {
+ if (appBridge && selectedFile) {
+ appBridge.selectCustomMask(selectedFile.toString());
+ }
+ }
+ }
+}
diff --git a/src/desktop/qml/components/ScaleMethodControls.qml b/src/desktop/qml/components/ScaleMethodControls.qml
new file mode 100644
index 0000000..565c44b
--- /dev/null
+++ b/src/desktop/qml/components/ScaleMethodControls.qml
@@ -0,0 +1,40 @@
+import QtQuick
+import QtQuick.Dialogs
+import ".."
+import "../controls"
+
+Column {
+ id: root
+ property var appBridge: null
+ readonly property bool isImage: appBridge ? appBridge.nrMode === "Image" : true
+ width: parent ? parent.width : 320
+ spacing: 12
+ AppComboBox {
+ width: parent.width
+ label: "Scaling Method"
+ model: root.isImage ? (appBridge ? appBridge.imageScalingFilterChoices : ["Lanczos4", "Area", "Bicubic", "Bilinear", "Nearest"])
+ : (appBridge ? appBridge.videoScalingFilterChoices : ["Spline36", "Lanczos", "Bicubic", "Area", "Bilinear", "EWA Lanczos"])
+ currentValue: root.isImage ? (appBridge ? appBridge.imageScalingFilter : "Lanczos4")
+ : (appBridge ? appBridge.videoScalingFilter : "Spline36")
+ onActivated: v => {
+ if (appBridge) {
+ if (root.isImage)
+ appBridge.imageScalingFilter = v;
+ else
+ appBridge.videoScalingFilter = v;
+ }
+ }
+ }
+
+ AppComboBox {
+ width: parent.width
+ label: "Scale"
+ model: appBridge ? appBridge.nrScaleChoices : []
+ currentValue: appBridge ? appBridge.upscalingFactor : 1.0
+ onActivated: v => {
+ if (appBridge)
+ appBridge.upscalingFactor = v;
+ }
+ }
+
+}
diff --git a/src/desktop/qml/components/SharpeningControls.qml b/src/desktop/qml/components/SharpeningControls.qml
new file mode 100644
index 0000000..24687e8
--- /dev/null
+++ b/src/desktop/qml/components/SharpeningControls.qml
@@ -0,0 +1,27 @@
+import QtQuick
+import "../controls"
+
+Column {
+ id: root
+ property var appBridge: null
+ width: parent ? parent.width : 320
+ spacing: 12
+
+ AppComboBox {
+ objectName: "sharpening-method"
+ width: parent.width
+ label: "Sharpening Method"
+ model: root.appBridge ? root.appBridge.sharpeningMethodChoices : ["NVIDIA NIS", "AMD CAS"]
+ currentValue: root.appBridge ? root.appBridge.sharpeningMethod : "AMD CAS"
+ onActivated: value => { if (root.appBridge) root.appBridge.sharpeningMethod = value }
+ }
+
+ AppSlider {
+ objectName: "sharpening-strength"
+ width: parent.width
+ label: "Sharpness"
+ from: 0; to: 100; stepSize: 1; precision: 0; defaultValue: 50; unit: "%"
+ value: root.appBridge ? root.appBridge.casSharpness : 50
+ onValueModified: v => { if (root.appBridge) root.appBridge.casSharpness = Math.round(v) }
+ }
+}
diff --git a/src/desktop/qml/components/SuperResolutionControls.qml b/src/desktop/qml/components/SuperResolutionControls.qml
new file mode 100644
index 0000000..57f4dc3
--- /dev/null
+++ b/src/desktop/qml/components/SuperResolutionControls.qml
@@ -0,0 +1,224 @@
+import QtQuick
+import QtQuick.Dialogs
+import ".."
+import "../controls"
+
+Column {
+ id: root
+ property var appBridge: null
+ readonly property bool isImage: appBridge ? appBridge.nrMode === "Image" : true
+ width: parent ? parent.width : 320
+ spacing: 12
+ AppSwitch {
+ visible: !root.isImage
+ label: "Enable RTX VSR"
+ checked: appBridge ? appBridge.upscaleVsrEnabled : true
+ enabled: appBridge ? (!checked || appBridge.upscaleHdrEnabled) : true
+ onToggled: c => {
+ if (appBridge)
+ appBridge.upscaleVsrEnabled = c;
+ }
+ }
+
+ AppComboBox {
+ width: parent.width
+ label: "VSR Quality"
+ model: appBridge ? appBridge.vsrQualityChoices : []
+ currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageVsrQuality : 4) : (appBridge ? appBridge.upscaleVsrQuality : 4)
+ onActivated: v => {
+ if (appBridge) {
+ if (root.isImage)
+ appBridge.upscaleImageVsrQuality = v;
+ else
+ appBridge.upscaleVsrQuality = v;
+ }
+ }
+ }
+
+ AppSegmentedControl {
+ width: parent.width
+ label: "Sizing Mode"
+ model: appBridge ? (root.isImage ? appBridge.imageSizeModeChoices : appBridge.videoSizeModeChoices) : []
+ currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageSizeMode : "Scale factor") : (appBridge ? appBridge.upscaleSizeMode : "Scale factor")
+ onActivated: v => {
+ if (appBridge) {
+ if (root.isImage)
+ appBridge.upscaleImageSizeMode = v;
+ else
+ appBridge.upscaleSizeMode = v;
+ }
+ }
+ }
+
+ AppComboBox {
+ width: parent.width
+ label: "Scale Factor"
+ visible: appBridge && (root.isImage ? appBridge.upscaleImageSizeMode : appBridge.upscaleSizeMode) === "Scale factor"
+ model: appBridge ? (root.isImage ? appBridge.imageScaleFactorChoices : appBridge.videoScaleFactorChoices) : []
+ currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageScaleFactor : 2.0) : (appBridge ? appBridge.upscaleScaleFactor : 2.0)
+ onActivated: v => {
+ if (appBridge) {
+ if (root.isImage)
+ appBridge.upscaleImageScaleFactor = v;
+ else
+ appBridge.upscaleScaleFactor = v;
+ }
+ }
+ }
+
+ Row {
+ width: parent.width
+ spacing: 8
+ visible: appBridge && (root.isImage ? appBridge.upscaleImageSizeMode : appBridge.upscaleSizeMode) === "Custom dimensions"
+
+ AppTextField {
+ width: (parent.width - 8) / 2
+ label: "Width (px)"
+ text: (root.isImage ? (appBridge ? appBridge.upscaleImageWidth : 3840)
+ : (appBridge ? appBridge.upscaleWidth : 3840)).toString()
+ commitOnEveryEdit: false
+ onTextEdited: t => {
+ var num = parseInt(t);
+ if (!isNaN(num) && num > 0) {
+ if (root.isImage)
+ appBridge.upscaleImageWidth = num;
+ else
+ appBridge.upscaleWidth = num;
+ }
+ }
+ }
+
+ AppTextField {
+ width: (parent.width - 8) / 2
+ label: "Height (px)"
+ text: (root.isImage ? (appBridge ? appBridge.upscaleImageHeight : 2160)
+ : (appBridge ? appBridge.upscaleHeight : 2160)).toString()
+ commitOnEveryEdit: false
+ onTextEdited: t => {
+ var num = parseInt(t);
+ if (!isNaN(num) && num > 0) {
+ if (root.isImage)
+ appBridge.upscaleImageHeight = num;
+ else
+ appBridge.upscaleHeight = num;
+ }
+ }
+ }
+ }
+
+ AppCheckBox {
+ label: "Lock Aspect Ratio"
+ checked: root.isImage ? (appBridge ? appBridge.upscaleImageAspectLock : true) : (appBridge ? appBridge.upscaleAspectLock : true)
+ onToggled: c => {
+ if (appBridge) {
+ if (root.isImage)
+ appBridge.upscaleImageAspectLock = c;
+ else
+ appBridge.upscaleAspectLock = c;
+ }
+ }
+ }
+
+ Text {
+ width: parent.width
+ visible: appBridge && appBridge.outputEstimate !== ""
+ text: appBridge ? appBridge.outputEstimate : ""
+ wrapMode: Text.Wrap
+ font.family: Theme.monoFontFamily
+ font.pixelSize: Theme.fontSizeSmall
+ color: Theme.textMuted
+ }
+
+ Column {
+ visible: !root.isImage
+ width: parent.width
+ spacing: 12
+ Text {
+ text: "RTX Video HDR"
+ font.family: Theme.fontFamily
+ font.pixelSize: Theme.fontSizeSubtitle
+ color: Theme.textSecondary
+ }
+ AppSwitch {
+ label: "Convert SDR to HDR"
+ checked: appBridge ? appBridge.upscaleHdrEnabled : false
+ enabled: appBridge ? (appBridge.upscaleHdrSupported && (!checked || appBridge.upscaleVsrEnabled)) : false
+ onToggled: c => {
+ if (appBridge)
+ appBridge.upscaleHdrEnabled = c;
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "HDR Contrast"
+ from: 0
+ to: 200
+ stepSize: 1
+ precision: 0
+ defaultValue: 100
+ value: appBridge ? appBridge.upscaleHdrContrast : 100
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.upscaleHdrContrast = Math.round(v);
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "HDR Saturation"
+ from: 0
+ to: 200
+ stepSize: 1
+ precision: 0
+ defaultValue: 100
+ value: appBridge ? appBridge.upscaleHdrSaturation : 100
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.upscaleHdrSaturation = Math.round(v);
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "Middle Gray"
+ from: 10
+ to: 100
+ stepSize: 1
+ precision: 0
+ defaultValue: 50
+ value: appBridge ? appBridge.upscaleHdrMiddleGray : 50
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.upscaleHdrMiddleGray = Math.round(v);
+ }
+ }
+
+ AppSlider {
+ width: parent.width
+ label: "Peak Luminance"
+ unit: "nits"
+ from: 400
+ to: 2000
+ stepSize: 50
+ precision: 0
+ defaultValue: 1000
+ value: appBridge ? appBridge.upscaleHdrPeakLuminance : 1000
+ onValueModified: v => {
+ if (appBridge)
+ appBridge.upscaleHdrPeakLuminance = Math.round(v);
+ }
+ }
+
+ AppSegmentedControl {
+ width: parent.width
+ label: "HDR Precision"
+ model: appBridge ? appBridge.hdrPrecisionChoices : []
+ currentValue: appBridge ? appBridge.upscaleHdrPrecision : "Packed 10-bit"
+ onActivated: v => {
+ if (appBridge)
+ appBridge.upscaleHdrPrecision = v;
+ }
+ }
+ }
+}
diff --git a/src/desktop/qml/components/WorkflowStageCard.qml b/src/desktop/qml/components/WorkflowStageCard.qml
new file mode 100644
index 0000000..4f028f3
--- /dev/null
+++ b/src/desktop/qml/components/WorkflowStageCard.qml
@@ -0,0 +1,177 @@
+import QtQuick
+import ".."
+import "../controls"
+
+Item {
+ id: card
+ property var appBridge: null
+ property string stageId: ""
+ property string title: ""
+ property bool stageEnabled: false
+ property int stageIndex: 0
+ property int stageCount: 0
+ property var stageRepeater: null
+ property bool collapsed: true
+ property real dragOffset: 0
+ property real slotOffset: 0
+ property int dragTarget: stageIndex
+ readonly property bool dragging: dragger.active
+ default property alias content: contentContainer.data
+
+ signal dragBegan(string stageId, int originIndex, real cardHeight)
+ signal dragMoved(int targetIndex)
+ signal dragFinished(string stageId, int targetIndex)
+
+ implicitWidth: 320
+ implicitHeight: header.height + (collapsed ? 0 : contentContainer.childrenRect.height + 24)
+ z: dragging ? 100 : 0
+ scale: dragging ? 1.018 : 1.0
+ transform: [
+ Translate { y: card.dragOffset },
+ Translate {
+ y: card.slotOffset
+ Behavior on y { NumberAnimation { duration: 150; easing.type: Easing.OutCubic } }
+ }
+ ]
+ Behavior on scale { NumberAnimation { duration: 120; easing.type: Easing.OutCubic } }
+
+ Rectangle {
+ anchors.fill: parent
+ radius: Theme.radiusLarge
+ color: card.dragging ? Theme.bgPressed : Theme.bgCard
+ border.color: card.dragging ? Theme.accent : Theme.borderSubtle
+ border.width: 1
+ Behavior on color { ColorAnimation { duration: 120 } }
+ }
+
+ Row {
+ id: header
+ x: 10
+ y: 0
+ width: parent.width - 20
+ height: 42
+ spacing: 3
+
+ AppSwitch {
+ objectName: "workflow-stage-switch-" + card.stageId
+ width: 40
+ height: 28
+ anchors.verticalCenter: parent.verticalCenter
+ checked: card.stageEnabled
+ onToggled: value => {
+ if (card.appBridge)
+ card.appBridge.setWorkflowStageEnabled(card.stageId, value);
+ }
+ Accessible.name: card.title + (card.stageEnabled ? " enabled" : " disabled")
+ }
+
+ Text {
+ id: titleText
+ width: Math.max(70, parent.width - 40 - 22 * 3 - 3 * 4)
+ height: parent.height
+ verticalAlignment: Text.AlignVCenter
+ text: card.title
+ elide: Text.ElideRight
+ font.family: Theme.fontFamily
+ font.pixelSize: Theme.fontSizeSubtitle
+ font.weight: Font.DemiBold
+ color: card.stageEnabled ? Theme.textPrimary : Theme.textSecondary
+ MouseArea {
+ anchors.fill: parent
+ cursorShape: Qt.OpenHandCursor
+ onClicked: card.collapsed = !card.collapsed
+ }
+ }
+
+ AppIconButton {
+ iconName: "chevron_up"
+ buttonSize: 22
+ anchors.verticalCenter: parent.verticalCenter
+ tooltipText: "Move " + card.title + " up"
+ enabled: card.stageIndex > 0
+ onClicked: {
+ if (card.appBridge)
+ card.appBridge.moveWorkflowStage(card.stageId, card.stageIndex - 1);
+ }
+ }
+ AppIconButton {
+ iconName: "chevron_down"
+ buttonSize: 22
+ anchors.verticalCenter: parent.verticalCenter
+ tooltipText: "Move " + card.title + " down"
+ enabled: card.stageIndex < card.stageCount - 1
+ onClicked: {
+ if (card.appBridge)
+ card.appBridge.moveWorkflowStage(card.stageId, card.stageIndex + 1);
+ }
+ }
+ AppIconButton {
+ iconName: card.collapsed ? "chevron_right" : "chevron_left"
+ buttonSize: 22
+ anchors.verticalCenter: parent.verticalCenter
+ tooltipText: card.collapsed ? "Expand " + card.title : "Collapse " + card.title
+ onClicked: card.collapsed = !card.collapsed
+ }
+
+ DragHandler {
+ id: dragger
+ target: null
+ acceptedButtons: Qt.LeftButton
+ yAxis.enabled: true
+ xAxis.enabled: false
+ onTranslationChanged: {
+ if (!active) return;
+ card.dragOffset = translation.y;
+ var target = card.stageIndex;
+ var other;
+ if (card.dragOffset < 0) {
+ var top = card.y + card.dragOffset;
+ for (var i = card.stageIndex - 1; i >= 0; --i) {
+ other = card.stageRepeater ? card.stageRepeater.itemAt(i) : null;
+ if (other && top < other.y + other.height / 2)
+ target = i;
+ }
+ } else if (card.dragOffset > 0) {
+ var bottom = card.y + card.height + card.dragOffset;
+ for (var j = card.stageIndex + 1; j < card.stageCount; ++j) {
+ other = card.stageRepeater ? card.stageRepeater.itemAt(j) : null;
+ if (other && bottom > other.y + other.height / 2)
+ target = j;
+ }
+ }
+ if (target !== card.dragTarget) {
+ card.dragTarget = target;
+ card.dragMoved(target);
+ }
+ }
+ onActiveChanged: {
+ if (active) {
+ card.dragTarget = card.stageIndex;
+ card.dragBegan(card.stageId, card.stageIndex, card.height);
+ } else {
+ card.dragFinished(card.stageId, card.dragTarget);
+ card.dragOffset = 0;
+ card.dragTarget = card.stageIndex;
+ }
+ }
+ }
+ }
+
+ Rectangle {
+ visible: !card.collapsed
+ x: 12
+ y: header.height
+ width: parent.width - 24
+ height: 1
+ color: Theme.borderSubtle
+ }
+ Item {
+ id: contentContainer
+ visible: !card.collapsed
+ x: 12
+ y: header.height + 12
+ width: parent.width - 24
+ height: childrenRect.height
+ opacity: card.stageEnabled ? 1.0 : 0.6
+ }
+}
diff --git a/src/desktop/qml/views/AboutView.qml b/src/desktop/qml/views/AboutView.qml
index f2869d7..5a0223b 100644
--- a/src/desktop/qml/views/AboutView.qml
+++ b/src/desktop/qml/views/AboutView.qml
@@ -28,6 +28,12 @@ Rectangle {
anchors.horizontalCenter: parent.horizontalCenter; spacing: 12
AppButton { text: "GitHub Repository"; iconName: "github"; onClicked: Qt.openUrlExternally("https://github.com/Merserk/dlss5-visual-enhancer") }
AppButton { text: "Support on Patreon"; iconName: "heart"; onClicked: Qt.openUrlExternally("https://www.patreon.com/Merserk") }
+ AppButton { text: "Third-Party Licenses"; onClicked: { if (root.appBridge) root.appBridge.openThirdPartyNotices() } }
+ }
+ Text {
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: "Includes Qt/PySide6 under LGPLv3 and other open-source components. See Third-Party Licenses."
+ font.family: Theme.fontFamily; font.pixelSize: Theme.fontSizeSmall; color: Theme.textSecondary
}
Text { anchors.horizontalCenter: parent.horizontalCenter; text: "© 2026 Merserk. NVIDIA, DLSS, and RTX are trademarks of NVIDIA Corporation."; font.family: Theme.fontFamily; font.pixelSize: Theme.fontSizeSmall; color: Theme.textMuted }
}
diff --git a/src/desktop/qml/views/FrameInterpolationView.qml b/src/desktop/qml/views/FrameInterpolationView.qml
index 0363d19..37e2074 100644
--- a/src/desktop/qml/views/FrameInterpolationView.qml
+++ b/src/desktop/qml/views/FrameInterpolationView.qml
@@ -85,7 +85,7 @@ Item {
// Card 1: Frame Generation Configuration
AppCard {
width: parent.width
- title: "DLSS-G Frame Generation"
+ title: "DLSS Frame Generation"
Column {
width: parent.width
diff --git a/src/desktop/qml/views/NeuralRenderingView.qml b/src/desktop/qml/views/NeuralRenderingView.qml
index ff49f6e..50212c9 100644
--- a/src/desktop/qml/views/NeuralRenderingView.qml
+++ b/src/desktop/qml/views/NeuralRenderingView.qml
@@ -1,374 +1,302 @@
-import QtQuick
-import ".."
-import "../controls"
-import "../components"
-
+import QtQuick
+import ".."
+import "../controls"
+import "../components"
+
Item {
id: root
+ objectName: "neural-rendering-view"
property var appBridge: null
- readonly property int adaptiveInspectorWidth: width >= 2560 ? 520 : (width >= 1920 ? 460 : (width >= 1600 ? 420 : (width >= 1280 ? 380 : 340)))
-
+ property alias workflowRepeater: stageRepeater
+ readonly property int adaptiveInspectorWidth: width >= 2560 ? 520 : (width >= 1920 ? 460 : (width >= 1600 ? 420 : (width >= 1280 ? 380 : 340)))
+
readonly property bool isImage: appBridge ? (appBridge.nrMode === "Image") : true
readonly property var activeQueue: appBridge ? (isImage ? appBridge.nrImageQueue : appBridge.nrVideoQueue) : null
-
- Row {
- anchors.fill: parent
-
- // Main Center Area: Media Viewport + Batch Queue Drawer
- Item {
- width: parent.width - sidebar.width
- height: parent.height
-
- MediaViewport {
- id: viewport
- anchors.top: parent.top
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.bottom: queueDrawer.top
- appBridge: root.appBridge
- }
-
- BatchQueueDrawer {
- id: queueDrawer
- anchors.bottom: parent.bottom
- anchors.left: parent.left
- anchors.right: parent.right
- appBridge: root.appBridge
- queueModel: root.activeQueue
- hidden: appBridge ? appBridge.focusPreview : false
- expandedHeight: appBridge ? appBridge.queueHeight : 190
- }
- }
-
- // Right Sidebar: Parameters & Inspector (Topaz-style)
- Rectangle {
- id: sidebar
- width: appBridge && appBridge.focusPreview ? 0 : Math.max(root.adaptiveInspectorWidth, Math.min(560, appBridge ? appBridge.inspectorWidth : root.adaptiveInspectorWidth))
- height: parent.height
- visible: width > 0
- color: Theme.bgSurface
- border.color: Theme.borderSubtle
- border.width: 1
-
- MouseArea {
- id: inspectorResizeHandle
- anchors.left: parent.left
- anchors.top: parent.top
- anchors.bottom: parent.bottom
- width: 6
- z: 100
- cursorShape: Qt.SizeHorCursor
- onPositionChanged: (mouse) => {
- if (!pressed || !appBridge) return
- var pt = inspectorResizeHandle.mapToItem(root, mouse.x, mouse.y)
- appBridge.inspectorWidth = Math.max(300, Math.min(560, root.width - pt.x))
- }
- }
-
- Column {
- anchors.fill: parent
-
- // Workflow Submode Switcher: Image vs Video
- Rectangle {
- width: parent.width
- height: 48
- color: Theme.bgSurface
- border.color: Theme.borderSubtle
- border.width: 1
-
- Row {
- anchors.centerIn: parent
- spacing: 8
-
- AppSegmentedControl {
- model: ["Image", "Video"]
- currentValue: root.appBridge ? root.appBridge.nrMode : "Image"
- onActivated: (val) => {
- if (root.appBridge) root.appBridge.nrMode = val
- }
- }
- }
- }
-
- // Scrollable Cards Area
- Flickable {
- id: flick
- width: parent.width
- height: parent.height - 48 - actionBar.height
- contentWidth: width
- contentHeight: contentCol.implicitHeight + 24
+ property var collapsedCards: ({})
+ property string draggedStageId: ""
+ property int dragOriginIndex: -1
+ property int dragTargetIndex: -1
+ property real draggedCardHeight: 0
+
+ function collapseKey(stageId, mode) { return mode + ":" + stageId }
+ function storedCollapsed(stageId, mode) {
+ var key = collapseKey(stageId, mode)
+ return collapsedCards[key] === undefined ? true : collapsedCards[key]
+ }
+ function rememberCollapsed(stageId, mode, value) {
+ collapsedCards[collapseKey(stageId, mode)] = value
+ }
+ function stageSlotOffset(stageId, index) {
+ if (!draggedStageId || stageId === draggedStageId) return 0
+ var distance = draggedCardHeight + contentCol.spacing
+ if (dragTargetIndex > dragOriginIndex
+ && index > dragOriginIndex && index <= dragTargetIndex) return -distance
+ if (dragTargetIndex < dragOriginIndex
+ && index >= dragTargetIndex && index < dragOriginIndex) return distance
+ return 0
+ }
+
+ function stageTitle(id) {
+ if (id === "denoising") return "Denoising"
+ if (id === "neural_model") return "DLSS Neural Rendering"
+ if (id === "scale_method") return "Scaling"
+ if (id === "dlss_super_resolution") return "DLSS Super Resolution"
+ if (id === "super_resolution") return "RTX Super Resolution"
+ if (id === "coloring") return "Coloring"
+ if (id === "cas_sharpening") return "Sharpening"
+ return "DLSS Frame Generation"
+ }
+
+ Component { id: neuralControls; NeuralModelControls { appBridge: root.appBridge } }
+ Component { id: scaleControls; ScaleMethodControls { appBridge: root.appBridge } }
+ Component { id: dlssControls; DlssSuperResolutionControls { appBridge: root.appBridge } }
+ Component { id: superControls; SuperResolutionControls { appBridge: root.appBridge } }
+ Component { id: coloringControls; ColoringControls { appBridge: root.appBridge } }
+ Component { id: denoisingControls; DenoisingControls { appBridge: root.appBridge } }
+ Component { id: sharpeningControls; SharpeningControls { appBridge: root.appBridge } }
+ Component { id: frameControls; FrameGenerationControls { appBridge: root.appBridge } }
+
+ Row {
+ anchors.fill: parent
+
+ // Main Center Area: Media Viewport + Batch Queue Drawer
+ Item {
+ width: parent.width - sidebar.width
+ height: parent.height
+
+ MediaViewport {
+ id: viewport
+ anchors.top: parent.top
+ anchors.left: parent.left
+ anchors.right: parent.right
+ anchors.bottom: queueDrawer.top
+ appBridge: root.appBridge
+ }
+
+ BatchQueueDrawer {
+ id: queueDrawer
+ anchors.bottom: parent.bottom
+ anchors.left: parent.left
+ anchors.right: parent.right
+ appBridge: root.appBridge
+ queueModel: root.activeQueue
+ hidden: appBridge ? appBridge.focusPreview : false
+ expandedHeight: appBridge ? appBridge.queueHeight : 190
+ }
+ }
+
+ // Right Sidebar: Parameters & Inspector (Topaz-style)
+ Rectangle {
+ id: sidebar
+ width: appBridge && appBridge.focusPreview ? 0 : Math.max(root.adaptiveInspectorWidth, Math.min(560, appBridge ? appBridge.inspectorWidth : root.adaptiveInspectorWidth))
+ height: parent.height
+ visible: width > 0
+ color: Theme.bgSurface
+ border.color: Theme.borderSubtle
+ border.width: 1
+
+ MouseArea {
+ id: inspectorResizeHandle
+ anchors.left: parent.left
+ anchors.top: parent.top
+ anchors.bottom: parent.bottom
+ width: 6
+ z: 100
+ cursorShape: Qt.SizeHorCursor
+ onPositionChanged: (mouse) => {
+ if (!pressed || !appBridge) return
+ var pt = inspectorResizeHandle.mapToItem(root, mouse.x, mouse.y)
+ appBridge.inspectorWidth = Math.max(300, Math.min(560, root.width - pt.x))
+ }
+ }
+
+ Column {
+ anchors.fill: parent
+
+ // Workflow Submode Switcher: Image vs Video
+ Rectangle {
+ width: parent.width
+ height: 48
+ color: Theme.bgSurface
+ border.color: Theme.borderSubtle
+ border.width: 1
+
+ Row {
+ anchors.centerIn: parent
+ spacing: 8
+
+ AppSegmentedControl {
+ model: ["Image", "Video"]
+ currentValue: root.appBridge ? root.appBridge.nrMode : "Image"
+ onActivated: (val) => {
+ if (root.appBridge) root.appBridge.nrMode = val
+ }
+ }
+ }
+ }
+
+ // Scrollable Cards Area
+ Flickable {
+ id: flick
+ width: parent.width
+ height: parent.height - 48 - actionBar.height
+ contentWidth: width
+ contentHeight: contentCol.implicitHeight + 24
clip: true
boundsBehavior: Flickable.StopAtBounds
-
- Column {
- id: contentCol
- width: parent.width - 24
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.top: parent.top
- anchors.topMargin: 12
- spacing: 12
-
- // Card 1: Neural Rendering Parameters
- AppCard {
- width: parent.width
- title: "DLSS Neural Model"
-
- Column {
- width: parent.width
- spacing: 12
-
- AppSegmentedControl {
- width: parent.width
- label: "NR Style"
- model: appBridge ? appBridge.nrStyleChoices : []
- currentValue: appBridge ? appBridge.nrStyle : "Default"
- onActivated: (v) => { if (appBridge) appBridge.nrStyle = v }
- }
-
- AppComboBox {
- width: parent.width
- label: "Scale"
-model: appBridge ? appBridge.nrScaleChoices : []
- currentValue: appBridge ? appBridge.upscalingFactor : 1.0
- onActivated: (v) => { if (appBridge) appBridge.upscalingFactor = v }
- }
-
- AppSlider {
- width: parent.width
- label: "NR Intensity"
- from: 0.0
- to: 2.0
- stepSize: 0.05
- defaultValue: 1.0
- value: appBridge ? appBridge.nrIntensity : 1.0
- onValueModified: (v) => { if (appBridge) appBridge.nrIntensity = v }
- }
-
- AppSlider {
- width: parent.width
- label: "NR Passes"
- from: 1
- to: 4
- stepSize: 1
- precision: 0
- defaultValue: 1
- value: appBridge ? appBridge.nrPasses : 1
- onValueModified: (v) => { if (appBridge) appBridge.nrPasses = Math.round(v) }
- }
-
- AppSlider {
- width: parent.width
- label: "Local Tone Strength"
- from: 0.0
- to: 2.0
- stepSize: 0.05
- defaultValue: 1.0
- value: appBridge ? appBridge.localToneStrength : 1.0
- onValueModified: (v) => { if (appBridge) appBridge.localToneStrength = v }
- }
-
- AppSlider {
- width: parent.width
- label: "Local Structure Strength"
- from: 0.0
- to: 2.0
- stepSize: 0.05
- defaultValue: 1.0
- value: appBridge ? appBridge.localStructureStrength : 1.0
- onValueModified: (v) => { if (appBridge) appBridge.localStructureStrength = v }
+ interactive: root.draggedStageId === ""
+
+ Column {
+ id: contentCol
+ width: parent.width - 24
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.top: parent.top
+ anchors.topMargin: 12
+ spacing: 12
+
+ Repeater {
+ id: stageRepeater
+ model: appBridge ? appBridge.workflowStages : []
+ delegate: WorkflowStageCard {
+ objectName: "workflow-stage-" + stageId
+ width: contentCol.width
+ appBridge: root.appBridge
+ stageId: modelData.id
+ stageEnabled: modelData.enabled
+ stageIndex: index
+ stageCount: root.workflowRepeater ? root.workflowRepeater.count : 0
+ stageRepeater: root.workflowRepeater
+ title: root.stageTitle(stageId)
+ slotOffset: root.stageSlotOffset(stageId, stageIndex)
+ property string layoutMode: root.isImage ? "Image" : "Video"
+ property bool restoringCollapse: false
+ function restoreCollapse() {
+ if (!stageId) return
+ restoringCollapse = true
+ collapsed = root.storedCollapsed(stageId, layoutMode)
+ restoringCollapse = false
}
-
- AppSlider {
- width: parent.width
- label: "Skin Structure Strength"
- from: -1.0
- to: 2.0
- stepSize: 0.05
- defaultValue: -1.0
- value: appBridge ? appBridge.skinStructureStrength : -1.0
- onValueModified: (v) => { if (appBridge) appBridge.skinStructureStrength = v }
+ onStageIdChanged: restoreCollapse()
+ onLayoutModeChanged: restoreCollapse()
+ Component.onCompleted: restoreCollapse()
+ onCollapsedChanged: {
+ if (!restoringCollapse && stageId)
+ root.rememberCollapsed(stageId, layoutMode, collapsed)
}
-
- AppSwitch {
- label: "Automatic Mask"
- checked: appBridge ? appBridge.automaticMask : false
- onToggled: (c) => { if (appBridge) appBridge.automaticMask = c }
+ onDragBegan: (id, origin, cardHeight) => {
+ root.draggedStageId = id
+ root.dragOriginIndex = origin
+ root.dragTargetIndex = origin
+ root.draggedCardHeight = cardHeight
}
-
- AppSlider {
- visible: !root.isImage
- width: parent.width
- label: "Shimmer Suppression"
- from: 0.0
- to: 1.0
- stepSize: 0.05
- defaultValue: 0.70
- value: appBridge ? appBridge.shimmerSuppression : 0.70
- onValueModified: (v) => { if (appBridge) appBridge.shimmerSuppression = v }
+ onDragMoved: target => { root.dragTargetIndex = target }
+ onDragFinished: (id, target) => {
+ root.draggedStageId = ""
+ root.dragOriginIndex = -1
+ root.dragTargetIndex = -1
+ if (target !== stageIndex && root.appBridge)
+ root.appBridge.moveWorkflowStage(id, target)
}
- }
- }
-
- // Card 2: Composition & Masking
- CompositionCard {
- width: parent.width
- appBridge: root.appBridge
- }
-
- // Card 3: Export & Encoding Settings
- AppCard {
- width: parent.width
- title: "Export Settings"
-
- Column {
- width: parent.width
- spacing: 12
-
- // IMAGE SPECIFIC
- Column {
- visible: root.isImage
- width: parent.width
- spacing: 12
-
- AppComboBox {
- width: parent.width
- label: "Output Format"
- model: appBridge ? appBridge.imageFormatChoices : []
- currentValue: appBridge ? appBridge.imageFormat : "PNG"
- onActivated: (v) => { if (appBridge) appBridge.imageFormat = v }
- }
-
- AppSlider {
- width: parent.width
- label: "Image Quality"
- from: 1
- to: 100
- stepSize: 1
- precision: 0
- defaultValue: 95
- value: appBridge ? appBridge.imageQuality : 95
- onValueModified: (v) => { if (appBridge) appBridge.imageQuality = Math.round(v) }
- }
-
- }
-
- // VIDEO SPECIFIC
- Column {
- visible: !root.isImage
+ Loader {
width: parent.width
- spacing: 12
-
- AppComboBox {
- width: parent.width
- label: "Video Codec"
- model: appBridge ? appBridge.codecChoices : []
- currentValue: appBridge ? appBridge.videoCodec : "H.264 (NVIDIA NVENC)"
- onActivated: (v) => { if (appBridge) appBridge.videoCodec = v }
- }
-
- AppComboBox {
- width: parent.width
- label: "Container"
- model: appBridge ? appBridge.containerChoices : []
- currentValue: appBridge ? appBridge.videoContainer : "MP4"
- enabled: false
- }
-
- AppComboBox {
- width: parent.width
- label: "Encoding Quality"
- visible: !appBridge || appBridge.fixedQualityCodecs.indexOf(appBridge.videoCodec) < 0
- model: appBridge ? appBridge.encodingQualityChoices : []
- currentValue: appBridge ? appBridge.videoQuality : "Auto (Default)"
- onActivated: (v) => { if (appBridge) appBridge.videoQuality = v }
- }
-
- Text {
- visible: appBridge && appBridge.fixedQualityCodecs.indexOf(appBridge.videoCodec) >= 0
- text: "Encoding Quality: Fixed by codec"
- color: Theme.textSecondary
- font.pixelSize: Theme.fontSizeSmall
- }
-
- AppCheckBox {
- label: "10-bit HDR Mode"
- checked: appBridge ? appBridge.videoHdrMode : false
- onToggled: (c) => { if (appBridge) appBridge.videoHdrMode = c }
- }
-
- }
- }
- }
- }
- }
-
- // Sticky Bottom Action Bar
- Rectangle {
- id: actionBar
- width: parent.width
- height: 88
- color: Theme.bgSurface
- border.color: Theme.borderSubtle
- border.width: 1
-
- Column {
- anchors.fill: parent
- anchors.margins: 8
- spacing: 6
-
- Row {
- width: parent.width
- spacing: 8
-
- AppButton {
- text: "Preview"
- iconName: "preview"
- width: (parent.width - 16) / 3
- buttonHeight: 30
- enabled: appBridge ? appBridge.canPreview : false
- onClicked: {
- if (appBridge) appBridge.renderPreviewAt(viewport.playheadMs)
- }
- }
-
- AppButton {
- text: "Reset"
- iconName: "reset"
- width: (parent.width - 16) / 3
- buttonHeight: 30
- onClicked: { if (appBridge) appBridge.resetTabSettings("neural-rendering") }
- }
-
- AppButton {
- text: "Outputs"
- iconName: "outputs_folder"
- width: (parent.width - 16) / 3
- buttonHeight: 30
- onClicked: { if (appBridge) appBridge.openFolder("") }
- }
- }
-
- AppButton {
- text: appBridge && appBridge.canStop ? "Stop" : (root.isImage ? "Render Image(s)" : "Render Video(s)")
- iconName: appBridge && appBridge.canStop ? "stop" : "start_render"
- variant: appBridge && appBridge.canStop ? "danger" : "primary"
- width: parent.width
- buttonHeight: 34
- enabled: appBridge ? (appBridge.canStop || (appBridge.operationState === "Idle" && appBridge.runtimeState === "Ready" && !appBridge.isLiveRunning)) : false
- onClicked: {
- if (appBridge) {
- if (appBridge.canStop) {
- appBridge.stopActiveBatch()
- } else {
- appBridge.requestActiveBatchExport()
- }
- }
- }
- }
- }
- }
- }
- }
- }
-}
+ sourceComponent: stageId === "neural_model" ? neuralControls
+ : stageId === "denoising" ? denoisingControls
+ : stageId === "scale_method" ? scaleControls
+ : stageId === "dlss_super_resolution" ? dlssControls
+ : stageId === "super_resolution" ? superControls
+ : stageId === "coloring" ? coloringControls
+ : stageId === "cas_sharpening" ? sharpeningControls
+ : frameControls
+ }
+ }
+ }
+
+ AppCard {
+ width: parent.width
+ title: "Export Settings"
+ ExportSettingsControls {
+ width: parent.width
+ appBridge: root.appBridge
+ }
+ }
+ }
+ }
+
+ // Sticky Bottom Action Bar
+ Rectangle {
+ id: actionBar
+ width: parent.width
+ height: 88
+ color: Theme.bgSurface
+ border.color: Theme.borderSubtle
+ border.width: 1
+
+ Column {
+ anchors.fill: parent
+ anchors.margins: 8
+ spacing: 6
+
+ Row {
+ width: parent.width
+ spacing: 8
+
+ AppButton {
+ text: "Preview"
+ iconName: "preview"
+ width: Math.max(100, parent.width - (root.isImage ? 84 : 156))
+ buttonHeight: 30
+ enabled: appBridge ? appBridge.canPreview : false
+ onClicked: {
+ if (appBridge) appBridge.renderPreviewAt(viewport.playheadMs)
+ }
+ }
+
+ AppComboBox {
+ width: 72
+ comboHeight: 30
+ dropUp: true
+ visible: !root.isImage
+ model: appBridge ? appBridge.nrPreviewLengthChoices : []
+ currentValue: appBridge ? appBridge.nrPreviewLength : "3"
+ onActivated: (v) => { if (appBridge) appBridge.nrPreviewLength = v }
+ }
+
+ AppIconButton {
+ iconName: "reset"
+ buttonSize: 30
+ tooltipText: "Reset neural rendering settings"
+ onClicked: { if (appBridge) appBridge.resetTabSettings("neural-rendering") }
+ }
+
+ AppIconButton {
+ iconName: "outputs_folder"
+ buttonSize: 30
+ tooltipText: "Open outputs folder"
+ onClicked: { if (appBridge) appBridge.openFolder("") }
+ }
+ }
+
+ AppButton {
+ text: appBridge && appBridge.canStop ? "Stop" : (root.isImage ? "Render Image(s)" : "Render Video(s)")
+ iconName: appBridge && appBridge.canStop ? "stop" : "start_render"
+ variant: appBridge && appBridge.canStop ? "danger" : "primary"
+ width: parent.width
+ buttonHeight: 34
+ enabled: appBridge ? (appBridge.canStop || (appBridge.operationState === "Idle" && appBridge.runtimeState === "Ready" && !appBridge.isLiveRunning)) : false
+ onClicked: {
+ if (appBridge) {
+ if (appBridge.canStop) {
+ appBridge.stopActiveBatch()
+ } else {
+ appBridge.requestActiveBatchExport()
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/desktop/qml/views/UpscaleView.qml b/src/desktop/qml/views/UpscaleView.qml
index 65f6397..395b83b 100644
--- a/src/desktop/qml/views/UpscaleView.qml
+++ b/src/desktop/qml/views/UpscaleView.qml
@@ -108,17 +108,59 @@ Item {
anchors.topMargin: 12
spacing: 12
- // Card 1: RTX Video Super Resolution (VSR)
+ // Card 1: Super Resolution
AppCard {
width: parent.width
- title: "RTX Video Super Resolution"
+ title: "DLSS Super Resolution"
Column {
width: parent.width
spacing: 12
+ AppComboBox {
+ width: parent.width
+ label: "Engine"
+ model: appBridge ? appBridge.upscaleEngineChoices : []
+ currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageEngine : "RTX Video Super Resolution") : (appBridge ? appBridge.upscaleEngine : "RTX Video Super Resolution")
+ onActivated: (v) => {
+ if (appBridge) {
+ if (root.isImage) appBridge.upscaleImageEngine = v
+ else appBridge.upscaleEngine = v
+ }
+ }
+ }
+
+ AppComboBox {
+ width: parent.width
+ label: "DLSS Mode"
+ visible: appBridge && (root.isImage ? appBridge.upscaleImageEngine : appBridge.upscaleEngine) === "DLSS"
+ model: appBridge ? appBridge.dlssModeChoices : []
+ currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageDlssMode : "Quality") : (appBridge ? appBridge.upscaleDlssMode : "Quality")
+ onActivated: (v) => {
+ if (appBridge) {
+ if (root.isImage) appBridge.upscaleImageDlssMode = v
+ else appBridge.upscaleDlssMode = v
+ }
+ }
+ }
+
+ AppComboBox {
+ width: parent.width
+ label: "DLSS Preset"
+ visible: appBridge && (root.isImage ? appBridge.upscaleImageEngine : appBridge.upscaleEngine) === "DLSS"
+ model: appBridge ? appBridge.dlssPresetChoices : []
+ currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageDlssPreset : "Default") : (appBridge ? appBridge.upscaleDlssPreset : "Default")
+ onActivated: (v) => {
+ if (appBridge) {
+ if (root.isImage) appBridge.upscaleImageDlssPreset = v
+ else appBridge.upscaleDlssPreset = v
+ }
+ }
+ }
+
AppSwitch {
visible: !root.isImage
+ && appBridge && appBridge.upscaleEngine !== "DLSS"
label: "Enable RTX VSR"
checked: appBridge ? appBridge.upscaleVsrEnabled : true
enabled: appBridge ? (!checked || appBridge.upscaleHdrEnabled) : true
@@ -128,6 +170,7 @@ Item {
AppComboBox {
width: parent.width
label: "VSR Quality"
+ visible: !appBridge || (root.isImage ? appBridge.upscaleImageEngine : appBridge.upscaleEngine) !== "DLSS"
model: appBridge ? appBridge.vsrQualityChoices : []
currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageVsrQuality : 4) : (appBridge ? appBridge.upscaleVsrQuality : 4)
onActivated: (v) => {
@@ -141,6 +184,7 @@ model: appBridge ? appBridge.vsrQualityChoices : []
AppSegmentedControl {
width: parent.width
label: "Sizing Mode"
+ visible: !appBridge || (root.isImage ? appBridge.upscaleImageEngine : appBridge.upscaleEngine) !== "DLSS"
model: appBridge ? (root.isImage ? appBridge.imageSizeModeChoices : appBridge.videoSizeModeChoices) : []
currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageSizeMode : "Scale factor") : (appBridge ? appBridge.upscaleSizeMode : "Scale factor")
onActivated: (v) => {
@@ -154,7 +198,7 @@ model: appBridge ? appBridge.vsrQualityChoices : []
AppComboBox {
width: parent.width
label: "Scale Factor"
- visible: (root.isImage ? appBridge.upscaleImageSizeMode : appBridge.upscaleSizeMode) === "Scale factor"
+ visible: appBridge && (root.isImage ? appBridge.upscaleImageEngine : appBridge.upscaleEngine) !== "DLSS" && (root.isImage ? appBridge.upscaleImageSizeMode : appBridge.upscaleSizeMode) === "Scale factor"
model: appBridge ? (root.isImage ? appBridge.imageScaleFactorChoices : appBridge.videoScaleFactorChoices) : []
currentValue: root.isImage ? (appBridge ? appBridge.upscaleImageScaleFactor : 2.0) : (appBridge ? appBridge.upscaleScaleFactor : 2.0)
onActivated: (v) => {
@@ -168,7 +212,7 @@ model: appBridge ? appBridge.vsrQualityChoices : []
Row {
width: parent.width
spacing: 8
- visible: (root.isImage ? appBridge.upscaleImageSizeMode : appBridge.upscaleSizeMode) === "Custom dimensions"
+ visible: appBridge && (root.isImage ? appBridge.upscaleImageEngine : appBridge.upscaleEngine) !== "DLSS" && (root.isImage ? appBridge.upscaleImageSizeMode : appBridge.upscaleSizeMode) === "Custom dimensions"
AppTextField {
width: (parent.width - 8) / 2
@@ -201,6 +245,7 @@ model: appBridge ? appBridge.vsrQualityChoices : []
AppCheckBox {
label: "Lock Aspect Ratio"
+ visible: !appBridge || (root.isImage ? appBridge.upscaleImageEngine : appBridge.upscaleEngine) !== "DLSS"
checked: root.isImage ? (appBridge ? appBridge.upscaleImageAspectLock : true) : (appBridge ? appBridge.upscaleAspectLock : true)
onToggled: (c) => {
if (appBridge) {
@@ -235,7 +280,7 @@ model: appBridge ? appBridge.vsrQualityChoices : []
AppSwitch {
label: "Convert SDR to HDR"
checked: appBridge ? appBridge.upscaleHdrEnabled : false
- enabled: appBridge ? (appBridge.upscaleHdrSupported && (!checked || appBridge.upscaleVsrEnabled)) : false
+ enabled: appBridge ? (appBridge.upscaleHdrSupported && (!checked || appBridge.upscaleVsrEnabled || appBridge.upscaleEngine === "DLSS")) : false
onToggled: (c) => { if (appBridge) appBridge.upscaleHdrEnabled = c }
}
@@ -332,12 +377,6 @@ model: appBridge ? appBridge.vsrQualityChoices : []
onValueModified: (v) => { if (appBridge) appBridge.upscaleImageQuality = Math.round(v) }
}
- AppCheckBox {
- label: "Preserve EXIF Metadata"
- checked: appBridge ? appBridge.upscaleImagePreserveMetadata : true
- onToggled: (c) => { if (appBridge) appBridge.upscaleImagePreserveMetadata = c }
- }
-
}
Column {
diff --git a/src/desktop/state.py b/src/desktop/state.py
index 2df241f..79e5e10 100644
--- a/src/desktop/state.py
+++ b/src/desktop/state.py
@@ -45,6 +45,7 @@ class PreviewState:
source_width: int = 0
source_height: int = 0
source_fps: float = 0.0
+ source_hdr: bool = False
duration_seconds: float = 0.0
output_width: int = 0
output_height: int = 0
diff --git a/src/desktop/workflow.py b/src/desktop/workflow.py
new file mode 100644
index 0000000..8d1681d
--- /dev/null
+++ b/src/desktop/workflow.py
@@ -0,0 +1,883 @@
+"""Ordered, file-backed Neural Rendering workflow shared by preview and export."""
+
+from __future__ import annotations
+
+import subprocess
+import shutil
+import tempfile
+import time
+from dataclasses import dataclass, replace
+from pathlib import Path
+
+import numpy as np
+
+from ..core import app_log, ffmpeg
+from ..core.batch_progress import BatchProgress
+from ..core.cache_cleanup import prune_preview_cache
+from ..core.disk_paths import OutputFile, prepare_output_dir
+from ..core.dlss_modes import dlss_output_size
+from ..core.ffmpeg.audio import plan_audio_streams
+from ..core.ffmpeg.encoder import _codec_command
+from ..core.gpu_detection import detect_gpus
+from ..core.jobs import Cancelled, JobController
+from ..core.naming import output_filename, unique_output_path
+from ..core.paths import (FFMPEG, JOBS, OUTPUTS, PREVIEW_CACHE,
+ DLSSSR_BRIDGE, DLSSSR_RUNTIME, DLSSNR_BRIDGE,
+ DLSSNR_CALLER_SHIM, DLSSG_DIR, RUNTIME,
+ NEURAL_RUNTIME)
+from ..core.nr_composition import mask_selection
+from ..core.runtime import resolve_output_size
+from ..frame_interpolation.models import FrameInterpolationOptions, resolve_target_rate
+from ..frame_interpolation.processor import interpolate_video
+from ..neural_rendering.image.batch import convert_images
+from ..neural_rendering.image.decoder import _open_pillow_source, decode_image
+from ..neural_rendering.image.encoder import _encode_image
+from ..neural_rendering.image.models import IMAGE_EXTENSIONS, ImageConversionOptions
+from ..neural_rendering.video.models import ConversionOptions
+from ..neural_rendering.video.processor import convert_video
+from ..settings.models import (UISettings, IMAGE_SCALING_FILTERS, VIDEO_SCALING_FILTERS,
+ IMAGE_16BIT_FORMATS,
+ validate_stage_layout)
+from ..upscale.image.models import options_from_settings as image_upscale_options, output_size as image_upscale_size
+from ..upscale.image.processor import upscale_image
+from ..upscale.video.models import options_from_settings as video_upscale_options, output_size as video_upscale_size
+from ..upscale.video.processor import upscale_video
+from .coloring import (apply_cube_lut, compose_cube_lut, has_lut_adjustments,
+ identity_cube_lut, load_cube_lut, match_image_colors, save_cube_lut)
+from .cas_sharpening import sharpen_image, sharpen_video
+from .denoising import denoise_image, denoise_video
+from .preview_cache import PreviewStageCache, cache_key, file_identity, optional_file_identity
+
+
+LOSSLESS_VIDEO = "FFV1 Lossless RGB 10-bit"
+STAGE_LABELS = {
+ "denoising": "Denoising",
+ "neural_model": "DLSS Neural Rendering",
+ "scale_method": "Scaling",
+ "dlss_super_resolution": "DLSS Super Resolution",
+ "super_resolution": "RTX Super Resolution",
+ "frame_generation": "DLSS Frame Generation",
+ "coloring": "Coloring",
+ "cas_sharpening": "Sharpening",
+}
+
+
+_NR_FIELDS = (
+ "nr_style", "nr_intensity", "nr_passes", "local_tone_strength",
+ "local_structure_strength", "skin_structure_strength", "nr_color_strength",
+ "tone_preservation", "face_skin_protection", "grain_preservation",
+ "mask_feather", "automatic_mask",
+)
+_LUT_FIELDS = (
+ "lut_resolution", "lut_mix", "lut_exposure", "lut_contrast",
+ "lut_highlights", "lut_shadows", "lut_whites", "lut_blacks",
+ "lut_midtones", "lut_temperature", "lut_tint", "lut_hue",
+ "lut_vibrance", "lut_saturation",
+)
+_IMAGE_VSR_FIELDS = (
+ "upscale_image_vsr_quality", "upscale_image_size_mode",
+ "upscale_image_scale_factor", "upscale_image_width",
+ "upscale_image_height", "upscale_image_aspect_lock",
+)
+_VIDEO_VSR_FIELDS = (
+ "upscale_vsr_enabled", "upscale_vsr_quality", "upscale_size_mode",
+ "upscale_scale_factor", "upscale_width", "upscale_height",
+ "upscale_aspect_lock", "upscale_hdr_enabled", "upscale_hdr_contrast",
+ "upscale_hdr_saturation", "upscale_hdr_middle_gray",
+ "upscale_hdr_peak_luminance", "upscale_hdr_precision",
+)
+
+
+def _preview_runtime_identity() -> list[dict | None]:
+ # A replaced processing engine must never inherit intermediates produced
+ # by the previous engine, including when the app is updated in place.
+ source_root = Path(__file__).resolve().parents[1]
+ return [optional_file_identity(path) for path in
+ (Path(__file__), Path(__file__).with_name("coloring.py"),
+ Path(__file__).with_name("denoising.py"),
+ Path(__file__).with_name("cas_sharpening.py"),
+ Path(__file__).with_name("nis_sharpening.py"),
+ source_root / "core" / "dlss_bridge.py",
+ source_root / "upscale" / "image" / "processor.py",
+ source_root / "upscale" / "video" / "processor.py",
+ source_root / "neural_rendering" / "image" / "batch.py",
+ source_root / "neural_rendering" / "video" / "processor.py",
+ source_root / "frame_interpolation" / "processor.py",
+ FFMPEG, DLSSSR_BRIDGE, DLSSSR_RUNTIME, DLSSNR_BRIDGE,
+ DLSSNR_CALLER_SHIM, NEURAL_RUNTIME,
+ RUNTIME / "rtx_video" / "neuroframe_engine_upscaling.dll",
+ RUNTIME / "rtx_video" / "nvngx_vsr.dll",
+ RUNTIME / "rtx_video" / "nvngx_truehdr.dll",
+ DLSSG_DIR / "nvngx_dlssg.dll")]
+
+
+def _stage_cache_settings(settings: UISettings, mode: str, stage: str, hdr: bool) -> dict:
+ """Only settings consumed by this card belong to its cache key."""
+ fields: tuple[str, ...]
+ extras: dict = {}
+ if stage == "denoising":
+ fields = ("denoise_strength", "denoise_deblock")
+ if mode == "Video":
+ fields += ("denoise_temporal",)
+ elif stage == "cas_sharpening":
+ fields = ("cas_sharpness", "sharpening_method")
+ elif stage == "neural_model":
+ fields = _NR_FIELDS + (("shimmer_suppression", "video_gpu_uuid") if mode == "Video" else ())
+ fields += ("ai_gpu_uuid",)
+ selected_mask = mask_selection(settings.nr_mask)
+ extras["mask"] = (None if selected_mask is None else
+ {**selected_mask.state(), "file": file_identity(selected_mask.path)})
+ extras["hdr_input"] = hdr
+ elif stage == "scale_method":
+ fields = ("upscaling_factor", "image_scaling_filter" if mode == "Image"
+ else "video_scaling_filter")
+ elif stage == "dlss_super_resolution":
+ fields = (("upscale_image_dlss_mode", "upscale_image_dlss_preset", "ai_gpu_uuid")
+ if mode == "Image" else
+ ("upscale_dlss_mode", "upscale_dlss_preset", "ai_gpu_uuid", "video_gpu_uuid"))
+ elif stage == "super_resolution":
+ fields = (("ai_gpu_uuid",) + _IMAGE_VSR_FIELDS if mode == "Image" else
+ ("ai_gpu_uuid", "video_gpu_uuid") + _VIDEO_VSR_FIELDS)
+ elif stage == "frame_generation":
+ fields = ("frame_interpolation_target_fps", "frame_interpolation_engine",
+ "ai_gpu_uuid", "video_gpu_uuid")
+ extras["hdr_input"] = hdr
+ elif stage == "coloring":
+ fields = _LUT_FIELDS if mode == "Video" or settings.coloring_mode == "LUT" else ()
+ if mode == "Image":
+ fields += ("coloring_mode",)
+ if settings.coloring_mode == "Color Match":
+ fields += ("color_match_source",)
+ if settings.color_match_source == "Selected Image":
+ extras["reference"] = file_identity(settings.color_match_reference)
+ else:
+ extras["lut"] = (file_identity(settings.lut_path) if settings.lut_path else None)
+ else:
+ extras["lut"] = (file_identity(settings.lut_path) if settings.lut_path else None)
+ else:
+ raise ValueError(f"Unknown processing card: {stage}")
+ return {**{name: getattr(settings, name) for name in fields}, **extras}
+
+
+def _video_scaling_filter(width: int, height: int, method: str) -> tuple[list[str], str]:
+ """Return FFmpeg device arguments and the exact requested scaler."""
+ if method == "Spline36":
+ return [], f"format=gbrp10le,zscale=w={width}:h={height}:filter=spline36:matrixin=gbr:matrix=gbr"
+ if method == "EWA Lanczos":
+ return ["-init_hw_device", "vulkan=vk:0", "-filter_hw_device", "vk"], (
+ "format=gbrp10le,hwupload,"
+ f"libplacebo=w={width}:h={height}:upscaler=ewa_lanczos:downscaler=ewa_lanczos,"
+ "hwdownload,format=gbrp10le"
+ )
+ flags = {"Lanczos": "lanczos", "Bicubic": "bicubic", "Area": "area", "Bilinear": "bilinear"}
+ if method not in flags:
+ raise ValueError(f"Unknown video scaling filter: {method!r}.")
+ return [], f"scale={width}:{height}:flags={flags[method]}"
+
+
+@dataclass(frozen=True)
+class PipelineEstimate:
+ width: int
+ height: int
+ fps: float
+ hdr: bool
+
+
+@dataclass(frozen=True)
+class PipelineSuccess:
+ input_path: str
+ output_path: str
+
+
+@dataclass(frozen=True)
+class PipelineFailure:
+ input_path: str
+ error: str
+ cancelled: bool = False
+
+
+@dataclass(frozen=True)
+class PipelineBatchResult:
+ successes: list[PipelineSuccess]
+ failures: list[PipelineFailure]
+ cancelled: bool
+
+
+def enabled_stages(settings: UISettings, mode: str) -> tuple[str, ...]:
+ order = settings.image_stage_order if mode == "Image" else settings.video_stage_order
+ enabled = settings.image_enabled_stages if mode == "Image" else settings.video_enabled_stages
+ validate_stage_layout(order, enabled, video=mode == "Video")
+ return tuple(stage for stage in order if stage in enabled)
+
+
+def estimate_pipeline(width: int, height: int, fps: float, hdr: bool,
+ settings: UISettings, mode: str) -> PipelineEstimate:
+ """Preflight every enabled stage in its actual execution order."""
+ if width < 1 or height < 1:
+ raise ValueError("Input dimensions are unavailable.")
+ if mode == "Video" and fps <= 0:
+ raise ValueError("Input frame rate is unavailable; video export needs a known FPS.")
+ for stage in enabled_stages(settings, mode):
+ if stage == "denoising":
+ pass # Pixel size, frame rate and HDR flags are preserved.
+ elif stage == "cas_sharpening":
+ if mode == "Video" and hdr and settings.cas_sharpness:
+ raise ValueError("Sharpening requires SDR video at this position. Move it before HDR conversion.")
+ elif stage == "neural_model":
+ if min(width, height) < 64:
+ raise ValueError("DLSS Neural Rendering requires at least 64×64 input.")
+ resolve_output_size(width, height, 1.0)
+ elif stage == "scale_method":
+ selected_filter = settings.image_scaling_filter if mode == "Image" else settings.video_scaling_filter
+ choices = IMAGE_SCALING_FILTERS if mode == "Image" else VIDEO_SCALING_FILTERS
+ if selected_filter not in choices:
+ raise ValueError(f"Unknown {mode.lower()} scaling filter: {selected_filter!r}.")
+ if mode == "Video" and hdr:
+ raise ValueError("Scaling cannot process HDR video at this position. Move it before HDR conversion.")
+ width, height = resolve_output_size(width, height, settings.upscaling_factor)
+ elif stage == "dlss_super_resolution":
+ if mode == "Video" and hdr:
+ raise ValueError("DLSS Super Resolution cannot process HDR video at this position. Move it before HDR conversion.")
+ dlss_mode = settings.upscale_image_dlss_mode if mode == "Image" else settings.upscale_dlss_mode
+ width, height = dlss_output_size(width, height, dlss_mode, even=mode == "Video")
+ elif stage == "super_resolution":
+ if mode == "Image":
+ options = replace(image_upscale_options(settings), engine="RTX Video Super Resolution")
+ width, height = image_upscale_size(width, height, options)
+ else:
+ if hdr:
+ raise ValueError("RTX Super Resolution cannot process HDR video at this position. Move it before HDR conversion.")
+ opts = replace(video_upscale_options(settings), engine="RTX Video Super Resolution",
+ codec=LOSSLESS_VIDEO,
+ container="MKV", quality="Auto (Default)")
+ opts.validate(for_render=True)
+ width, height, _ = video_upscale_size(width, height, opts)
+ hdr = opts.hdr_enabled
+ elif stage == "frame_generation":
+ if mode != "Video":
+ raise ValueError("DLSS Frame Generation accepts video only.")
+ target_fps = float(resolve_target_rate(settings.frame_interpolation_target_fps))
+ if fps <= 0:
+ raise ValueError("Frame Generation requires a known input frame rate.")
+ if target_fps <= fps:
+ raise ValueError(
+ f"DLSS Frame Generation target {target_fps:g} FPS must exceed the "
+ f"{fps:g} FPS entering this card. Choose a higher target FPS."
+ )
+ fps = target_fps
+ elif stage == "coloring":
+ if mode == "Video" or settings.coloring_mode == "LUT":
+ if settings.lut_path and not Path(settings.lut_path).is_file():
+ raise ValueError("The selected .cube LUT is unavailable.")
+ elif settings.color_match_source == "Selected Image":
+ if not settings.color_match_reference:
+ raise ValueError("Choose a reference image in Coloring before rendering.")
+ if not Path(settings.color_match_reference).is_file():
+ raise ValueError("The selected Color Match reference image is unavailable.")
+ else:
+ raise ValueError(f"Unknown processing card: {stage}")
+ if mode == "Video":
+ if (width % 2 or height % 2) and settings.codec != LOSSLESS_VIDEO:
+ raise ValueError(
+ f"Video export requires even dimensions; this sequence ends at {width}×{height}. "
+ "Choose an even output size in Scaling, DLSS Super Resolution, or RTX Super Resolution."
+ )
+ if hdr and not settings.hdr_mode:
+ raise ValueError("HDR output requires 10-bit HDR Mode in Export Settings.")
+ if hdr and not ffmpeg.hdr_mode_supported(settings.codec):
+ raise ValueError("HDR output requires a 10-bit capable codec in Export Settings.")
+ ffmpeg.validate_codec_container(settings.codec, ffmpeg.container_for_codec(settings.codec))
+ return PipelineEstimate(width, height, fps, hdr)
+
+
+def preflight_source(source: Path, settings: UISettings, mode: str) -> PipelineEstimate:
+ if not source.is_file():
+ raise FileNotFoundError(source)
+ if "coloring" in enabled_stages(settings, mode) and (mode == "Video" or settings.coloring_mode == "LUT"):
+ if settings.lut_path:
+ load_cube_lut(settings.lut_path)
+ if mode == "Image":
+ if ("coloring" in enabled_stages(settings, mode)
+ and settings.coloring_mode == "Color Match"
+ and settings.color_match_source == "Selected Image"):
+ if not settings.color_match_reference:
+ raise ValueError("Choose a reference image in Coloring before rendering.")
+ reference = Path(settings.color_match_reference)
+ if not reference.is_file():
+ raise ValueError(f"Color Match reference image is unavailable: {reference}")
+ try:
+ reference_image, _ = _open_pillow_source(reference)
+ reference_image.close()
+ except Exception as exc:
+ raise ValueError(f"Color Match reference image cannot be opened: {reference}") from exc
+ image, _ = _open_pillow_source(source)
+ try:
+ width, height = image.size
+ if image.getexif().get(274) in {5, 6, 7, 8}:
+ width, height = height, width
+ finally:
+ image.close()
+ return estimate_pipeline(width, height, 0.0, False, settings, mode)
+ native_fg = ("frame_generation" in enabled_stages(settings, mode)
+ and settings.frame_interpolation_engine == "Native DLSSG")
+ metadata = ffmpeg.probe_video(source, count_mode="metadata",
+ inspect_timestamps=native_fg)
+ result = estimate_pipeline(int(metadata["width"]), int(metadata["height"]),
+ float(metadata["fps"]), bool(metadata.get("hdr")), settings, mode)
+ if "(NVIDIA NVENC)" in settings.codec:
+ ffmpeg.resolve_video_gpu(detect_gpus(), settings.video_gpu_uuid,
+ settings.codec, result.width, result.height)
+ if native_fg:
+ from ..frame_interpolation.capabilities import probe_frame_interpolation_capabilities
+ from ..frame_interpolation.scheduler import choose_interpolation_plan
+
+ caps = probe_frame_interpolation_capabilities(settings.ai_gpu_uuid)
+ if not caps.available:
+ raise ValueError("DLSS Frame Generation is unavailable. " + caps.detail)
+ choose_interpolation_plan(metadata["rate"],
+ resolve_target_rate(settings.frame_interpolation_target_fps),
+ settings.frame_interpolation_engine,
+ caps.native_multiplier, cfr=bool(metadata["cfr"]))
+ return result
+
+
+def preflight_capabilities(settings: UISettings, mode: str,
+ controller: JobController | None = None,
+ stages_override: tuple[str, ...] | None = None) -> None:
+ """Reject unavailable processing hardware before writing any stage output."""
+ stages = stages_override if stages_override is not None else enabled_stages(settings, mode)
+ if not stages:
+ return
+ needs_ai_gpu = bool(set(stages) & {"neural_model", "dlss_super_resolution", "super_resolution", "frame_generation"})
+ if needs_ai_gpu:
+ from ..core.gpu_selection import detect_gpu
+
+ detect_gpu(settings.ai_gpu_uuid)
+ if mode == "Video" and "scale_method" in stages and settings.video_scaling_filter == "EWA Lanczos":
+ device_args, filter_graph = _video_scaling_filter(64, 64, "EWA Lanczos")
+ try:
+ _run_command([str(FFMPEG), "-hide_banner", "-loglevel", "error",
+ *device_args, "-f", "lavfi", "-i", "testsrc2=size=64x64:rate=1:duration=1",
+ "-vf", filter_graph, "-frames:v", "1", "-f", "null", "-"],
+ controller or JobController(), "EWA Lanczos capability check")
+ except RuntimeError as exc:
+ raise ValueError("EWA Lanczos requires FFmpeg libplacebo and an available Vulkan device.") from exc
+ if "super_resolution" in stages:
+ vsr = mode == "Image" or settings.upscale_vsr_enabled
+ hdr = mode == "Video" and settings.upscale_hdr_enabled
+ if vsr or hdr:
+ from ..upscale.video.native import probe_capabilities
+
+ caps = probe_capabilities(settings.ai_gpu_uuid, controller=controller)
+ if vsr and not caps.vsr.get("available"):
+ raise ValueError("RTX Super Resolution requires an available RTX Video Super Resolution runtime.")
+ if hdr and not caps.hdr.get("available"):
+ raise ValueError("RTX Video HDR requires an available RTX Video HDR runtime.")
+ if "frame_generation" in stages:
+ from ..frame_interpolation.capabilities import probe_frame_interpolation_capabilities
+
+ caps = probe_frame_interpolation_capabilities(settings.ai_gpu_uuid)
+ if not caps.available:
+ raise ValueError("DLSS Frame Generation is unavailable. " + caps.detail)
+
+
+def _run_command(command: list[str], controller: JobController, label: str,
+ *, cwd: Path | None = None) -> None:
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ process = subprocess.Popen(command, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
+ cwd=cwd,
+ creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0))
+ controller.register(process)
+ try:
+ while True:
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ try:
+ _, stderr = process.communicate(timeout=0.2)
+ break
+ except subprocess.TimeoutExpired:
+ continue
+ if process.returncode:
+ raise RuntimeError(f"{label} failed: {stderr.decode('utf-8', 'replace')[-2500:]}")
+ finally:
+ if process.poll() is None:
+ process.terminate()
+ try:
+ process.wait(timeout=5)
+ except subprocess.TimeoutExpired:
+ process.kill()
+ process.wait(timeout=5)
+ controller.unregister(process)
+ if process.stderr:
+ process.stderr.close()
+
+
+def _neural_image_options(settings: UISettings) -> ImageConversionOptions:
+ return ImageConversionOptions(
+ ai_gpu_uuid=settings.ai_gpu_uuid, nr_style=settings.nr_style,
+ nr_intensity=settings.nr_intensity, nr_passes=settings.nr_passes,
+ local_tone_strength=settings.local_tone_strength,
+ local_structure_strength=settings.local_structure_strength,
+ skin_structure_strength=settings.skin_structure_strength,
+ nr_color_strength=settings.nr_color_strength,
+ tone_preservation=settings.tone_preservation,
+ face_skin_protection=settings.face_skin_protection,
+ grain_preservation=settings.grain_preservation,
+ mask_feather=settings.mask_feather, nr_mask=settings.nr_mask,
+ automatic_mask=settings.automatic_mask, upscaling_factor=1.0,
+ scale_method="Standard", output_format="TIFF", quality=100,
+ preserve_metadata=False,
+ )
+
+
+def _neural_video_options(settings: UISettings, hdr: bool) -> ConversionOptions:
+ return ConversionOptions(
+ ai_gpu_uuid=settings.ai_gpu_uuid, video_gpu_uuid=settings.video_gpu_uuid,
+ nr_style=settings.nr_style, nr_intensity=settings.nr_intensity,
+ nr_passes=settings.nr_passes, local_tone_strength=settings.local_tone_strength,
+ local_structure_strength=settings.local_structure_strength,
+ skin_structure_strength=settings.skin_structure_strength,
+ nr_color_strength=settings.nr_color_strength,
+ tone_preservation=settings.tone_preservation,
+ face_skin_protection=settings.face_skin_protection,
+ grain_preservation=settings.grain_preservation,
+ shimmer_suppression=settings.shimmer_suppression,
+ mask_feather=settings.mask_feather, nr_mask=settings.nr_mask,
+ automatic_mask=settings.automatic_mask, upscaling_factor=1.0,
+ scale_method="Standard", codec=LOSSLESS_VIDEO, container="MKV",
+ quality="Auto (Default)", preserve_hdr=hdr,
+ )
+
+
+def _image_stage(source: Path, stage: str, settings: UISettings,
+ directory: Path, controller: JobController, progress) -> Path:
+ if stage == "denoising":
+ return denoise_image(source, settings, directory, controller, progress, _run_command)
+ if stage == "cas_sharpening":
+ return sharpen_image(source, settings, directory, controller, progress)
+ if stage == "neural_model":
+ result = convert_images([source], _neural_image_options(settings), progress,
+ output_dir=directory, controller=controller,
+ generate_previews=False, create_zip=False)
+ if result.failures:
+ raise RuntimeError(result.failures[0].error)
+ return Path(result.successes[0].output_path)
+ if stage == "scale_method":
+ from ..core.runtime import resize_fit
+ decoded = decode_image(source)
+ height, width = decoded.rgba.shape[:2]
+ target_width, target_height = resolve_output_size(width, height, settings.upscaling_factor)
+ output = directory / "scaled.tiff"
+ _encode_image(output, resize_fit(decoded.rgba, target_width, target_height,
+ interpolation=settings.image_scaling_filter),
+ ImageConversionOptions(output_format="TIFF", preserve_metadata=False),
+ {}, generate_preview=False, controller=controller,
+ has_transparency=decoded.alpha is not None)
+ return output
+ opts = replace(image_upscale_options(settings),
+ engine="DLSS" if stage == "dlss_super_resolution" else "RTX Video Super Resolution",
+ output_format="TIFF", quality=100)
+ result = upscale_image(source, opts, progress, output_dir=directory,
+ controller=controller, generate_previews=False)
+ return Path(result.output_path)
+
+
+def _coloring_image_stage(current: Path, input_image: Path, settings: UISettings,
+ directory: Path, controller: JobController, progress) -> Path:
+ rendered = decode_image(current)
+ if settings.coloring_mode == "LUT":
+ lut = load_cube_lut(settings.lut_path) if settings.lut_path else identity_cube_lut()
+ if has_lut_adjustments(settings):
+ lut = compose_cube_lut(lut, settings, settings.lut_resolution)
+ matched = apply_cube_lut(rendered.rgba, lut)
+ message = "Applying LUT"
+ else:
+ reference = (input_image if settings.color_match_source == "Input Image"
+ else Path(settings.color_match_reference))
+ if current.resolve() == reference.resolve():
+ return current
+ target = decode_image(reference)
+ matched = match_image_colors(rendered.rgba, target.rgba)
+ message = "Matching colors"
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ progress(0.8, message)
+ output = directory / "color-matched.tiff"
+ _encode_image(output, matched,
+ ImageConversionOptions(output_format="TIFF", preserve_metadata=False),
+ {}, generate_preview=False, controller=controller,
+ has_transparency=rendered.alpha is not None)
+ progress(1.0, "Coloring complete")
+ return output
+
+
+def _coloring_video_stage(source: Path, settings: UISettings, directory: Path,
+ controller: JobController, progress) -> Path:
+ # Work in the stage directory so FFmpeg can use a simple relative LUT
+ # filename, including when the user's .cube path contains spaces or colons.
+ staged_lut = directory / "reference.cube"
+ if settings.lut_path and not has_lut_adjustments(settings):
+ shutil.copyfile(settings.lut_path, staged_lut)
+ else:
+ save_cube_lut(staged_lut, settings.lut_path or None, settings, controller=controller)
+ load_cube_lut(staged_lut)
+ metadata = ffmpeg.probe_video(source, count_mode="metadata", controller=controller)
+ color_args: list[str] = []
+ for key, flag in (("color_primaries", "-color_primaries"),
+ ("color_transfer", "-color_trc")):
+ value = metadata.get(key)
+ if value and value != "unknown":
+ color_args.extend((flag, str(value)))
+ output = directory / "coloring.mkv"
+ progress(0.1, "Applying LUT to video")
+ _run_command([str(FFMPEG), "-hide_banner", "-loglevel", "error", "-y",
+ "-i", str(source), "-map", "0:v:0", "-map_metadata", "0", "-an",
+ "-vf", "format=gbrp10le,lut3d=file=reference.cube:interp=trilinear,format=gbrp10le",
+ "-c:v", "ffv1", "-level", "3", "-pix_fmt", "gbrp10le",
+ "-fps_mode", "passthrough", *color_args, "-color_range", "pc",
+ str(output)], controller, "Video LUT", cwd=directory)
+ progress(1.0, "LUT complete")
+ return output
+
+
+def _video_stage(source: Path, stage: str, settings: UISettings, hdr: bool,
+ directory: Path, controller: JobController, progress) -> Path:
+ if stage == "denoising":
+ return denoise_video(source, settings, directory, controller, progress, _run_command)
+ if stage == "cas_sharpening":
+ return sharpen_video(source, settings, directory, controller, progress)
+ if stage == "neural_model":
+ result = convert_video(source, _neural_video_options(settings, hdr), progress,
+ output_dir=directory, controller=controller)
+ elif stage == "scale_method":
+ metadata = ffmpeg.probe_video(source, count_mode="metadata", controller=controller)
+ width, height = resolve_output_size(int(metadata["width"]), int(metadata["height"]),
+ settings.upscaling_factor)
+ output = directory / "scaled.mkv"
+ device_args, filter_graph = _video_scaling_filter(width, height, settings.video_scaling_filter)
+ _run_command([str(FFMPEG), "-hide_banner", "-loglevel", "error", "-y",
+ *device_args, "-i", str(source),
+ "-map", "0:v:0", "-map_metadata", "0", "-vf", filter_graph, "-c:v", "ffv1",
+ "-level", "3", "-pix_fmt", "gbrp10le", str(output)],
+ controller, f"{settings.video_scaling_filter} scaling")
+ return output
+ elif stage in {"dlss_super_resolution", "super_resolution"}:
+ opts = video_upscale_options(settings)
+ opts = replace(opts, engine="DLSS" if stage == "dlss_super_resolution"
+ else "RTX Video Super Resolution",
+ hdr_enabled=False if stage == "dlss_super_resolution" else opts.hdr_enabled)
+ opts = replace(opts, codec=LOSSLESS_VIDEO, container="MKV", quality="Auto (Default)")
+ result = upscale_video(source, opts, progress, output_dir=directory, controller=controller)
+ elif stage == "frame_generation":
+ opts = FrameInterpolationOptions(
+ ai_gpu_uuid=settings.ai_gpu_uuid, video_gpu_uuid=settings.video_gpu_uuid,
+ target_fps=settings.frame_interpolation_target_fps,
+ engine=settings.frame_interpolation_engine,
+ codec=LOSSLESS_VIDEO, container="MKV", quality="Auto (Default)",
+ hdr_mode=hdr,
+ )
+ result = interpolate_video(source, opts, progress, output_dir=directory,
+ controller=controller)
+ else:
+ raise ValueError(f"Unknown video processing card: {stage}")
+ return Path(result.output_path)
+
+
+def _image_at_bit_depth(rgba: np.ndarray, settings: UISettings) -> np.ndarray:
+ """Convert the processed pixels to the requested delivery depth."""
+ depth = settings.image_bit_depth
+ if depth == 16:
+ if settings.image_format not in IMAGE_16BIT_FORMATS:
+ raise ValueError("16-bit image output is available for PNG and TIFF only.")
+ if rgba.dtype == np.uint8:
+ return rgba.astype(np.uint16) * 257
+ return rgba
+ if depth == 8:
+ if rgba.dtype == np.uint16:
+ return ((rgba.astype(np.uint32) + 128) // 257).astype(np.uint8)
+ return rgba
+ raise ValueError("Image bit depth must be 8 or 16 bits.")
+
+
+def _export_image(current: Path, destination: Path,
+ settings: UISettings, controller: JobController) -> None:
+ rendered = decode_image(current)
+ pixels = _image_at_bit_depth(rendered.rgba, settings)
+ opts = ImageConversionOptions(output_format=settings.image_format,
+ quality=settings.image_quality,
+ preserve_metadata=False)
+ output = OutputFile(destination)
+ try:
+ _encode_image(output.temporary, pixels, opts, {},
+ generate_preview=False, controller=controller,
+ has_transparency=rendered.alpha is not None)
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ output.publish()
+ finally:
+ output.cleanup()
+
+
+def _export_video(source: Path, current: Path, destination: Path,
+ settings: UISettings, controller: JobController,
+ *, preview: bool = False, pipeline_hdr: bool = False) -> None:
+ metadata = ffmpeg.probe_video(current, count_mode="metadata", controller=controller)
+ width, height = int(metadata["width"]), int(metadata["height"])
+ codec = "H.264" if preview else settings.codec
+ quality = "Best" if preview else settings.quality
+ container = "MP4" if preview else ffmpeg.container_for_codec(codec)
+ current_hdr = bool(metadata.get("hdr")) or pipeline_hdr
+ hdr = current_hdr and not preview
+ source_metadata = ffmpeg.probe_video(source, count_mode="metadata", controller=controller)
+ encode_metadata = dict(metadata)
+ # FFV1 RGB intermediates report matrix=gbr. Delivery codecs need the
+ # original YUV matrix, or BT.2020 for HDR created by Super Resolution.
+ if metadata.get("color_space") == "gbr" and codec != LOSSLESS_VIDEO:
+ encode_metadata["color_space"] = "bt2020nc" if hdr else (
+ source_metadata.get("color_space")
+ if source_metadata.get("color_space") not in {None, "", "unknown", "gbr"}
+ else "bt709"
+ )
+ encode_metadata["color_range"] = "tv"
+ if hdr:
+ encode_metadata["color_primaries"] = "bt2020"
+ encode_metadata["color_transfer"] = "smpte2084"
+ encode_metadata["color_space"] = "bt2020nc"
+ elif preview and current_hdr:
+ encode_metadata.update(color_space="bt709", color_primaries="bt709",
+ color_transfer="bt709", color_range="tv")
+ tone_map = None
+ if preview and current_hdr:
+ tone_map = (
+ "zscale=matrixin=gbr:primariesin=bt2020:transferin=smpte2084:rangein=full:"
+ "transfer=linear:npl=100,format=gbrpf32le,zscale=primaries=bt709,"
+ "tonemap=mobius:desat=2:peak=10,zscale=transfer=bt709:matrix=bt709:"
+ "range=limited,format=yuv420p"
+ )
+ gpu = ffmpeg.resolve_video_gpu(detect_gpus(), settings.video_gpu_uuid,
+ codec, width, height)
+ codec_args, _, _ = _codec_command(codec, quality, width, height,
+ float(metadata["fps"]),
+ None if gpu is None else int(gpu["cuda_ordinal"]),
+ hdr_mode=hdr, hdr_metadata=encode_metadata,
+ speed_profile="preview" if preview else "default")
+ audio = plan_audio_streams(source, container, controller)
+ output = OutputFile(destination)
+ try:
+ command = [str(FFMPEG), "-hide_banner", "-loglevel", "error", "-y",
+ "-i", str(current), "-i", str(source),
+ "-map", "0:v:0", "-map", "1:a?", "-map_metadata", "1",
+ "-map_chapters", "1", *codec_args,
+ *(["-vf", tone_map, "-color_primaries", "bt709", "-color_trc", "bt709",
+ "-colorspace", "bt709", "-color_range", "tv"] if tone_map else []),
+ *audio.encoder_args(), "-fps_mode", "passthrough",
+ "-t", f"{max(float(metadata.get('duration') or 0), 1 / float(metadata['fps'])):.9f}",
+ str(output.temporary)]
+ _run_command(command, controller, "Video export")
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ output.publish()
+ finally:
+ output.cleanup()
+
+
+def render_item(source: Path, settings: UISettings, mode: str, destination: Path,
+ controller: JobController, progress=None, *, preview: bool = False,
+ capabilities_checked: bool = False,
+ preview_cache: PreviewStageCache | None = None,
+ source_cache_key: str | None = None) -> str:
+ preflight_source(source, settings, mode)
+ if not capabilities_checked and preview_cache is None:
+ preflight_capabilities(settings, mode, controller)
+ stages = enabled_stages(settings, mode)
+ upstream_key = (source_cache_key or cache_key({"kind": "source", "mode": mode,
+ "source": file_identity(source)})) if preview_cache else ""
+ JOBS.mkdir(parents=True, exist_ok=True)
+ with tempfile.TemporaryDirectory(prefix="visual-workflow-", dir=JOBS) as temp:
+ current = source
+ hdr = False
+ if mode == "Video":
+ hdr = bool(ffmpeg.probe_video(source, count_mode="metadata", controller=controller).get("hdr"))
+ for index, stage in enumerate(stages):
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ stage_key = (cache_key({"kind": "stage", "mode": mode, "upstream": upstream_key,
+ "stage": stage,
+ "settings": _stage_cache_settings(settings, mode, stage, hdr)})
+ if preview_cache else "")
+ if preview_cache:
+ cached = preview_cache.lookup(stage_key, current)
+ if cached is not None:
+ current = cached
+ if progress:
+ progress((index + 1) / (len(stages) + 1),
+ f"{STAGE_LABELS[stage]}: using Smart cache")
+ upstream_key = stage_key
+ if stage == "super_resolution" and mode == "Video":
+ hdr = bool(settings.upscale_hdr_enabled)
+ continue
+ directory = Path(temp) / f"{index:02d}-{stage}"
+ directory.mkdir()
+ stage_input = current
+ if preview_cache and not capabilities_checked:
+ preflight_capabilities(settings, mode, controller, (stage,))
+ def report(value, message, i=index, name=stage):
+ if progress:
+ progress((i + max(0.0, min(1.0, float(value)))) / (len(stages) + 1),
+ f"{STAGE_LABELS[name]}: {message}")
+ if stage == "coloring":
+ current = (_coloring_image_stage(current, source, settings, directory, controller, report)
+ if mode == "Image" else
+ _coloring_video_stage(current, settings, directory, controller, report))
+ elif mode == "Image":
+ current = _image_stage(current, stage, settings, directory, controller, report)
+ else:
+ current = _video_stage(current, stage, settings, hdr, directory, controller, report)
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ if preview_cache:
+ current = preview_cache.publish(stage_key, directory, current,
+ previous=stage_input)
+ upstream_key = stage_key
+ if stage == "super_resolution" and mode == "Video":
+ hdr = bool(settings.upscale_hdr_enabled)
+ if progress:
+ progress(len(stages) / (len(stages) + 1), "Exporting result")
+ destination.parent.mkdir(parents=True, exist_ok=True)
+ if mode == "Image":
+ _export_image(current, destination, settings, controller)
+ else:
+ _export_video(source, current, destination, settings, controller,
+ preview=preview, pipeline_hdr=hdr)
+ if progress:
+ progress(1.0, "Export complete")
+ return str(destination)
+
+
+def render_pipeline_batch(input_paths, settings: UISettings, mode: str,
+ progress=None, *, output_dir=None, controller=None,
+ on_item_update=None, same_as_input=False) -> PipelineBatchResult:
+ paths = [Path(path).resolve() for path in input_paths]
+ if not paths:
+ raise ValueError("Add a file before rendering.")
+ controller = controller or JobController()
+ for path in paths:
+ preflight_source(path, settings, mode)
+ preflight_capabilities(settings, mode, controller)
+ reporter = BatchProgress(paths, on_item_update, progress)
+ successes: list[PipelineSuccess] = []
+ failures: list[PipelineFailure] = []
+ reserved: set[Path] = set()
+ stamp = time.strftime("%Y%m%d-%H%M%S")
+ try:
+ for index, path in enumerate(paths):
+ if controller.cancel.is_set():
+ break
+ reporter.advance(index, 0.0, "Preparing pipeline")
+ folder = prepare_output_dir(path.parent if same_as_input else output_dir, default=OUTPUTS)
+ extension = (IMAGE_EXTENSIONS[settings.image_format] if mode == "Image" else
+ {"MP4": ".mp4", "MKV": ".mkv", "MOV": ".mov"}[ffmpeg.container_for_codec(settings.codec)])
+ rename_mode = settings.image_rename_mode if mode == "Image" else settings.video_rename_mode
+ suffix = settings.image_custom_suffix if mode == "Image" else settings.video_custom_suffix
+ output = unique_output_path(folder / output_filename(
+ path, extension, rename_mode, suffix, f"{path.stem}_Pipeline_{stamp}"), reserved)
+ reserved.add(output)
+ try:
+ rendered = render_item(path, settings, mode, output, controller,
+ lambda value, message, i=index: reporter.advance(i, value, message),
+ capabilities_checked=True)
+ except Exception as exc:
+ cancelled = isinstance(exc, Cancelled) or controller.cancel.is_set()
+ failures.append(PipelineFailure(str(path), str(exc), cancelled))
+ reporter.fail(index, exc, cancelled=cancelled)
+ if cancelled:
+ controller.stop()
+ break
+ else:
+ successes.append(PipelineSuccess(str(path), rendered))
+ reporter.complete(index, rendered)
+ if controller.cancel.is_set():
+ reporter.skip_from(0)
+ reporter.finish(cancelled=controller.cancel.is_set(), manifest_path=app_log.session_path())
+ return PipelineBatchResult(successes, failures, controller.cancel.is_set())
+ except BaseException as exc:
+ reporter.finish(cancelled=controller.cancel.is_set(), error=str(exc))
+ raise
+
+
+def render_pipeline_preview(source: str, settings: UISettings, mode: str, *,
+ output_dir: Path, controller=None, progress=None,
+ start_seconds: float = 0.0,
+ clip_seconds: float | None = None,
+ cache_dir: Path = PREVIEW_CACHE) -> tuple[str, str]:
+ controller = controller or JobController()
+ source_path = Path(source).resolve()
+ preflight_source(source_path, settings, mode)
+ if mode == "Image" and not enabled_stages(settings, mode):
+ decoded = decode_image(source_path)
+ return decoded.rgba, "Source preview (all processing cards are off)."
+ stage_cache = PreviewStageCache(cache_dir)
+ root_key = cache_key({"kind": "source", "mode": mode,
+ "source": file_identity(source_path),
+ "runtime": _preview_runtime_identity()})
+ output_dir = prepare_output_dir(output_dir)
+ if mode == "Image":
+ output = unique_output_path(output_dir / f"pipeline-preview-{time.time_ns()}.png")
+ preview_settings = replace(settings, image_format="PNG", image_quality=100)
+ path = render_item(source_path, preview_settings, mode, output, controller, progress,
+ preview=True,
+ preview_cache=stage_cache, source_cache_key=root_key)
+ prune_preview_cache(root=stage_cache.root, protected_keys=stage_cache.used_keys,
+ min_idle_seconds=0)
+ return path, "Pipeline image preview complete."
+ with tempfile.TemporaryDirectory(prefix="visual-preview-source-", dir=JOBS) as temp:
+ clip_key = cache_key({"kind": "source-clip", "source": root_key,
+ "start_seconds": float(start_seconds),
+ "clip_seconds": None if clip_seconds is None else float(clip_seconds)})
+ clip = stage_cache.lookup(clip_key)
+ if clip is None:
+ clip_dir = Path(temp) / "source-clip"
+ clip_dir.mkdir()
+ clip = _extract_lossless_preview_clip(source_path, clip_dir, controller,
+ start_seconds, clip_seconds)
+ if controller.cancel.is_set():
+ raise Cancelled("Render stopped by user.")
+ clip = stage_cache.publish(clip_key, clip_dir, clip)
+ elif progress:
+ progress(0.0, "Using cached source clip")
+ output = unique_output_path(output_dir / f"pipeline-preview-{time.time_ns()}.mp4")
+ render_item(clip, settings, mode, output, controller, progress, preview=True,
+ preview_cache=stage_cache,
+ source_cache_key=clip_key)
+ prune_preview_cache(root=stage_cache.root, protected_keys=stage_cache.used_keys,
+ min_idle_seconds=0)
+ return str(output), "Pipeline video preview complete."
+
+
+def _extract_lossless_preview_clip(source: Path, directory: Path,
+ controller: JobController, start_seconds: float,
+ clip_seconds: float | None) -> Path:
+ """Frame-accurate clip cut without changing pixels before the first card."""
+ metadata = ffmpeg.probe_video(source, count_mode="metadata", controller=controller)
+ start = max(0.0, float(start_seconds or 0.0) - 0.002)
+ fast_seek = max(0.0, start - 2.0)
+ accurate_seek = max(0.0, start - fast_seek)
+ output = directory / "source-clip.mkv"
+ color_args: list[str] = []
+ for key, flag in (("color_primaries", "-color_primaries"),
+ ("color_transfer", "-color_trc"),
+ ("color_space", "-colorspace")):
+ value = metadata.get(key)
+ if value and value != "unknown":
+ color_args.extend((flag, str(value)))
+ command = [str(FFMPEG), "-hide_banner", "-loglevel", "error", "-y",
+ "-ss", f"{fast_seek:.6f}", "-i", str(source),
+ "-ss", f"{accurate_seek:.6f}",
+ *(["-frames:v", "1"] if clip_seconds is None else
+ ["-t", f"{float(clip_seconds):.6f}"]),
+ "-map", "0:v:0", "-map_metadata", "0", "-an",
+ "-c:v", "ffv1", "-level", "3", "-pix_fmt", "gbrp10le",
+ *color_args, str(output)]
+ _run_command(command, controller, "Preview clip extraction")
+ return output
diff --git a/src/live/pipeline.py b/src/live/pipeline.py
index c8507e1..cb892e2 100644
--- a/src/live/pipeline.py
+++ b/src/live/pipeline.py
@@ -21,7 +21,8 @@ from av.codec.hwaccel import HWAccel
from ..core.gpu_selection import resolve_runtime_ai_gpu
from ..core.jobs import BoundedLogBuffer, Cancelled, JobController, active_job, drain_bounded_text
-from ..core import app_log
+from ..core import app_log
+from ..core.ffmpeg import chroma_location_code, decoded_rgba
from ..core.paths import FFMPEG, LIVE_DIR
from ..core.runtime import (DLSSFrameSession, prepare_runtime, resolve_native_settings,
resolve_output_size, resolve_upscaling_mode, resize_fit,
@@ -155,11 +156,9 @@ class LiveSession(threading.Thread):
native = None
try:
with NativeDeadline(self.controller, EFFECT_REPLACEMENT_TIMEOUT) as deadline:
- # The replacement session must match the running path: CUDA
- # branch native_args carry cuda_video=True, host ones don't.
- native = DLSSFrameSession(**native_args, controller=deadline,
- native_settings=resolve_native_settings(
- settings, gpu_mode=bool(native_args.get("cuda_video", False))),
+ # The replacement session keeps the current frame boundary.
+ native = DLSSFrameSession(**native_args, controller=deadline,
+ native_settings=resolve_native_settings(settings),
composition_mask=settings.nr_mask)
native.diagnostics.encode_backend = (
"nvenc" if self.info.encoder == "NVIDIA NVENC" else "cpu"
@@ -251,12 +250,14 @@ class LiveSession(threading.Thread):
"-af", "aresample=async=1:first_pts=0",
"-f", "nut", "-write_index", "0", "pipe:1"]
return command
- # GPU OFF keeps the host-staging pipeline and its decoded RGBA stream.
+ # Software decoding and CPU encoding retain a host frame boundary;
+ # Neural Rendering still evaluates those frames through CUDA/D3D12.
filters = [] if opts.target_fps == "Source" else [f"fps={rate}"]
filters += [f"scale={width}:{height}:flags=lanczos", "setsar=1"]
command += ["-map", "0:v:0", "-map", f"{audio_input}:a:0?", "-sn", "-dn",
"-vf", ",".join(filters),
- "-c:v", "rawvideo", "-pix_fmt", "rgba", "-threads:v", "1",
+ "-c:v", "rawvideo", "-pix_fmt",
+ "rgba64le" if self._source_depth > 8 else "rgba", "-threads:v", "1",
"-c:a", "pcm_s16le", "-ar", "48000", "-ac", "2",
"-af", "aresample=async=1:first_pts=0",
"-fps_mode", "passthrough", "-f", "nut", "-write_index", "0", "pipe:1"]
@@ -317,9 +318,10 @@ class LiveSession(threading.Thread):
sampled += 1
self._set(sampled_frames=sampled)
continue
- if packet.size != width * height * 4:
+ high_depth = self._source_depth > 8
+ if packet.size != width * height * 4 * (2 if high_depth else 1):
raise RuntimeError("Decoder returned an incomplete RGBA frame.")
- rgba = np.frombuffer(packet, np.uint8).reshape(height, width, 4)
+ rgba = np.frombuffer(packet, np.uint16 if high_depth else np.uint8).reshape(height, width, 4)
start = time.perf_counter()
guide = guides.process(rgba)
guide_ms = (time.perf_counter() - start) * 1000
@@ -352,7 +354,10 @@ class LiveSession(threading.Thread):
muxer = None
try:
audio = get(outgoing, self.controller.cancel)
- muxer = TimestampMuxer(encoder.stdin, width, height, self._rate.rate, audio)
+ muxer = TimestampMuxer(
+ encoder.stdin, width, height, self._rate.rate, audio,
+ pix_fmt="rgba64le" if self._source_depth > 8 else "rgba",
+ )
while True:
item = get(outgoing, self.controller.cancel)
if item is None:
@@ -473,6 +478,7 @@ class LiveSession(threading.Thread):
composition_mask=self.options.nr_mask,
controller=self.controller,
)
+ native.diagnostics.source_format = str(metadata["pixel_format"])
self._ready.set()
processing_start = time.perf_counter()
pacing_seconds = 0.0
@@ -522,11 +528,11 @@ class LiveSession(threading.Thread):
)
else:
rgba = rotate_frame(
- frame.to_ndarray(format="rgba"), int(metadata.get("rotation") or 0)
+ decoded_rgba(frame, metadata["depth"]), int(metadata.get("rotation") or 0)
)
if rgba.shape[:2] != (out_h, out_w):
rgba = resize_fit(rgba, out_w, out_h)
- rgba = np.ascontiguousarray(rgba, dtype=np.uint8)
+ rgba = np.ascontiguousarray(rgba)
guide = software_guides.process(rgba)
scene_score, reset = guide.scene_score, guide.reset
guide_cost = time.perf_counter() - guide_started
@@ -567,6 +573,7 @@ class LiveSession(threading.Thread):
index=processed, reset=force_reset, scene_score=scene_score,
pts=pts, duration=duration, time_base=TIME_BASE,
color_matrix=color_matrix, color_range=color_range,
+ chroma_location=chroma_location_code(metadata),
)
if frame.format.name == "cuda":
result, result_pts = native.process_video_frame(
@@ -780,6 +787,7 @@ class LiveSession(threading.Thread):
self._title = resolved.title
self._set(status=f"Probing {resolved.title}...")
metadata = probe_source(resolved, self.controller, options.network_timeout)
+ self._source_depth = int(metadata["depth"])
source_size = f"{metadata['width']}x{metadata['height']}"
source_limit = options.max_height if options.source_quality == "Auto" else int(options.source_quality)
source_note = (f"Requested up to {source_limit}p; received {source_size}."
@@ -797,8 +805,8 @@ class LiveSession(threading.Thread):
prepared_runtime = prepare_runtime()
ai_uuid, video_uuid = processing_gpu_settings()
gpu = resolve_runtime_ai_gpu(prepared_runtime.gpus, prepared_runtime.runtime_bundle, ai_uuid)
- # Automatic path selection: NVENC on the AI GPU takes the CUDA path,
- # anything else falls back to the host-memory path with a CPU encoder.
+ # NVENC on the AI GPU keeps frames on device; a CPU encoder uses
+ # host frame boundaries around the same CUDA/D3D12 evaluation.
nvenc, ordinal = self._select_encoder(prepared_runtime.gpus, ai_uuid, out_w, out_h)
self._set(input_size=f"{in_w}x{in_h}", output_size=f"{out_w}x{out_h}",
encoder="NVIDIA NVENC" if nvenc else "CPU x264")
@@ -820,10 +828,11 @@ class LiveSession(threading.Thread):
native_args = dict(input_width=in_w, input_height=in_h, output_width=out_w, output_height=out_h,
frame_count=None, warmup_frames=0, factor=factor, mode=mode,
gpu=gpu, runtime_bundle=prepared_runtime.runtime_bundle)
- native = DLSSFrameSession(**native_args, native_settings=resolve_native_settings(options, gpu_mode=False),
+ native = DLSSFrameSession(**native_args, native_settings=resolve_native_settings(options),
composition_mask=options.nr_mask,
controller=self.controller)
native.diagnostics.encode_backend = "nvenc" if nvenc else "cpu"
+ native.diagnostics.source_format = str(metadata["pixel_format"])
self._last_progress = time.monotonic()
decoder = self._spawn("decoder", self._decoder_command(resolved, out_w, out_h, self._rate.rate, cuda=False),
stdout=subprocess.PIPE, stdin=subprocess.DEVNULL)
diff --git a/src/live/source_resolver.py b/src/live/source_resolver.py
index 2d577b5..21a63f8 100644
--- a/src/live/source_resolver.py
+++ b/src/live/source_resolver.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import json
+import av
import subprocess
import time
from fractions import Fraction
@@ -152,9 +153,15 @@ def probe_source(source: ResolvedSource, controller: JobController, timeout: flo
duration = float((data.get("format") or {}).get("duration") or video.get("duration") or 0)
if source.kind == "direct" and duration > 0:
source.is_live = False
+ pixel_format = video.get("pix_fmt") or "unknown"
+ try:
+ depth = max(component.bits for component in av.VideoFormat(pixel_format).components)
+ except (ValueError, TypeError):
+ depth = int(video.get("bits_per_raw_sample") or 8)
return {"width": width, "height": height, "coded_width": int(video["width"]),
"coded_height": int(video["height"]), "rotation": rotation % 360,
- "rate": fps, "duration": duration,
+ "rate": fps, "duration": duration, "pixel_format": pixel_format, "depth": depth,
+ "chroma_location": video.get("chroma_location") or "unknown",
"color_space": video.get("color_space") or "unknown",
"color_range": video.get("color_range") or "unknown",
"color_primaries": video.get("color_primaries") or "unknown",
diff --git a/src/live/transport.py b/src/live/transport.py
index 0ff7d37..cffe4ae 100644
--- a/src/live/transport.py
+++ b/src/live/transport.py
@@ -127,13 +127,15 @@ class AdaptiveRate:
class TimestampMuxer:
"""Carry enhanced RGBA and original audio timestamps over one NUT pipe."""
- def __init__(self, pipe, width: int, height: int, rate: Fraction, audio_template=None) -> None:
+ def __init__(self, pipe, width: int, height: int, rate: Fraction, audio_template=None,
+ pix_fmt: str = "rgba") -> None:
self.container = av.open(PipeWriter(pipe), mode="w", format="nut", options={"write_index": "0"})
self.video = self.container.add_stream("rawvideo", rate=rate)
self.video.width = width
self.video.height = height
- self.video.pix_fmt = "rgba"
- self.video.codec_context.codec_tag = "RGBA"
+ self.video.pix_fmt = pix_fmt
+ if pix_fmt == "rgba":
+ self.video.codec_context.codec_tag = "RGBA"
self.video.time_base = TIME_BASE
self.audio = self.container.add_stream_from_template(audio_template) if audio_template else None
self.container.start_encoding()
diff --git a/src/neural_rendering/image/batch.py b/src/neural_rendering/image/batch.py
index 2de779e..5f9405a 100644
--- a/src/neural_rendering/image/batch.py
+++ b/src/neural_rendering/image/batch.py
@@ -13,6 +13,7 @@ import numpy as np
from ...core.batch_progress import BatchItemUpdate, BatchProgress
from ...core.disk_paths import OutputFile, prepare_output_dir
+from ...core.dlss_modes import DLSS_MODES, validate_dlss
from ...core.gpu_selection import resolve_runtime_ai_gpu
from ...core.jobs import Cancelled, JobController, active_job
from ...core.render_metadata import prepare_render_note
@@ -60,6 +61,9 @@ class _OutputTask:
def _validate_options(options: ImageConversionOptions) -> ImageConversionOptions:
+ if options.scale_method not in {"Standard", "DLSS"}:
+ raise ValueError("Unknown Neural Rendering scale method.")
+ validate_dlss(options.dlss_mode, options.dlss_preset)
if options.output_format not in IMAGE_FORMATS:
raise ValueError(f"Unknown image output format: {options.output_format!r}.")
if isinstance(options.quality, bool):
@@ -139,7 +143,8 @@ def _finalize_output(
render_height=task.render_height,
output_width=task.output_width,
output_height=task.output_height,
- upscaling_factor=float(options.upscaling_factor),
+ upscaling_factor=(float(DLSS_MODES[options.dlss_mode][0])
+ if options.scale_method == "DLSS" else float(options.upscaling_factor)),
output_format=options.output_format,
neural_dimensions={"width": task.render_width, "height": task.render_height},
resize_method=task.resize_method,
@@ -256,7 +261,8 @@ def convert_images(
raise Cancelled("Stopped before rendering.")
prepared = prepare_runtime()
gpu = resolve_runtime_ai_gpu(prepared.gpus, prepared.runtime_bundle, options.ai_gpu_uuid)
- factor, mode = resolve_upscaling_mode(options.upscaling_factor)
+ factor, mode = resolve_upscaling_mode(
+ 1.0 if options.scale_method == "DLSS" else options.upscaling_factor)
native = resolve_native_settings(options)
next_decode: Future[tuple[_DecodedImage, float]] | None = None
session_size: tuple[int, int] | None = None
@@ -298,9 +304,19 @@ def convert_images(
raise ValueError(
f"{path.name} is {width}×{height}; DLSS requires at least 64×64."
)
- output_width, output_height = resolve_output_size(
- width, height, options.upscaling_factor,
- )
+ dlss_details = None
+ if options.scale_method == "DLSS":
+ from ...core.dlss_bridge import process_image as process_dlss_image
+ dlss_started = time.monotonic()
+ dlss_rgba, dlss_details = process_dlss_image(
+ decoded.rgba, options.dlss_mode, options.dlss_preset,
+ gpu_uuid=options.ai_gpu_uuid, controller=controller)
+ timings["dlss_super_resolution"] = time.monotonic() - dlss_started
+ output_height, output_width = dlss_rgba.shape[:2]
+ else:
+ dlss_rgba = None
+ output_width, output_height = resolve_output_size(
+ width, height, options.upscaling_factor)
dimensions = (output_width, output_height)
if session is not None and dimensions != session_size:
close_started = time.monotonic()
@@ -313,8 +329,8 @@ def convert_images(
reporter.advance(index, .10, "Starting D3D12/NGX bridge")
setup_started = time.monotonic()
session = DLSSFrameSession(
- input_width=width,
- input_height=height,
+ input_width=output_width if dlss_rgba is not None else width,
+ input_height=output_height if dlss_rgba is not None else height,
output_width=output_width,
output_height=output_height,
frame_count=None,
@@ -334,7 +350,10 @@ def convert_images(
reporter.advance(index, .25, "Processing image")
prep_started = time.monotonic()
render_rgba = resize_fit(
- decoded.rgba, session.render_width, session.render_height,
+ dlss_rgba if dlss_rgba is not None else decoded.rgba,
+ session.render_width, session.render_height)
+ session.diagnostics.source_format = (
+ f"{decoded.metadata['source_format']}/{decoded.metadata['source_bit_depth']}"
)
timings["render_prepare"] = time.monotonic() - prep_started
@@ -358,7 +377,7 @@ def convert_images(
alpha_started = time.monotonic()
if decoded.alpha is None:
- processed[..., 3] = 255
+ processed[..., 3] = np.iinfo(processed.dtype).max
elif decoded.alpha.shape == dimensions[::-1]:
processed[..., 3] = decoded.alpha
else:
@@ -366,14 +385,25 @@ def convert_images(
decoded.alpha, dimensions, interpolation=cv2.INTER_LANCZOS4,
)
timings["alpha"] = time.monotonic() - alpha_started
+ output_depth = 8
+ if processed.dtype == np.uint16:
+ if options.output_format in {"PNG", "TIFF"}:
+ output_depth = 16
+ elif options.output_format == "AVIF":
+ output_depth = (
+ 12 if int(decoded.metadata["source_bit_depth"]) > 10 else 10
+ )
+ session.diagnostics.output_format = f"{options.output_format}/{output_depth}"
session_data = snapshot_session(session)
evidence_snapshot = dict(session_evidence)
render_width = session.render_width
render_height = session.render_height
- resize_method = "none" if factor == 1.0 else "lanczos"
+ resize_method = "dlss" if dlss_details else ("none" if factor == 1.0 else "lanczos")
memory_path = session.diagnostics.memory_path
bridge_status = session.structured_status()
+ if dlss_details:
+ bridge_status = {**bridge_status, "dlss_super_resolution": dlss_details}
# Preserve the old invariant that the final image is not
# published if native streaming completion fails.
diff --git a/src/neural_rendering/image/decoder.py b/src/neural_rendering/image/decoder.py
index 9f0aa33..373183c 100644
--- a/src/neural_rendering/image/decoder.py
+++ b/src/neural_rendering/image/decoder.py
@@ -7,6 +7,7 @@ from functools import lru_cache
from pathlib import Path
import numpy as np
+import cv2
import pillow_heif
import rawpy
import resvg_py
@@ -89,9 +90,78 @@ def _has_alpha(image: Image.Image, info: dict[str, object]) -> bool:
return image.mode in {"LA", "RGBA"} or (image.mode == "P" and "transparency" in info)
+def _orient_array(rgba: np.ndarray, orientation: int) -> np.ndarray:
+ if orientation == 2:
+ rgba = np.fliplr(rgba)
+ elif orientation == 3:
+ rgba = np.rot90(rgba, 2)
+ elif orientation == 4:
+ rgba = np.flipud(rgba)
+ elif orientation == 5:
+ rgba = np.transpose(rgba, (1, 0, 2))
+ elif orientation == 6:
+ rgba = np.rot90(rgba, 3)
+ elif orientation == 7:
+ rgba = np.flipud(np.fliplr(np.transpose(rgba, (1, 0, 2))))
+ elif orientation == 8:
+ rgba = np.rot90(rgba, 1)
+ return np.ascontiguousarray(rgba)
+
+
+def _decode_high_depth(source: Path, orientation: int) -> tuple[np.ndarray, int] | None:
+ suffix = source.suffix.lower()
+ if suffix in RAW_EXTENSIONS:
+ with rawpy.imread(str(source)) as raw:
+ rgb = raw.postprocess(
+ use_camera_wb=True, output_color=rawpy.ColorSpace.sRGB, output_bps=16,
+ )
+ rgba = np.empty((*rgb.shape[:2], 4), dtype=np.uint16)
+ rgba[..., :3] = rgb
+ rgba[..., 3] = 65535
+ return rgba, 16
+ if suffix in {".heic", ".heif", ".avif"}:
+ heif = pillow_heif.open_heif(source, convert_hdr_to_8bit=False)
+ if ";16" not in heif.mode:
+ return None
+ channels = 4 if "A" in heif.mode else 3
+ width, height = heif.size
+ stride = int(heif.stride) // 2
+ samples = np.frombuffer(heif.data, dtype="<u2").reshape(height, stride)
+ pixels = samples[:, :width * channels].reshape(height, width, channels)
+ rgba = np.empty((height, width, 4), dtype=np.uint16)
+ rgba[..., :channels] = pixels
+ if channels == 3:
+ rgba[..., 3] = 65535
+ return _orient_array(rgba, orientation), int(heif.info.get("bit_depth") or 16)
+ if suffix in {".png", ".tif", ".tiff"}:
+ raw = cv2.imread(str(source), cv2.IMREAD_UNCHANGED | cv2.IMREAD_IGNORE_ORIENTATION)
+ if raw is None or raw.dtype != np.uint16:
+ return None
+ if raw.ndim == 2:
+ rgb = np.repeat(raw[..., None], 3, axis=2)
+ alpha = None
+ elif raw.shape[2] == 3:
+ rgb = cv2.cvtColor(raw, cv2.COLOR_BGR2RGB)
+ alpha = None
+ elif raw.shape[2] == 4:
+ rgb = cv2.cvtColor(raw[..., :3], cv2.COLOR_BGR2RGB)
+ alpha = raw[..., 3]
+ else:
+ return None
+ rgba = np.empty((*raw.shape[:2], 4), dtype=np.uint16)
+ rgba[..., :3] = rgb
+ rgba[..., 3] = alpha if alpha is not None else 65535
+ return _orient_array(rgba, orientation), 16
+ return None
+
+
def decode_image(path: str | os.PathLike[str]) -> _DecodedImage:
source = Path(path).resolve()
- image, decoder = _open_pillow_source(source)
+ raw_high = _decode_high_depth(source, 1) if source.suffix.lower() in RAW_EXTENSIONS else None
+ if raw_high is not None:
+ image, decoder = Image.new("RGB", (1, 1)), "LibRaw"
+ else:
+ image, decoder = _open_pillow_source(source)
opened_image = image
warnings: list[str] = []
try:
@@ -102,14 +172,23 @@ def decode_image(path: str | os.PathLike[str]) -> _DecodedImage:
original_mode = image.mode
info = dict(image.info)
source_format = image.format or source.suffix.lstrip(".").upper()
- image = ImageOps.exif_transpose(image)
- image.load()
- if original_mode not in {"1", "L", "LA", "P", "RGB", "RGBA", "CMYK"}:
+ orientation = int(image.getexif().get(274, 1))
+ high = raw_high if raw_high is not None else _decode_high_depth(source, orientation)
+ if high is None:
+ image = ImageOps.exif_transpose(image)
+ image.load()
+ if original_mode not in {"1", "L", "LA", "P", "RGB", "RGBA", "CMYK"} and high is None:
warnings.append(f"Converted {original_mode} source data to 8-bit SDR sRGB.")
has_alpha = _has_alpha(image, info)
icc_profile = info.get("icc_profile")
- if isinstance(icc_profile, bytes) and icc_profile:
+ if high is not None:
+ rgba, source_bit_depth = high
+ has_alpha = bool(np.any(rgba[..., 3] != 65535)) or has_alpha
+ alpha = np.ascontiguousarray(rgba[..., 3]) if has_alpha else None
+ if isinstance(icc_profile, bytes) and icc_profile:
+ warnings.append("Embedded high-depth ICC profile retained without 8-bit color conversion.")
+ elif isinstance(icc_profile, bytes) and icc_profile:
# Color transforms operate on RGB only; preserve alpha independently.
alpha_image = image.convert("RGBA").getchannel("A") if has_alpha else None
rgb_image = image.convert("RGB")
@@ -144,13 +223,16 @@ def decode_image(path: str | os.PathLike[str]) -> _DecodedImage:
if exif:
exif[274] = 1
metadata: dict[str, object] = {
- "icc_profile": _srgb_profile_bytes(),
+ "icc_profile": icc_profile if high is not None and icc_profile else _srgb_profile_bytes(),
"exif": exif.tobytes() if exif else None,
"dpi": info.get("dpi"),
"xmp": info.get("xmp"),
"source_mode": original_mode,
"source_format": source_format,
"frame_count": frame_count,
+ "source_bit_depth": source_bit_depth if high is not None else 8,
+ "working_format": "rgba16le" if high is not None else "rgba8",
+ "ngx_format": "rgba16f",
}
return _DecodedImage(rgba, alpha, decoder, metadata, warnings)
finally:
diff --git a/src/neural_rendering/image/encoder.py b/src/neural_rendering/image/encoder.py
index e63b9b9..477d024 100644
--- a/src/neural_rendering/image/encoder.py
+++ b/src/neural_rendering/image/encoder.py
@@ -2,14 +2,19 @@ from __future__ import annotations
import atexit
import os
+import struct
import tempfile
import threading
import time
import warnings as python_warnings
+import zlib
from collections import OrderedDict
from pathlib import Path
import numpy as np
+import cv2
+import pillow_heif
+import tifffile
from PIL import Image
from .models import ImageConversionOptions
@@ -29,6 +34,12 @@ _preview_cache_bytes = 0
_preview_cache_lock = threading.Lock()
+def _rgba8_preview(rgba: np.ndarray) -> np.ndarray:
+ if rgba.dtype == np.uint8:
+ return rgba
+ return np.rint(rgba.astype(np.float32) * (255.0 / 65535.0)).astype(np.uint8)
+
+
def _clear_preview_cache() -> None:
global _preview_cache_bytes
with _preview_cache_lock:
@@ -96,7 +107,7 @@ def make_image_preview(
encoding. JPEG is the one format-specific exception: production JPEG output
composites transparency over white, so the gallery preview mirrors that.
"""
- image = Image.fromarray(rgba, mode="RGBA")
+ image = Image.fromarray(_rgba8_preview(rgba), mode="RGBA")
try:
if output_format == "JPEG":
if has_transparency is None:
@@ -130,7 +141,7 @@ def save_full_size_image_preview(
)
os.close(handle)
path = Path(raw_path)
- source = Image.fromarray(rgba, mode="RGBA")
+ source = Image.fromarray(_rgba8_preview(rgba), mode="RGBA")
display = source
try:
if output_format == "JPEG":
@@ -219,11 +230,112 @@ def _metadata_save_args(metadata: dict[str, object], output_format: str) -> dict
args["dpi"] = metadata["dpi"]
if metadata.get("exif") and output_format in {"JPEG", "WebP", "AVIF", "TIFF", "PNG"}:
args["exif"] = metadata["exif"]
- if metadata.get("xmp") and output_format in {"WebP", "AVIF"}:
+ if metadata.get("xmp") and output_format in {"WebP", "AVIF", "PNG", "TIFF"}:
args["xmp"] = metadata["xmp"]
return args
+def _png_chunk(name: bytes, data: bytes) -> bytes:
+ return struct.pack(">I", len(data)) + name + data + struct.pack(">I", zlib.crc32(name + data))
+
+
+def _save_high_image(path: Path, rgba: np.ndarray, output_format: str,
+ args: dict[str, object], quality: int, source_depth: int) -> None:
+ if output_format == "PNG":
+ bgra = cv2.cvtColor(rgba, cv2.COLOR_RGBA2BGRA)
+ ok, encoded = cv2.imencode(".png", bgra, [cv2.IMWRITE_PNG_COMPRESSION, 1])
+ if not ok:
+ raise RuntimeError("16-bit PNG encoder failed")
+ raw = encoded.tobytes()
+ chunks: list[bytes] = []
+ profile = args.get("icc_profile")
+ if isinstance(profile, bytes) and profile:
+ chunks.append(_png_chunk(b"iCCP", b"ICC Profile\0\0" + zlib.compress(profile)))
+ exif = args.get("exif")
+ if isinstance(exif, bytes) and exif:
+ chunks.append(_png_chunk(b"eXIf", exif.removeprefix(b"Exif\0\0")))
+ dpi = args.get("dpi")
+ if isinstance(dpi, (tuple, list)) and len(dpi) >= 2:
+ xppm = round(float(dpi[0]) / 0.0254)
+ yppm = round(float(dpi[1]) / 0.0254)
+ chunks.append(_png_chunk(b"pHYs", struct.pack(">IIB", xppm, yppm, 1)))
+ xmp = args.get("xmp")
+ if isinstance(xmp, bytes) and xmp:
+ chunks.append(_png_chunk(b"iTXt", b"XML:com.adobe.xmp\0\0\0\0\0" + xmp))
+ ihdr_end = 8 + 4 + 4 + 13 + 4
+ path.write_bytes(raw[:ihdr_end] + b"".join(chunks) + raw[ihdr_end:])
+ elif output_format == "TIFF":
+ exif = Image.Exif()
+ if isinstance(args.get("exif"), bytes):
+ exif.load(args["exif"])
+ extra = []
+ for tag in (269, 271, 272, 305, 306, 315, 316, 33432):
+ value = exif.get(tag)
+ if isinstance(value, str) and value:
+ extra.append((tag, "s", 0, value, False))
+ xmp = args.get("xmp")
+ if isinstance(xmp, bytes) and xmp:
+ extra.append((700, "B", len(xmp), xmp, False))
+ tifffile.imwrite(
+ path, rgba, photometric="rgb", extrasamples=["unassalpha"],
+ compression=None, metadata=None,
+ description=exif.get(270),
+ iccprofile=args.get("icc_profile") if isinstance(args.get("icc_profile"), bytes) else None,
+ resolution=args.get("dpi") if isinstance(args.get("dpi"), tuple) else None,
+ resolutionunit="INCH", extratags=extra,
+ )
+ elif output_format == "AVIF":
+ image = pillow_heif.from_bytes("RGBA;16", (rgba.shape[1], rgba.shape[0]), rgba.tobytes())
+ profile = args.get("icc_profile")
+ if isinstance(profile, bytes) and profile:
+ image[0].info["icc_profile"] = profile
+ image.save(
+ path, quality=int(quality), bit_depth=12 if source_depth > 10 else 10,
+ **{key: args[key] for key in ("exif", "xmp") if key in args},
+ )
+ else:
+ raise ValueError(f"Unsupported high-depth image output: {output_format}")
+
+
+def _save_high_image_atomic(output: Path, rgba: np.ndarray, options: ImageConversionOptions,
+ metadata: dict[str, object], render_note: str | None,
+ metadata_diagnostics: dict | None, controller,
+ timings: dict[str, float] | None) -> list[str]:
+ warnings: list[str] = []
+ args = _metadata_save_args(metadata, options.output_format) if options.preserve_metadata else {}
+ temporary = output.with_name(f".{output.stem}.{time.time_ns()}{output.suffix}")
+ description = None
+ note_requested = render_note is not None and options.output_format in IMAGE_NOTE_FORMATS
+ try:
+ check_cancelled(controller)
+ if note_requested:
+ try:
+ args, description = _add_render_note(args, render_note)
+ except (ValueError, TypeError, KeyError, SyntaxError, OSError) as exc:
+ warnings.append(embedding_warning(metadata_diagnostics, exc))
+ note_requested = False
+ try:
+ _save_high_image(temporary, rgba, options.output_format, args,
+ options.quality, int(metadata.get("source_bit_depth") or 16))
+ _verify_image(temporary, (rgba.shape[1], rgba.shape[0]), description if note_requested else None)
+ except (ValueError, TypeError, KeyError, SyntaxError, OSError, RuntimeError) as exc:
+ if not note_requested:
+ raise
+ warnings.append(embedding_warning(metadata_diagnostics, exc))
+ args.pop("exif", None)
+ _save_high_image(temporary, rgba, options.output_format, args,
+ options.quality, int(metadata.get("source_bit_depth") or 16))
+ _verify_image(temporary, (rgba.shape[1], rgba.shape[0]), None)
+ note_requested = False
+ check_cancelled(controller)
+ os.replace(temporary, output)
+ if note_requested:
+ record_embedding(metadata_diagnostics, "embedded", field="EXIF.ImageDescription")
+ finally:
+ temporary.unlink(missing_ok=True)
+ return warnings
+
+
def save_image(
output: Path,
rgba: np.ndarray,
@@ -233,6 +345,11 @@ def save_image(
controller=None, has_transparency: bool | None = None, timings: dict[str, float] | None = None,
) -> list[str]:
output_format = options.output_format
+ if rgba.dtype == np.uint16 and output_format in {"PNG", "TIFF", "AVIF"}:
+ return _save_high_image_atomic(output, rgba, options, metadata, render_note,
+ metadata_diagnostics, controller, timings)
+ if rgba.dtype == np.uint16:
+ rgba = _rgba8_preview(rgba)
source_image = Image.fromarray(rgba, mode="RGBA")
image = source_image
warnings: list[str] = []
diff --git a/src/neural_rendering/image/models.py b/src/neural_rendering/image/models.py
index 866c15d..49e9d81 100644
--- a/src/neural_rendering/image/models.py
+++ b/src/neural_rendering/image/models.py
@@ -28,6 +28,9 @@ class ImageConversionOptions:
mask_feather: int = 0
nr_mask: object | None = None
upscaling_factor: float = 1.0
+ scale_method: str = "Standard"
+ dlss_mode: str = "Quality"
+ dlss_preset: str = "Default"
output_format: str = "PNG"
quality: int = 95
preserve_metadata: bool = True
@@ -58,7 +61,7 @@ class ImageConversionResult:
output_format: str
neural_dimensions: dict[str, int] | None = None
resize_method: str = "none"
- memory_path: str = "host_staging"
+ memory_path: str = "host_cuda_d3d12_shared"
bridge_status: dict | None = None
warnings: list[str] = field(default_factory=list)
timings: dict[str, float] = field(default_factory=dict)
diff --git a/src/neural_rendering/image/preview.py b/src/neural_rendering/image/preview.py
index 2cdebcf..3303a02 100644
--- a/src/neural_rendering/image/preview.py
+++ b/src/neural_rendering/image/preview.py
@@ -62,20 +62,30 @@ def render_image_preview(
f"{source.name} is {width}×{height}; DLSS requires at least 64×64."
)
- output_width, output_height = resolve_output_size(
- width, height, options.upscaling_factor,
- )
+ dlss_details = None
+ if options.scale_method == "DLSS":
+ from ...core.dlss_bridge import process_image as process_dlss_image
+ _update(controller, progress, .08, "Processing DLSS phases")
+ dlss_rgba, dlss_details = process_dlss_image(
+ decoded.rgba, options.dlss_mode, options.dlss_preset,
+ gpu_uuid=options.ai_gpu_uuid, controller=controller)
+ output_height, output_width = dlss_rgba.shape[:2]
+ else:
+ dlss_rgba = None
+ output_width, output_height = resolve_output_size(
+ width, height, options.upscaling_factor)
prepared = prepare_runtime()
gpu = resolve_runtime_ai_gpu(
prepared.gpus, prepared.runtime_bundle, options.ai_gpu_uuid,
)
- factor, mode = resolve_upscaling_mode(options.upscaling_factor)
+ factor, mode = resolve_upscaling_mode(
+ 1.0 if dlss_rgba is not None else options.upscaling_factor)
native = resolve_native_settings(options)
_update(controller, progress, .12, "Starting D3D12/NGX bridge")
session = DLSSFrameSession(
- input_width=width,
- input_height=height,
+ input_width=output_width if dlss_rgba is not None else width,
+ input_height=output_height if dlss_rgba is not None else height,
output_width=output_width,
output_height=output_height,
frame_count=None,
@@ -90,7 +100,11 @@ def render_image_preview(
)
_update(controller, progress, .28, "Processing image")
render_rgba = resize_fit(
- decoded.rgba, session.render_width, session.render_height,
+ dlss_rgba if dlss_rgba is not None else decoded.rgba,
+ session.render_width, session.render_height,
+ )
+ session.diagnostics.source_format = (
+ f"{decoded.metadata['source_format']}/{decoded.metadata['source_bit_depth']}"
)
processed, _pts = session.process(
index=0, rgba=render_rgba, reset=True, pts=0,
@@ -100,7 +114,7 @@ def render_image_preview(
verify_feature_18(session.bridge_logs, session.structured_status())
if decoded.alpha is None:
- processed[..., 3] = 255
+ processed[..., 3] = np.iinfo(processed.dtype).max
elif decoded.alpha.shape == (output_height, output_width):
processed[..., 3] = decoded.alpha
else:
@@ -112,7 +126,7 @@ def render_image_preview(
render_width = session.render_width
render_height = session.render_height
- resize_method = "none" if factor == 1.0 else "lanczos"
+ resize_method = "dlss" if dlss_details else ("none" if factor == 1.0 else "lanczos")
memory_path = session.diagnostics.memory_path
gpu_name = str(gpu["display_name"])
@@ -129,6 +143,7 @@ def render_image_preview(
f"Preview complete: {source.name} | {width}×{height} → "
f"{output_width}×{output_height} | render {render_width}×{render_height} | "
f"{resize_method} resize | {memory_path} | GPU: {gpu_name} | "
+ f"{'DLSS ' + options.dlss_mode + ' preset ' + options.dlss_preset + ' → ' if dlss_details else ''}"
f"{elapsed:.2f}s. Feature-18 execution verified.\n"
"Preview only — no production output image was saved."
)
diff --git a/src/neural_rendering/video/cuda_pipeline.py b/src/neural_rendering/video/cuda_pipeline.py
index 1116b78..a722c60 100644
--- a/src/neural_rendering/video/cuda_pipeline.py
+++ b/src/neural_rendering/video/cuda_pipeline.py
@@ -17,6 +17,7 @@ import numpy as np
from av.codec.hwaccel import HWAccel
from ...core import app_log, ffmpeg
+from ...core.dlss_modes import dlss_output_size
from ...core.disk_paths import OutputFile, prepare_output_dir
from ...core.gpu_selection import resolve_runtime_ai_gpu
from ...core.jobs import Cancelled
@@ -54,23 +55,40 @@ def _range_code(metadata: dict[str, Any]) -> int:
def _set_color_properties(codec_context: Any, metadata: dict[str, Any], hdr: bool) -> None:
- primaries = {"bt709": 1, "bt2020": 9}.get(str(metadata.get("color_primaries")), 2)
+ fallback = 2 if hdr else 1
+ primaries = {"bt709": 1, "bt2020": 9}.get(str(metadata.get("color_primaries")), fallback)
transfer = {
"bt709": 1,
"smpte2084": 16,
"arib-std-b67": 18,
- }.get(str(metadata.get("color_transfer")), 2)
+ }.get(str(metadata.get("color_transfer")), fallback)
colorspace = {
"bt709": 1,
"bt470bg": 5,
"smpte170m": 6,
"bt2020nc": 9,
"bt2020c": 10,
- }.get(str(metadata.get("color_space")), 2)
+ }.get(str(metadata.get("color_space")), fallback)
codec_context.color_primaries = primaries
codec_context.color_trc = transfer
codec_context.colorspace = colorspace
- codec_context.color_range = 1 if hdr or not _range_code(metadata) else 2
+ codec_context.color_range = 2 if _range_code(metadata) else 1
+
+
+def _hdr_bitstream_filter(codec_name: str, metadata: dict[str, Any], preserve_hdr: bool) -> str | None:
+ if not preserve_hdr or not metadata.get("hdr"):
+ return None
+ primaries = {"bt2020": 9, "bt709": 1}.get(str(metadata.get("color_primaries")), 9)
+ transfer = {"smpte2084": 16, "arib-std-b67": 18}.get(str(metadata.get("color_transfer")), 16)
+ matrix = {"bt2020nc": 9, "bt2020c": 10, "bt709": 1}.get(str(metadata.get("color_space")), 9)
+ full = _range_code(metadata)
+ if codec_name == "hevc_nvenc":
+ return (f"hevc_metadata=video_full_range_flag={full}:colour_primaries={primaries}:"
+ f"transfer_characteristics={transfer}:matrix_coefficients={matrix}")
+ if codec_name == "av1_nvenc":
+ return (f"av1_metadata=color_range={full}:color_primaries={primaries}:"
+ f"transfer_characteristics={transfer}:matrix_coefficients={matrix}")
+ return None
def _check_cancel(controller: Any) -> None:
@@ -107,9 +125,11 @@ def convert_video_cuda_nvenc(
gpu: dict[str, Any] | None = None
video_gpu: dict[str, Any] | None = None
session: DLSSFrameSession | None = None
+ dlss_session = None
output_file: OutputFile | None = None
job_dir: Path | None = None
delivered = 0
+ dlss_scene_cuts = 0
encoded_container: Any | None = None
timings: dict[str, float] = {}
frame_accounting: dict[str, Any] = {}
@@ -130,12 +150,23 @@ def convert_video_cuda_nvenc(
estimated_frames,
max(1, int(math.ceil(preview_seconds * float(metadata["fps"])))),
)
- factor, mode = resolve_upscaling_mode(options.upscaling_factor)
+ factor, mode = resolve_upscaling_mode(
+ 1.0 if options.scale_method == "DLSS" else options.upscaling_factor)
input_width, input_height = int(metadata["width"]), int(metadata["height"])
- output_width, output_height = resolve_output_size(input_width, input_height, factor)
+ output_width, output_height = (
+ dlss_output_size(input_width, input_height, options.dlss_mode, even=True)
+ if options.scale_method == "DLSS" else
+ resolve_output_size(input_width, input_height, factor))
effective_hdr = bool(options.preserve_hdr and not compat_preview)
- output_p010 = effective_hdr
+ output_depth = ffmpeg.output_video_depth(metadata["depth"], options.codec, effective_hdr)
+ output_p010 = output_depth > 8
+ output_color_metadata = dict(metadata)
+ if output_p010 and not effective_hdr:
+ for field in ("color_space", "color_primaries", "color_transfer"):
+ if output_color_metadata.get(field) in (None, "", "unknown", "unspecified"):
+ output_color_metadata[field] = "bt709"
codec_name = _NVENC_CODEC[ffmpeg._normalize_codec(options.codec)]
+ color_bitstream_filter = _hdr_bitstream_filter(codec_name, metadata, effective_hdr)
gpu = resolve_runtime_ai_gpu(
prepared_runtime.gpus, prepared_runtime.runtime_bundle, options.ai_gpu_uuid
)
@@ -178,6 +209,7 @@ def convert_video_cuda_nvenc(
native = resolve_native_settings(options)
matrix = _matrix_code(metadata)
color_range = _range_code(metadata)
+ chroma_location = ffmpeg.chroma_location_code(metadata)
# FFmpeg and the bridge deliberately share CUDA's primary context.
# Open the decoder first because some driver versions reject creating a
@@ -208,7 +240,7 @@ def convert_video_cuda_nvenc(
output_width,
output_height,
float(metadata["fps"]),
- hdr_mode=effective_hdr,
+ hdr_mode=output_p010,
)
encoded_container = av.open(str(temp_video), mode="w")
try:
@@ -234,9 +266,14 @@ def convert_video_cuda_nvenc(
encoded_container.close()
raise
session_started = time.perf_counter()
+ if options.scale_method == "DLSS":
+ from ...core.dlss_bridge import DLSSSession
+ dlss_session = DLSSSession(
+ input_width, input_height, options.dlss_mode, options.dlss_preset,
+ gpu_uuid=options.ai_gpu_uuid, even=True)
session = DLSSFrameSession(
- input_width=input_width,
- input_height=input_height,
+ input_width=output_width if dlss_session else input_width,
+ input_height=output_height if dlss_session else input_height,
output_width=output_width,
output_height=output_height,
frame_count=None,
@@ -250,6 +287,8 @@ def convert_video_cuda_nvenc(
controller=controller,
cuda_video=True,
)
+ session.diagnostics.source_format = str(metadata["pixel_format"])
+ session.diagnostics.output_format = "p010le" if output_p010 else "nv12"
timings["native_setup_seconds"] = time.perf_counter() - session_started
encode_started = time.perf_counter()
with encoded_container as encoded:
@@ -292,6 +331,13 @@ def convert_video_cuda_nvenc(
if frame.format.name == "cuda":
decode_backends.add("nvdec")
+ if dlss_session is not None:
+ frame, dlss_detail = dlss_session.process_cuda_frame(
+ frame, color_matrix=matrix, color_range=color_range,
+ rotation=int(metadata["rotation"]), phase=delivered,
+ output_p010=output_p010)
+ dlss_scene_cuts += int(dlss_detail["scene_cut"])
+ frame.pts, frame.time_base, frame.duration = pts, frame_time_base, duration
scene_started = time.perf_counter()
scene_score, reset = session.score_cuda_frame(
frame, color_matrix=matrix, color_range=color_range
@@ -308,25 +354,40 @@ def convert_video_cuda_nvenc(
time_base=frame_time_base,
color_matrix=matrix,
color_range=color_range,
- rotation=int(metadata["rotation"]),
+ rotation=0 if dlss_session else int(metadata["rotation"]),
+ chroma_location=chroma_location,
output_p010=output_p010,
)
else:
decode_backends.add("software")
prepare_started = time.perf_counter()
rgba = rotate_frame(
- frame.to_ndarray(format="rgba"), int(metadata["rotation"])
+ ffmpeg.decoded_rgba(frame, metadata["depth"]), int(metadata["rotation"])
)
- if rgba.shape[:2] != (output_height, output_width):
+ if dlss_session is not None:
+ if software_guides is None:
+ software_guides = TemporalGuideGenerator(rgba.shape[1], rgba.shape[0])
+ scene_started = time.perf_counter()
+ guide = software_guides.process(rgba)
+ scene_seconds += time.perf_counter() - scene_started
+ scene_score, reset = guide.scene_score, guide.reset
+ dlss_scene_cuts += int(reset and delivered > 0)
+ dlss_half = dlss_session.process(rgba, reset=reset, phase=delivered)
+ levels = 65535 if output_p010 else 255
+ rgba = np.rint(np.clip(dlss_half.astype(np.float32), 0, 1) * levels).astype(
+ np.uint16 if output_p010 else np.uint8)
+ rgba[..., 3] = levels
+ elif rgba.shape[:2] != (output_height, output_width):
rgba = resize_fit(rgba, output_width, output_height)
- rgba = np.ascontiguousarray(rgba, dtype=np.uint8)
+ rgba = np.ascontiguousarray(rgba)
prepare_seconds += time.perf_counter() - prepare_started
- if software_guides is None:
- software_guides = TemporalGuideGenerator(output_width, output_height)
- scene_started = time.perf_counter()
- guide = software_guides.process(rgba)
- scene_seconds += time.perf_counter() - scene_started
- scene_score, reset = guide.scene_score, guide.reset
+ if dlss_session is None:
+ if software_guides is None:
+ software_guides = TemporalGuideGenerator(output_width, output_height)
+ scene_started = time.perf_counter()
+ guide = software_guides.process(rgba)
+ scene_seconds += time.perf_counter() - scene_started
+ scene_score, reset = guide.scene_score, guide.reset
evaluate_started = time.perf_counter()
processed, output_pts = session.process_video_frame(
index=delivered,
@@ -382,6 +443,9 @@ def convert_video_cuda_nvenc(
timings["encoding_stage_seconds"] = time.perf_counter() - encode_started
assert session is not None
session.close()
+ if dlss_session is not None:
+ if dlss_session.frames != delivered:
+ raise RuntimeError("DLSS frame count does not match Neural Rendering input.")
frame_accounting["bridge_completed_frames"] = session.completed_frames
if session.completed_frames != delivered:
raise RuntimeError("Bridge completion does not match the processed frame count.")
@@ -403,6 +467,8 @@ def convert_video_cuda_nvenc(
render_note=render_note,
metadata_diagnostics=metadata_diagnostics,
audio_diagnostics=audio_diagnostics,
+ video_bitstream_filter=color_bitstream_filter,
+ video_color_metadata=output_color_metadata if output_p010 else None,
)
timings["final_mux_seconds"] = time.perf_counter() - mux_started
_check_cancel(controller)
@@ -416,15 +482,43 @@ def convert_video_cuda_nvenc(
raise RuntimeError(
f"Output container reports {declared_output} frames instead of {delivered}."
)
- if effective_hdr and (not verified.get("hdr") or verified.get("color_space") != "bt2020nc"):
- raise RuntimeError("Saved HDR output did not retain BT.2020 HDR signaling.")
+ if effective_hdr and metadata.get("hdr") and (
+ not verified.get("hdr") or verified.get("color_space") != str(metadata.get("color_space"))
+ ):
+ intermediate = ffmpeg.probe_video(temp_video, count_mode="metadata", controller=controller)
+ raise RuntimeError(
+ "Saved HDR output did not retain BT.2020 HDR signaling: "
+ f"transfer={verified.get('color_transfer')} matrix={verified.get('color_space')} "
+ f"primaries={verified.get('color_primaries')} range={verified.get('color_range')}; "
+ f"intermediate transfer={intermediate.get('color_transfer')} "
+ f"matrix={intermediate.get('color_space')} "
+ f"primaries={intermediate.get('color_primaries')}."
+ )
status = session.structured_status()
+ if dlss_session is not None:
+ status["dlss_super_resolution"] = {
+ "mode": options.dlss_mode, "preset": options.dlss_preset,
+ "guides": "estimated", "frames": dlss_session.frames,
+ "scene_cuts": dlss_scene_cuts,
+ "render_width": dlss_session.last_result.render_width,
+ "render_height": dlss_session.last_result.render_height,
+ "gpu_pre_resize": (
+ dlss_session.last_result.render_width, dlss_session.last_result.render_height
+ ) != (input_width, input_height),
+ }
+ temporal_timing = status.get("temporal_stabilization", {})
+ for field in (
+ "gpu_copy_in_seconds", "gpu_ngx_seconds", "gpu_copy_out_seconds",
+ "cuda_input_wait_seconds", "d3d12_wait_seconds", "optical_flow_seconds",
+ ):
+ timings[field] = float(temporal_timing.get(field, 0.0))
decode_backend = "+".join(sorted(decode_backends)) or "unknown"
status["decode_backend"] = decode_backend
status["encode_backend"] = codec_name
status["audio_streams"] = audio_diagnostics.get("streams", [])
- resize_method = "none" if factor == 1.0 else "lanczos"
+ status["timings"] = dict(timings)
+ resize_method = "dlss" if dlss_session else ("none" if factor == 1.0 else "lanczos")
elapsed = time.perf_counter() - started
report_path = app_log.session_path()
app_log.info(
@@ -447,7 +541,7 @@ def convert_video_cuda_nvenc(
render_height=output_height,
output_width=output_width,
output_height=output_height,
- upscaling_factor=factor,
+ upscaling_factor=(output_width / input_width if dlss_session else factor),
neural_dimensions={"width": output_width, "height": output_height},
resize_method=resize_method,
memory_path="cuda_d3d12_shared",
@@ -472,6 +566,8 @@ def convert_video_cuda_nvenc(
failure = app_log.fail("video-render-cuda", f"video-render-cuda-{source.stem}", exc, tails)
raise RuntimeError(f"{exc}\nDetails: {failure}") from exc
finally:
+ if dlss_session is not None:
+ dlss_session.close()
if encoded_container is not None:
with suppress(Exception):
encoded_container.close()
diff --git a/src/neural_rendering/video/guides.py b/src/neural_rendering/video/guides.py
index 449e834..ffa8d03 100644
--- a/src/neural_rendering/video/guides.py
+++ b/src/neural_rendering/video/guides.py
@@ -18,7 +18,9 @@ class GuideFrame:
class TemporalGuideGenerator:
"""Reduced-luma scene reset detector that retains history between cuts."""
- def __init__(self, width: int, height: int, flow_width: int = 640) -> None:
+ def __init__(self, width: int, height: int, flow_width: int = 640,
+ cut_threshold: float = SCENE_CUT_THRESHOLD) -> None:
+ self.cut_threshold = cut_threshold
scale = min(1.0, flow_width / max(1, width))
self.luma_width = max(32, int(round(width * scale / 2) * 2))
self.luma_height = max(32, int(round(height * scale / 2) * 2))
@@ -31,6 +33,14 @@ class TemporalGuideGenerator:
self.duplicate_frames = 0
def _small_gray(self, rgba: np.ndarray) -> np.ndarray:
+ if rgba.dtype == np.uint16:
+ # Scene scoring may use 8-bit luma; the render frame stays 16-bit.
+ small = cv2.resize(
+ rgba, (self.luma_width, self.luma_height), interpolation=cv2.INTER_AREA
+ )
+ gray16 = cv2.cvtColor(small, cv2.COLOR_RGBA2GRAY)
+ np.copyto(self._current_gray, (gray16 >> 8).astype(np.uint8))
+ return self._current_gray
cv2.resize(
rgba,
(self.luma_width, self.luma_height),
@@ -55,7 +65,7 @@ class TemporalGuideGenerator:
scene_score = 0.0
else:
scene_score = float(np.mean(self._difference)) / 255.0
- reset = scene_score > SCENE_CUT_THRESHOLD
+ reset = scene_score > self.cut_threshold
self.previous_gray = current
self._current_gray = self._gray_b if current is self._gray_a else self._gray_a
diff --git a/src/neural_rendering/video/models.py b/src/neural_rendering/video/models.py
index c505f16..1912029 100644
--- a/src/neural_rendering/video/models.py
+++ b/src/neural_rendering/video/models.py
@@ -23,6 +23,9 @@ class ConversionOptions:
mask_feather: int = 0
nr_mask: object | None = None
upscaling_factor: float = 1.0
+ scale_method: str = "Standard"
+ dlss_mode: str = "Quality"
+ dlss_preset: str = "Default"
codec: str = "H.264 (NVIDIA NVENC)"
container: str = "MP4"
quality: str = "Auto (Default)"
@@ -54,7 +57,7 @@ class ConversionResult:
upscaling_factor: float
neural_dimensions: dict[str, int] | None = None
resize_method: str = "none"
- memory_path: str = "host_staging"
+ memory_path: str = "host_cuda_d3d12_shared"
bridge_status: dict | None = None
diff --git a/src/neural_rendering/video/preview.py b/src/neural_rendering/video/preview.py
index 2dce65d..c5834a9 100644
--- a/src/neural_rendering/video/preview.py
+++ b/src/neural_rendering/video/preview.py
@@ -59,12 +59,14 @@ def process_video_preview(
frame_no = 1
effective_source = str(source)
temp_clip: str | None = None
- if start > 0.05 and preview_frames is not None:
+ if start > 0.05 and (preview_frames is not None or preview_seconds is not None):
from ...core.ffmpeg.preview import extract_preview_subclip
_emit_progress(progress, 0.02, "Seeking to timeline frame…")
temp_clip = extract_preview_subclip(
str(source), dest_dir=output_dir, start_seconds=start,
- single_frame=True, controller=controller,
+ single_frame=preview_frames is not None,
+ length_seconds=preview_seconds if preview_frames is None else None,
+ controller=controller,
)
effective_source = temp_clip
@@ -153,10 +155,12 @@ def process_video_preview(
f"{result.render_width}×{result.render_height}; {result.resize_method}, "
f"{result.memory_path}. Feature 18 confirmed.{derived_note}",
)
+ clip_seconds = preview_seconds if preview_seconds is not None else PREVIEW_SECONDS
+ start_note = f" from {start:.2f}s" if start > 0.05 else ""
return finish(
output_preview,
- f"Preview complete for {source_name}: {result.frames} frames from the first "
- f"{PREVIEW_SECONDS:g} seconds processed on {result.gpu} in "
+ f"Preview complete for {source_name}:{start_note} {result.frames} frames from the "
+ f"{clip_seconds:g}-second clip processed on {result.gpu} in "
f"{result.elapsed_seconds:.1f}s. Neural dimensions "
f"{result.render_width}×{result.render_height}; {result.resize_method}, "
f"{result.memory_path}. All frames returned feature-18 success.{derived_note}",
diff --git a/src/neural_rendering/video/processor.py b/src/neural_rendering/video/processor.py
index 7326982..786e7d7 100644
--- a/src/neural_rendering/video/processor.py
+++ b/src/neural_rendering/video/processor.py
@@ -17,6 +17,7 @@ import av
import numpy as np
from ...core import app_log, ffmpeg
+from ...core.dlss_modes import validate_dlss
from ...core.gpu_selection import resolve_runtime_ai_gpu
from ...core.jobs import Cancelled, active_job
from ...core.naming import output_filename, unique_output_path, validate_rename
@@ -34,8 +35,8 @@ validate_codec_container = ffmpeg.validate_codec_container
_BATCH_CONTEXT = threading.local()
-def automatic_gpu_mode(codec: str) -> bool:
- """Use CUDA transport exactly when the selected encoder is NVENC."""
+def uses_nvenc_frame_boundary(codec: str) -> bool:
+ """Keep decoded and encoded frames on CUDA when NVENC is selected."""
return ffmpeg._is_nvenc_codec(codec)
def _validate_preview_options(
@@ -83,10 +84,12 @@ def convert_video(
# Compat previews use the forced H.264 SDR 8-bit path; user-encoded previews
# (Preview Encoding Auto-playable / Disabled) preserve the HDR choice.
compat_preview = is_preview and bool(getattr(options, "preview_compat", True))
- # Processing-engine selection is codec-driven: NVENC encoders take the
- # CUDA transport, CPU codecs take the host-memory path. There is no
- # user-facing mode switch.
- cuda_path = automatic_gpu_mode(options.codec)
+ # The codec selects the frame boundary and encoder. Neural evaluation
+ # always uses CUDA/D3D12, including the CPU encoder route below.
+ if options.scale_method not in {"Standard", "DLSS"}:
+ raise ValueError("Unknown Neural Rendering scale method.")
+ validate_dlss(options.dlss_mode, options.dlss_preset)
+ cuda_path = uses_nvenc_frame_boundary(options.codec)
hdr_requested = bool(options.preserve_hdr)
if compat_preview:
hdr_requested = False
@@ -139,6 +142,7 @@ def convert_video(
output: Path | None = None
output_file: OutputFile | None = None
session: DLSSFrameSession | None = None
+ dlss_session = None
gpu: dict | None = resolve_runtime_ai_gpu(
prepared_runtime.gpus, prepared_runtime.runtime_bundle, options.ai_gpu_uuid
)
@@ -171,6 +175,7 @@ def convert_video(
color_range = int(
str(metadata.get("color_range") or "").casefold() in {"pc", "jpeg", "full"}
)
+ chroma_location = ffmpeg.chroma_location_code(metadata)
declared_frames = int(metadata["frames"])
estimated_frames = declared_frames or max(
1, int(math.ceil(float(metadata["duration"]) * float(metadata["fps"])))
@@ -188,20 +193,38 @@ def convert_video(
timings["probe_seconds"] = time.perf_counter() - stage_started
input_width = int(metadata["width"])
input_height = int(metadata["height"])
- factor, mode = resolve_upscaling_mode(options.upscaling_factor)
- output_width, output_height = resolve_output_size(
- input_width, input_height, factor
- )
- # HDR metadata to copy – 10-bit path when HDR Mode is on
- hdr_metadata = None
+ if options.scale_method == "DLSS":
+ from ...core.dlss_bridge import DLSSSession
+ dlss_session = DLSSSession(
+ input_width, input_height, options.dlss_mode, options.dlss_preset,
+ gpu_uuid=options.ai_gpu_uuid, even=True)
+ output_width, output_height = dlss_session.output_width, dlss_session.output_height
+ factor, mode = resolve_upscaling_mode(1.0)
+ else:
+ factor, mode = resolve_upscaling_mode(options.upscaling_factor)
+ output_width, output_height = resolve_output_size(
+ input_width, input_height, factor)
effective_hdr = hdr_requested and (not is_preview or not compat_preview)
- if effective_hdr:
- hdr_metadata = {
- "color_space": metadata.get("color_space", "unknown"),
- "color_primaries": metadata.get("color_primaries", "unknown"),
- "color_transfer": metadata.get("color_transfer", "unknown"),
- "hdr": bool(metadata.get("hdr", False)),
- }
+ hdr_metadata = {
+ "color_space": metadata.get("color_space", "unknown"),
+ "color_primaries": metadata.get("color_primaries", "unknown"),
+ "color_transfer": metadata.get("color_transfer", "unknown"),
+ "color_range": metadata.get("color_range", "unknown"),
+ "hdr": bool(metadata.get("hdr", False)),
+ }
+ output_depth = ffmpeg.output_video_depth(metadata["depth"], options.codec, effective_hdr)
+ output_color_metadata = dict(hdr_metadata)
+ if not effective_hdr:
+ for field in ("color_space", "color_primaries", "color_transfer"):
+ if output_color_metadata.get(field) in (None, "", "unknown", "unspecified"):
+ output_color_metadata[field] = "bt709"
+ if options.codec == "FFV1 Lossless RGB 10-bit":
+ # The FFV1 branch carries full-range GBR samples. Container
+ # metadata must describe that output, not the source YUV range.
+ # FFmpeg's CLI does not accept `-colorspace gbr`; the FFV1
+ # bitstream already carries GBR from the setparams filter.
+ output_color_metadata["color_space"] = "unknown"
+ output_color_metadata["color_range"] = "pc"
destination = prepare_output_dir(output_dir, default=OUTPUTS)
JOBS.mkdir(exist_ok=True)
app_log.info("video-render", f"start src={source.name}")
@@ -231,8 +254,7 @@ def convert_video(
))
output_file = OutputFile(output)
temp_video = job_dir / (f"processed-video{extension}" if preview_frames is not None else "processed-video.mkv")
- # Host-memory path (CPU codec): stage explicitly, never CUDA.
- native = resolve_native_settings(options, gpu_mode=False)
+ native = resolve_native_settings(options)
metadata_diagnostics: dict = {}
render_note = prepare_render_note(options, metadata_diagnostics)
video_duration = float(metadata.get("video_stream_duration") or 0.0)
@@ -240,6 +262,8 @@ def convert_video(
options.container in {"MP4", "MOV"}
and preview_frames is None
and (preview_seconds is not None or video_duration > 0.0)
+ and not (effective_hdr and hdr_metadata["hdr"])
+ and not (output_depth > 8 and options.codec == "AV1")
)
audio_diagnostics: dict = {}
direct_audio_plan = (
@@ -271,8 +295,8 @@ def convert_video(
nonlocal video_gpu
encoder_started = time.perf_counter()
try:
- # The host-memory path retains the separate Video
- # Processing GPU selection for the CPU encoder stage.
+ # The CPU encoder route retains the separate Video
+ # Processing GPU selection for its output stage.
encoder_gpu_uuid = options.video_gpu_uuid
video_gpu = ffmpeg.resolve_video_gpu(
prepared_runtime.gpus,
@@ -293,7 +317,7 @@ def convert_video(
None if video_gpu is None else int(video_gpu["cuda_ordinal"]),
video_gpu is not None,
hdr_mode=effective_hdr,
- hdr_metadata=hdr_metadata,
+ hdr_metadata=output_color_metadata,
preserve_timestamps=not metadata["cfr"],
speed_profile="preview" if compat_preview else "neural",
source_audio=source if direct_mux else None,
@@ -302,6 +326,7 @@ def convert_video(
audio_duration=audio_duration if direct_mux else None,
include_source_metadata=not is_preview,
audio_plan=direct_audio_plan,
+ output_depth=output_depth,
)
)
except BaseException as exc:
@@ -321,8 +346,8 @@ def convert_video(
# feature 18 and optical flow still execute on the selected GPU.
session_started = time.perf_counter()
session = DLSSFrameSession(
- input_width=input_width,
- input_height=input_height,
+ input_width=output_width if dlss_session else input_width,
+ input_height=output_height if dlss_session else input_height,
output_width=output_width,
output_height=output_height,
frame_count=None,
@@ -348,6 +373,10 @@ def convert_video(
raise RuntimeError("Video encoder did not finish preparing.")
render_width = session.render_width
render_height = session.render_height
+ session.diagnostics.source_format = str(metadata["pixel_format"])
+ session.diagnostics.output_format = (
+ "rgba16le" if int(metadata["depth"]) > 8 else "rgba8"
+ )
setup_result = session.setup_result
minimum_width = session.minimum_width
minimum_height = session.minimum_height
@@ -367,8 +396,10 @@ def convert_video(
) = encoder_setup[0]
assert encoder.stdin is not None
- prepared_bytes = render_width * render_height * 4
- rendered_bytes = output_width * output_height * 4
+ high_depth = int(metadata["depth"]) > 8
+ sample_bytes = 2 if high_depth else 1
+ prepared_bytes = render_width * render_height * 4 * sample_bytes
+ rendered_bytes = output_width * output_height * 4 * sample_bytes
queue_slots = max(
1,
min(3, (384 * 1024 * 1024) // max(1, prepared_bytes + rendered_bytes)),
@@ -377,7 +408,7 @@ def convert_video(
rendered_frames: queue.Queue[object] = queue.Queue(maxsize=queue_slots)
output_pool: queue.LifoQueue[np.ndarray] = queue.LifoQueue(maxsize=queue_slots + 1)
for _ in range(queue_slots + 1):
- output_pool.put(np.empty((output_height, output_width, 4), dtype=np.uint8))
+ output_pool.put(np.empty((output_height, output_width, 4), dtype=np.uint16 if high_depth else np.uint8))
stop_marker = object()
def put_pipeline(target: queue.Queue[object], item: object) -> bool:
@@ -420,7 +451,9 @@ def convert_video(
container = av.open(str(source))
stream = container.streams.video[0]
stream.thread_type = "AUTO"
- guides = TemporalGuideGenerator(render_width, render_height)
+ guides = TemporalGuideGenerator(
+ input_width if dlss_session else render_width,
+ input_height if dlss_session else render_height)
first_time: float | None = None
rate = float(stream.average_rate or 30)
default_duration = max(
@@ -462,7 +495,7 @@ def convert_video(
raise RuntimeError(
f"The video decoder marked source frame {index} as corrupt."
)
- if frame.format.name == "cuda":
+ if frame.format.name == "cuda" and dlss_session is None:
hardware_frames += 1
guide_started = time.perf_counter()
scene_score, reset = session.score_cuda_frame(
@@ -475,11 +508,11 @@ def convert_video(
software_frames += 1
prepare_started = time.perf_counter()
rgba = rotate_frame(
- frame.to_ndarray(format="rgba"), metadata["rotation"]
+ ffmpeg.decoded_rgba(frame, metadata["depth"]), metadata["rotation"]
)
- if rgba.shape[1] != render_width or rgba.shape[0] != render_height:
+ if dlss_session is None and (rgba.shape[1] != render_width or rgba.shape[0] != render_height):
rgba = resize_fit(rgba, render_width, render_height)
- rgba = np.ascontiguousarray(rgba, dtype=np.uint8)
+ rgba = np.ascontiguousarray(rgba)
prepare_seconds += time.perf_counter() - prepare_started
guide_started = time.perf_counter()
guide = guides.process(rgba)
@@ -526,6 +559,7 @@ def convert_video(
height=output_height,
rate=metadata["rate"],
time_base=metadata["time_base"],
+ pix_fmt="rgba64le" if high_depth else "rgba",
)
while not pipeline_stop.is_set():
if controller.cancel.is_set():
@@ -604,9 +638,18 @@ def convert_video(
color_matrix=color_matrix,
color_range=color_range,
rotation=int(metadata["rotation"]),
+ chroma_location=chroma_location,
output_buffer=output_buffer,
)
else:
+ if dlss_session is not None:
+ dlss_frame = dlss_session.process(
+ prepared, reset=guide.reset, phase=index)
+ levels = 65535 if high_depth else 255
+ prepared = np.rint(np.clip(
+ dlss_frame.astype(np.float32), 0, 1) * levels
+ ).astype(np.uint16 if high_depth else np.uint8)
+ prepared[..., 3] = levels
processed, out_pts = session.process(
index=index,
rgba=prepared,
@@ -708,7 +751,7 @@ def convert_video(
)
session.diagnostics.encode_backend = selected_encoder
nr_count = delivered
- resize_method = "none" if factor == 1.0 else "lanczos"
+ resize_method = "dlss" if dlss_session else ("none" if factor == 1.0 else "lanczos")
memory_path = session.diagnostics.memory_path
mux_started = time.perf_counter()
if direct_mux:
@@ -734,6 +777,7 @@ def convert_video(
temp_video, source, output_file.temporary, options.container, controller,
render_note=render_note, metadata_diagnostics=metadata_diagnostics,
audio_diagnostics=audio_diagnostics,
+ video_color_metadata=output_color_metadata if output_depth > 8 else None,
)
timings["final_mux_seconds"] = time.perf_counter() - mux_started
timings["muxing_seconds"] = timings["final_mux_seconds"]
@@ -801,10 +845,23 @@ def convert_video(
gpu=gpu["display_name"], input_width=input_width,
input_height=input_height, render_width=render_width,
render_height=render_height, output_width=output_width,
- output_height=output_height, upscaling_factor=factor,
+ output_height=output_height,
+ upscaling_factor=(output_width / input_width if dlss_session else factor),
neural_dimensions={"width": render_width, "height": render_height},
resize_method=resize_method, memory_path=memory_path,
- bridge_status={**session.structured_status(), "audio_streams": audio_diagnostics.get("streams", [])},
+ bridge_status={**session.structured_status(),
+ **({"dlss_super_resolution": {
+ "mode": options.dlss_mode, "preset": options.dlss_preset,
+ "guides": "estimated", "frames": dlss_session.frames,
+ "scene_cuts": scene_resets,
+ "render_width": dlss_session.last_result.render_width,
+ "render_height": dlss_session.last_result.render_height,
+ "gpu_pre_resize": (
+ dlss_session.last_result.render_width,
+ dlss_session.last_result.render_height) != (input_width, input_height),
+ }} if dlss_session else {}),
+ "timings": dict(timings),
+ "audio_streams": audio_diagnostics.get("streams", [])},
)
except Exception as exc:
was_cancelled = controller.cancel.is_set()
@@ -843,6 +900,8 @@ def convert_video(
report_path = app_log.fail("video-render", f"video-render-{source.stem}", exc, tails or None)
raise RuntimeError(f"{exc}\nDetails: {report_path}") from exc
finally:
+ if dlss_session is not None:
+ dlss_session.close()
if output_file is not None:
output_file.cleanup()
pipeline_stop.set()
diff --git a/src/settings/models.py b/src/settings/models.py
index 1c525f6..8fa3a22 100644
--- a/src/settings/models.py
+++ b/src/settings/models.py
@@ -1,11 +1,13 @@
from __future__ import annotations
from dataclasses import dataclass, replace
+import math
from types import SimpleNamespace
from ..core.ffmpeg import CODEC_CHOICES as FFMPEG_CODEC_CHOICES, ENCODING_QUALITIES, HDR_ALLOWED_CODECS, hdr_mode_supported
from ..core.naming import validate_rename
from ..core.runtime import resolve_native_settings, resolve_upscaling_mode
+from ..core.dlss_modes import DLSS_METHODS, validate_dlss
from ..frame_interpolation.models import ENGINE_CHOICES, FPS_CHOICES, PREVIEW_LENGTH_CHOICES
from .migration import _migrate_codec
from ..upscale.video.models import options_from_settings
@@ -15,9 +17,11 @@ QUALITY_CHOICES = ENCODING_QUALITIES
CODEC_CHOICES = FFMPEG_CODEC_CHOICES
CONTAINER_CHOICES = ("MP4", "MKV", "MOV")
IMAGE_FORMAT_CHOICES = ("PNG", "JPEG", "WebP", "AVIF", "TIFF")
+IMAGE_16BIT_FORMATS = ("PNG", "TIFF")
+IMAGE_BIT_DEPTH_CHOICES = (8, 16)
CONFIG_SECTION = "Settings"
PRESET_FORMAT = "dlss5-visual-enhancer-settings-preset"
-PRESET_SCHEMA_VERSION = 7
+PRESET_SCHEMA_VERSION = 18
MAX_PRESET_BYTES = 1024 * 1024
AUTOMATIC_MASK_CHOICES = ("Off", "On")
@@ -26,6 +30,110 @@ PREVIEW_ENCODING_CHOICES = ("Auto", "Always H.264", "Disabled")
UPSCALE_MODE_CHOICES = ("Image", "Video")
UPSCALE_PREVIEW_LENGTH_CHOICES = PREVIEW_LENGTH_CHOICES
+IMAGE_SCALING_FILTERS = ("Lanczos4", "Area", "Bicubic", "Bilinear", "Nearest")
+VIDEO_SCALING_FILTERS = ("Spline36", "Lanczos", "Bicubic", "Area", "Bilinear", "EWA Lanczos")
+
+LEGACY_IMAGE_STAGE_ORDER = ("neural_model", "scale_method", "super_resolution")
+LEGACY_VIDEO_STAGE_ORDER = (*LEGACY_IMAGE_STAGE_ORDER, "frame_generation")
+PREVIOUS_IMAGE_STAGE_ORDER = ("neural_model", "scale_method", "dlss_super_resolution", "super_resolution")
+BEFORE_DENOISING_IMAGE_STAGE_ORDER = (*PREVIOUS_IMAGE_STAGE_ORDER, "coloring")
+BEFORE_CAS_IMAGE_STAGE_ORDER = ("denoising", *BEFORE_DENOISING_IMAGE_STAGE_ORDER)
+IMAGE_STAGE_ORDER = (*BEFORE_CAS_IMAGE_STAGE_ORDER, "cas_sharpening")
+PREVIOUS_VIDEO_STAGE_ORDER = (*PREVIOUS_IMAGE_STAGE_ORDER, "frame_generation")
+BEFORE_DENOISING_VIDEO_STAGE_ORDER = (*PREVIOUS_VIDEO_STAGE_ORDER, "coloring")
+BEFORE_CAS_VIDEO_STAGE_ORDER = ("denoising", *BEFORE_DENOISING_VIDEO_STAGE_ORDER)
+VIDEO_STAGE_ORDER = (*BEFORE_CAS_VIDEO_STAGE_ORDER, "cas_sharpening")
+COLORING_MODES = ("Color Match", "LUT")
+SHARPENING_METHODS = ("NVIDIA NIS", "AMD CAS")
+COLOR_MATCH_SOURCES = ("Input Image", "Selected Image")
+LUT_RESOLUTIONS = (33, 65, 129)
+LUT_ADJUSTMENT_RANGES = {
+ "lut_mix": (0, 200),
+ "lut_exposure": (-3.0, 3.0),
+ "lut_contrast": (-100, 100),
+ "lut_highlights": (-100, 100),
+ "lut_shadows": (-100, 100),
+ "lut_whites": (-100, 100),
+ "lut_blacks": (-100, 100),
+ "lut_midtones": (-100, 100),
+ "lut_temperature": (-100, 100),
+ "lut_tint": (-100, 100),
+ "lut_hue": (-180, 180),
+ "lut_vibrance": (-100, 100),
+ "lut_saturation": (-100, 100),
+}
+
+
+def validate_stage_layout(order: tuple[str, ...], enabled: tuple[str, ...], *, video: bool) -> None:
+ allowed = VIDEO_STAGE_ORDER if video else IMAGE_STAGE_ORDER
+ if not isinstance(order, tuple) or len(order) != len(allowed) or set(order) != set(allowed):
+ raise ValueError("Pipeline order must contain each available processing card exactly once.")
+ if not isinstance(enabled, tuple) or len(enabled) != len(set(enabled)) or not set(enabled) <= set(allowed):
+ raise ValueError("Pipeline enabled stages contain an unavailable or duplicate card.")
+
+
+def migrate_stage_layout(order: tuple[str, ...], enabled: tuple[str, ...], *,
+ video: bool, scale_method: str, upscale_engine: str) -> tuple[tuple[str, ...], tuple[str, ...]]:
+ """Upgrade old card layouts while retaining their order and enabled behavior."""
+ allowed = VIDEO_STAGE_ORDER if video else IMAGE_STAGE_ORDER
+ if set(order) == set(allowed) and len(order) == len(allowed):
+ validate_stage_layout(order, enabled, video=video)
+ return order, enabled
+ before_cas = BEFORE_CAS_VIDEO_STAGE_ORDER if video else BEFORE_CAS_IMAGE_STAGE_ORDER
+ if len(order) == len(before_cas) and set(order) == set(before_cas):
+ if len(enabled) != len(set(enabled)) or not set(enabled) <= set(order):
+ raise ValueError("Pipeline enabled stages contain an unavailable or duplicate card.")
+ result = (*order, "cas_sharpening"), enabled
+ validate_stage_layout(*result, video=video)
+ return result
+ before_denoising = (BEFORE_DENOISING_VIDEO_STAGE_ORDER if video
+ else BEFORE_DENOISING_IMAGE_STAGE_ORDER)
+ if len(order) == len(before_denoising) and set(order) == set(before_denoising):
+ if len(enabled) != len(set(enabled)) or not set(enabled) <= set(order):
+ raise ValueError("Pipeline enabled stages contain an unavailable or duplicate card.")
+ result = ("denoising", *order, "cas_sharpening"), enabled
+ validate_stage_layout(*result, video=video)
+ return result
+ previous = PREVIOUS_VIDEO_STAGE_ORDER if video else PREVIOUS_IMAGE_STAGE_ORDER
+ if len(order) == len(previous) and set(order) == set(previous):
+ if len(enabled) != len(set(enabled)) or not set(enabled) <= set(order):
+ raise ValueError("Pipeline enabled stages contain an unavailable or duplicate card.")
+ result = ("denoising", *order, "coloring", "cas_sharpening"), enabled
+ validate_stage_layout(*result, video=video)
+ return result
+ old = LEGACY_VIDEO_STAGE_ORDER if video else LEGACY_IMAGE_STAGE_ORDER
+ if len(order) != len(old) or set(order) != set(old) or len(enabled) != len(set(enabled)) or not set(enabled) <= set(old):
+ raise ValueError("Pipeline order contains unknown or duplicate processing cards.")
+ scale_dlss_active = "scale_method" in enabled and scale_method == "DLSS"
+ upscale_dlss_active = "super_resolution" in enabled and upscale_engine == "DLSS"
+ if scale_dlss_active and upscale_dlss_active:
+ dlss_origin = next(stage for stage in order if stage in {"scale_method", "super_resolution"})
+ elif scale_dlss_active:
+ dlss_origin = "scale_method"
+ else:
+ dlss_origin = "super_resolution"
+ migrated_order: list[str] = []
+ for stage in order:
+ if stage == "scale_method":
+ if dlss_origin == "scale_method":
+ migrated_order.append("dlss_super_resolution")
+ migrated_order.append(stage)
+ elif stage == "super_resolution":
+ if dlss_origin == "super_resolution":
+ migrated_order.append("dlss_super_resolution")
+ migrated_order.append(stage)
+ else:
+ migrated_order.append(stage)
+ migrated_enabled = set(enabled) - {"scale_method", "super_resolution"}
+ if "scale_method" in enabled:
+ migrated_enabled.add("dlss_super_resolution" if scale_method == "DLSS" else "scale_method")
+ if "super_resolution" in enabled:
+ migrated_enabled.add("dlss_super_resolution" if upscale_engine == "DLSS" else "super_resolution")
+ result = tuple(migrated_order), tuple(stage for stage in migrated_order if stage in migrated_enabled)
+ result = ("denoising", *result[0], "coloring", "cas_sharpening"), result[1]
+ validate_stage_layout(*result, video=video)
+ return result
+
def coerce_hdr_mode(codec: str, enabled: bool) -> bool:
return bool(enabled) and hdr_mode_supported(codec)
@@ -43,6 +151,34 @@ def parse_automatic_mask(value: str) -> bool:
@dataclass(frozen=True, slots=True)
class UISettings:
+ image_stage_order: tuple[str, ...] = IMAGE_STAGE_ORDER
+ video_stage_order: tuple[str, ...] = VIDEO_STAGE_ORDER
+ image_enabled_stages: tuple[str, ...] = ()
+ video_enabled_stages: tuple[str, ...] = ()
+ denoise_strength: int = 50
+ denoise_deblock: bool = True
+ denoise_temporal: int = 30
+ sharpening_method: str = "AMD CAS"
+ # Legacy key retained so existing CAS settings and presets keep their value.
+ cas_sharpness: int = 50
+ coloring_mode: str = "Color Match"
+ color_match_source: str = "Input Image"
+ color_match_reference: str = ""
+ lut_path: str = ""
+ lut_resolution: int = 33
+ lut_mix: int = 100
+ lut_exposure: float = 0.0
+ lut_contrast: int = 0
+ lut_highlights: int = 0
+ lut_shadows: int = 0
+ lut_whites: int = 0
+ lut_blacks: int = 0
+ lut_midtones: int = 0
+ lut_temperature: int = 0
+ lut_tint: int = 0
+ lut_hue: int = 0
+ lut_vibrance: int = 0
+ lut_saturation: int = 0
ai_gpu_uuid: str = "auto"
video_gpu_uuid: str = "auto"
nr_style: str = "Default"
@@ -62,6 +198,12 @@ class UISettings:
# Validated native file-picker identity; intentionally omitted from config/presets.
nr_mask: object | None = None
upscaling_factor: float = 1.0
+ image_scaling_filter: str = "Lanczos4"
+ video_scaling_filter: str = "Spline36"
+ nr_scale_method: str = "Standard"
+ nr_dlss_mode: str = "Quality"
+ nr_dlss_preset: str = "Default"
+ nr_preview_length: str = "3"
# Independent Live-tab mirrors of the NR controls above. The Live tab
# reads/writes only these, so tuning or resetting Live never touches
# the Neural Rendering tab (and vice versa). nr_mask stays shared:
@@ -87,6 +229,7 @@ class UISettings:
hdr_mode: bool = False
image_format: str = "PNG"
image_quality: int = 95
+ image_bit_depth: int = 8
automatic_mask: bool = False
image_rename_mode: str = "Auto"
image_custom_suffix: str = "_Neural_Rendering"
@@ -105,6 +248,9 @@ class UISettings:
preview_encoding: str = "Auto"
upscale_mode: str = "Image"
upscale_image_vsr_quality: int = 4
+ upscale_image_engine: str = "RTX Video Super Resolution"
+ upscale_image_dlss_mode: str = "Quality"
+ upscale_image_dlss_preset: str = "Default"
upscale_image_size_mode: str = "Scale factor"
upscale_image_scale_factor: float = 2.0
upscale_image_width: int = 3840
@@ -112,10 +258,12 @@ class UISettings:
upscale_image_aspect_lock: bool = True
upscale_image_output_format: str = "PNG"
upscale_image_quality: int = 95
- upscale_image_preserve_metadata: bool = True
upscale_image_rename_mode: str = "Auto"
upscale_image_custom_suffix: str = "_Upscale"
upscale_vsr_enabled: bool = True
+ upscale_engine: str = "RTX Video Super Resolution"
+ upscale_dlss_mode: str = "Quality"
+ upscale_dlss_preset: str = "Default"
upscale_vsr_quality: int = 4
upscale_size_mode: str = "Scale factor"
upscale_scale_factor: float = 2.0
@@ -187,6 +335,34 @@ DEFAULT_SETTINGS = UISettings()
def _validate(settings: UISettings) -> UISettings:
+ validate_stage_layout(settings.image_stage_order, settings.image_enabled_stages, video=False)
+ validate_stage_layout(settings.video_stage_order, settings.video_enabled_stages, video=True)
+ for name in ("denoise_strength", "denoise_temporal", "cas_sharpness"):
+ value = getattr(settings, name)
+ if isinstance(value, bool) or not isinstance(value, int) or not 0 <= value <= 100:
+ raise ValueError(f"{name} must be an integer from 0 to 100.")
+ if not isinstance(settings.denoise_deblock, bool):
+ raise ValueError("Compression artifact cleanup must be a boolean value.")
+ if settings.sharpening_method not in SHARPENING_METHODS:
+ raise ValueError(f"Unknown sharpening method: {settings.sharpening_method!r}.")
+ if settings.coloring_mode not in COLORING_MODES:
+ raise ValueError(f"Unknown Coloring mode: {settings.coloring_mode!r}.")
+ if settings.color_match_source not in COLOR_MATCH_SOURCES:
+ raise ValueError(f"Unknown Color Match source: {settings.color_match_source!r}.")
+ if not isinstance(settings.color_match_reference, str) or len(settings.color_match_reference) > 4096:
+ raise ValueError("Color Match reference must be a valid image path.")
+ if not isinstance(settings.lut_path, str) or len(settings.lut_path) > 4096:
+ raise ValueError("LUT must be a valid .cube file path.")
+ if isinstance(settings.lut_resolution, bool) or settings.lut_resolution not in LUT_RESOLUTIONS:
+ raise ValueError("LUT resolution must be 33, 65, or 129.")
+ for name, (minimum, maximum) in LUT_ADJUSTMENT_RANGES.items():
+ value = getattr(settings, name)
+ if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value):
+ raise ValueError(f"{name} must be a finite number.")
+ if name != "lut_exposure" and (not isinstance(value, int) or isinstance(value, bool)):
+ raise ValueError(f"{name} must be an integer.")
+ if not minimum <= value <= maximum:
+ raise ValueError(f"{name} must be between {minimum} and {maximum}.")
options_from_settings(settings).validate(for_render=False)
image_upscale_options(settings).validate(for_render=False)
for label, value in (
@@ -213,6 +389,13 @@ def _validate(settings: UISettings) -> UISettings:
if not 0 <= settings.live_mask_feather <= 128:
raise ValueError("Live Mask Feather must be between 0 and 128 pixels.")
resolve_upscaling_mode(settings.upscaling_factor)
+ if settings.image_scaling_filter not in IMAGE_SCALING_FILTERS:
+ raise ValueError(f"Unknown image scaling filter: {settings.image_scaling_filter!r}.")
+ if settings.video_scaling_filter not in VIDEO_SCALING_FILTERS:
+ raise ValueError(f"Unknown video scaling filter: {settings.video_scaling_filter!r}.")
+ if settings.nr_scale_method not in DLSS_METHODS:
+ raise ValueError(f"Unknown Neural Rendering scale method: {settings.nr_scale_method!r}.")
+ validate_dlss(settings.nr_dlss_mode, settings.nr_dlss_preset)
resolve_upscaling_mode(settings.live_upscaling_factor)
if not isinstance(settings.automatic_mask, bool):
raise ValueError("Automatic Mask must be a boolean value.")
@@ -272,6 +455,10 @@ def _validate(settings: UISettings) -> UISettings:
settings.upscale_preview_length,
UPSCALE_PREVIEW_LENGTH_CHOICES,
),
+ "Neural Rendering preview length": (
+ settings.nr_preview_length,
+ PREVIEW_LENGTH_CHOICES,
+ ),
"Preview encoding": (
settings.preview_encoding,
PREVIEW_ENCODING_CHOICES,
@@ -288,10 +475,16 @@ def _validate(settings: UISettings) -> UISettings:
raise ValueError("Image quality must be an integer from 1 to 100.")
if int(settings.image_quality) != settings.image_quality:
raise ValueError("Image quality must be an integer from 1 to 100.")
+ if isinstance(settings.image_bit_depth, bool) or settings.image_bit_depth not in IMAGE_BIT_DEPTH_CHOICES:
+ raise ValueError("Image bit depth must be 8 or 16 bits.")
+ if settings.image_bit_depth == 16 and settings.image_format not in IMAGE_16BIT_FORMATS:
+ raise ValueError("16-bit image output is available for PNG and TIFF only.")
validate_rename(settings.image_rename_mode, settings.image_custom_suffix)
validate_rename(settings.video_rename_mode, settings.video_custom_suffix)
validate_rename(
settings.frame_interpolation_rename_mode,
settings.frame_interpolation_custom_suffix,
)
+ options_from_settings(settings).validate(for_render=False)
+ image_upscale_options(settings).validate(for_render=False)
return settings
diff --git a/src/settings/presets.py b/src/settings/presets.py
index b85c909..f14406d 100644
--- a/src/settings/presets.py
+++ b/src/settings/presets.py
@@ -12,6 +12,7 @@ from typing import Any
from ..core.paths import APP_TEMP
from .models import (
DEFAULT_SETTINGS, MAX_PRESET_BYTES, PRESET_FORMAT, PRESET_SCHEMA_VERSION, UISettings, _validate,
+ LUT_ADJUSTMENT_RANGES, migrate_stage_layout,
)
_WINDOWS_RESERVED_NAMES = {
@@ -78,6 +79,10 @@ def export_settings_preset(name: str, settings: UISettings) -> Path:
def _coerce_preset_value(field_name: str, value: Any, current: UISettings) -> Any:
expected = getattr(current, field_name)
+ if isinstance(expected, tuple):
+ if not isinstance(value, list) or not all(isinstance(item, str) for item in value):
+ raise ValueError(f"Preset setting {field_name!r} must be a list of stage IDs.")
+ return tuple(value)
if isinstance(expected, bool):
if not isinstance(value, bool):
raise ValueError(f"Preset setting {field_name!r} must be a boolean.")
@@ -157,6 +162,107 @@ def import_settings_preset(
changes["nr_passes"] = DEFAULT_SETTINGS.nr_passes
if version < 6:
changes["shimmer_suppression"] = DEFAULT_SETTINGS.shimmer_suppression
+ if version < 8:
+ for key in (
+ "nr_scale_method", "nr_dlss_mode", "nr_dlss_preset",
+ "upscale_image_engine", "upscale_image_dlss_mode", "upscale_image_dlss_preset",
+ "upscale_engine", "upscale_dlss_mode", "upscale_dlss_preset",
+ ):
+ changes[key] = getattr(DEFAULT_SETTINGS, key)
+ if version < 9:
+ for key in ("image_stage_order", "video_stage_order", "image_enabled_stages", "video_enabled_stages"):
+ changes[key] = getattr(DEFAULT_SETTINGS, key)
+ if version < 10:
+ old_scale = changes.get("nr_scale_method", DEFAULT_SETTINGS.nr_scale_method)
+ changes["image_scaling_filter"] = "Lanczos4"
+ changes["video_scaling_filter"] = (
+ "Lanczos" if old_scale == "Standard" else DEFAULT_SETTINGS.video_scaling_filter
+ )
+ if version == 9:
+ for mode, prefix in (("Image", "image"), ("Video", "video")):
+ order_key = f"{prefix}_stage_order"
+ enabled_key = f"{prefix}_enabled_stages"
+ old_order = changes.get(order_key, getattr(DEFAULT_SETTINGS, order_key))
+ old_enabled = changes.get(enabled_key, ())
+ engine_key = "upscale_image_engine" if mode == "Image" else "upscale_engine"
+ engine = changes.get(engine_key, getattr(DEFAULT_SETTINGS, engine_key))
+ changes[order_key], changes[enabled_key] = migrate_stage_layout(
+ old_order, old_enabled, video=mode == "Video",
+ scale_method=old_scale, upscale_engine=engine,
+ )
+ if (old_scale == "DLSS" and "scale_method" in old_enabled and
+ ("super_resolution" not in old_enabled or engine != "DLSS" or
+ old_order.index("scale_method") < old_order.index("super_resolution"))):
+ mode_key = "upscale_image_dlss_mode" if mode == "Image" else "upscale_dlss_mode"
+ preset_key = "upscale_image_dlss_preset" if mode == "Image" else "upscale_dlss_preset"
+ changes[mode_key] = changes.get("nr_dlss_mode", DEFAULT_SETTINGS.nr_dlss_mode)
+ changes[preset_key] = changes.get("nr_dlss_preset", DEFAULT_SETTINGS.nr_dlss_preset)
+ changes["nr_scale_method"] = "Standard"
+ changes["upscale_image_engine"] = "RTX Video Super Resolution"
+ changes["upscale_engine"] = "RTX Video Super Resolution"
+ if not changes.get("upscale_vsr_enabled", DEFAULT_SETTINGS.upscale_vsr_enabled) and not changes.get(
+ "upscale_hdr_enabled", DEFAULT_SETTINGS.upscale_hdr_enabled
+ ):
+ changes["upscale_vsr_enabled"] = True
+ if version < 11:
+ old_order = changes.get("image_stage_order", DEFAULT_SETTINGS.image_stage_order)
+ old_enabled = changes.get("image_enabled_stages", ())
+ changes["image_stage_order"], changes["image_enabled_stages"] = migrate_stage_layout(
+ old_order, old_enabled, video=False,
+ scale_method=changes.get("nr_scale_method", DEFAULT_SETTINGS.nr_scale_method),
+ upscale_engine=changes.get("upscale_image_engine", DEFAULT_SETTINGS.upscale_image_engine),
+ )
+ for key in ("coloring_mode", "color_match_source", "color_match_reference"):
+ changes[key] = getattr(DEFAULT_SETTINGS, key)
+ if version < 12:
+ old_order = changes.get("video_stage_order", DEFAULT_SETTINGS.video_stage_order)
+ old_enabled = changes.get("video_enabled_stages", ())
+ changes["video_stage_order"], changes["video_enabled_stages"] = migrate_stage_layout(
+ old_order, old_enabled, video=True,
+ scale_method=changes.get("nr_scale_method", DEFAULT_SETTINGS.nr_scale_method),
+ upscale_engine=changes.get("upscale_engine", DEFAULT_SETTINGS.upscale_engine),
+ )
+ if changes.get("coloring_mode") == "Mode 2":
+ changes["coloring_mode"] = "LUT"
+ changes["lut_path"] = ""
+ if version < 14:
+ changes["image_bit_depth"] = DEFAULT_SETTINGS.image_bit_depth
+ if version < 15:
+ for key in ("lut_resolution", *LUT_ADJUSTMENT_RANGES):
+ changes[key] = getattr(DEFAULT_SETTINGS, key)
+ if version < 16:
+ for mode, prefix in (("Image", "image"), ("Video", "video")):
+ order_key = f"{prefix}_stage_order"
+ enabled_key = f"{prefix}_enabled_stages"
+ changes[order_key], changes[enabled_key] = migrate_stage_layout(
+ changes.get(order_key, getattr(DEFAULT_SETTINGS, order_key)),
+ changes.get(enabled_key, getattr(DEFAULT_SETTINGS, enabled_key)),
+ video=mode == "Video",
+ scale_method=changes.get("nr_scale_method", DEFAULT_SETTINGS.nr_scale_method),
+ upscale_engine=changes.get(
+ "upscale_engine" if mode == "Video" else "upscale_image_engine",
+ DEFAULT_SETTINGS.upscale_engine if mode == "Video" else DEFAULT_SETTINGS.upscale_image_engine,
+ ),
+ )
+ for key in ("denoise_strength", "denoise_deblock", "denoise_temporal"):
+ changes[key] = getattr(DEFAULT_SETTINGS, key)
+ if version < 17:
+ for mode, prefix in (("Image", "image"), ("Video", "video")):
+ order_key = f"{prefix}_stage_order"
+ enabled_key = f"{prefix}_enabled_stages"
+ changes[order_key], changes[enabled_key] = migrate_stage_layout(
+ changes.get(order_key, getattr(DEFAULT_SETTINGS, order_key)),
+ changes.get(enabled_key, getattr(DEFAULT_SETTINGS, enabled_key)),
+ video=mode == "Video",
+ scale_method=changes.get("nr_scale_method", DEFAULT_SETTINGS.nr_scale_method),
+ upscale_engine=changes.get(
+ "upscale_engine" if mode == "Video" else "upscale_image_engine",
+ DEFAULT_SETTINGS.upscale_engine if mode == "Video" else DEFAULT_SETTINGS.upscale_image_engine,
+ ),
+ )
+ changes["cas_sharpness"] = DEFAULT_SETTINGS.cas_sharpness
+ if version < 18:
+ changes["sharpening_method"] = DEFAULT_SETTINGS.sharpening_method
# NR Preset was removed entirely (non-functional). Old preset files still
# carry it; ignore so imports from previous builds keep working.
# (Unknown keys are already filtered above; this covers any edge case where
diff --git a/src/settings/storage.py b/src/settings/storage.py
index 2399152..2794728 100644
--- a/src/settings/storage.py
+++ b/src/settings/storage.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import configparser
+import json
import math
import os
import threading
@@ -11,12 +12,17 @@ from ..core.ffmpeg import HDR_ALLOWED_CODECS
from ..core.paths import CONFIG_PATH
from ..core.naming import RENAME_MODES, validate_rename
from ..core.runtime import NR_STYLES, resolve_upscaling_mode
+from ..core.dlss_modes import DLSS_METHODS, DLSS_MODES, DLSS_PRESETS
from ..frame_interpolation.models import ENGINE_CHOICES, FPS_CHOICES, PREVIEW_LENGTH_CHOICES
from .migration import _migrate_codec
from .models import (
CODEC_CHOICES, CONFIG_SECTION, CONTAINER_CHOICES, DEFAULT_SETTINGS, IMAGE_FORMAT_CHOICES,
+ IMAGE_16BIT_FORMATS, IMAGE_BIT_DEPTH_CHOICES,
PREVIEW_ENCODING_CHOICES, QUALITY_CHOICES, UPSCALE_MODE_CHOICES,
UPSCALE_PREVIEW_LENGTH_CHOICES, UISettings, _validate,
+ IMAGE_STAGE_ORDER, VIDEO_STAGE_ORDER, IMAGE_SCALING_FILTERS, VIDEO_SCALING_FILTERS,
+ LEGACY_IMAGE_STAGE_ORDER, LEGACY_VIDEO_STAGE_ORDER, COLORING_MODES, SHARPENING_METHODS,
+ COLOR_MATCH_SOURCES, LUT_ADJUSTMENT_RANGES, LUT_RESOLUTIONS, migrate_stage_layout,
)
from ..upscale.video.models import SETTING_FIELDS, options_from_settings
from ..upscale.image.models import SETTING_FIELDS as IMAGE_UPSCALE_FIELDS, options_from_settings as image_upscale_options
@@ -69,6 +75,11 @@ def load_settings(path: str | os.PathLike[str]) -> UISettings:
value = number(key, minimum, maximum, default)
return int(value) if float(value).is_integer() else default
+ def lut_resolution() -> int:
+ value = integer("lut_resolution", min(LUT_RESOLUTIONS), max(LUT_RESOLUTIONS),
+ DEFAULT_SETTINGS.lut_resolution)
+ return value if value in LUT_RESOLUTIONS else DEFAULT_SETTINGS.lut_resolution
+
def boolean(key: str, default: bool) -> bool:
raw_value = section.get(key)
if raw_value is None:
@@ -105,6 +116,11 @@ def load_settings(path: str | os.PathLike[str]) -> UISettings:
return "Cascade"
return value if value in ENGINE_CHOICES else DEFAULT_SETTINGS.frame_interpolation_engine
+ image_format = choice("image_format", IMAGE_FORMAT_CHOICES, DEFAULT_SETTINGS.image_format)
+ image_bit_depth = integer("image_bit_depth", 8, 16, DEFAULT_SETTINGS.image_bit_depth)
+ if image_bit_depth not in IMAGE_BIT_DEPTH_CHOICES or (image_bit_depth == 16 and image_format not in IMAGE_16BIT_FORMATS):
+ image_bit_depth = DEFAULT_SETTINGS.image_bit_depth
+
image_rename_mode = choice(
"image_rename_mode", RENAME_MODES, DEFAULT_SETTINGS.image_rename_mode
)
@@ -182,14 +198,44 @@ def load_settings(path: str | os.PathLike[str]) -> UISettings:
)),
automatic_mask=boolean("automatic_mask", DEFAULT_SETTINGS.automatic_mask),
upscaling_factor=upscaling_factor(),
+ image_scaling_filter=choice("image_scaling_filter", IMAGE_SCALING_FILTERS,
+ DEFAULT_SETTINGS.image_scaling_filter),
+ video_scaling_filter=choice(
+ "video_scaling_filter", VIDEO_SCALING_FILTERS,
+ "Lanczos" if section.get("nr_scale_method") == "Standard"
+ else DEFAULT_SETTINGS.video_scaling_filter,
+ ),
+ nr_scale_method=choice("nr_scale_method", DLSS_METHODS, DEFAULT_SETTINGS.nr_scale_method),
+ nr_dlss_mode=choice("nr_dlss_mode", tuple(DLSS_MODES), DEFAULT_SETTINGS.nr_dlss_mode),
+ nr_dlss_preset=choice("nr_dlss_preset", DLSS_PRESETS, DEFAULT_SETTINGS.nr_dlss_preset),
+ nr_preview_length=choice(
+ "nr_preview_length",
+ PREVIEW_LENGTH_CHOICES,
+ DEFAULT_SETTINGS.nr_preview_length,
+ ),
codec=codec_choice("codec", DEFAULT_SETTINGS.codec),
container=choice("container", CONTAINER_CHOICES, DEFAULT_SETTINGS.container),
quality=choice("quality", QUALITY_CHOICES, DEFAULT_SETTINGS.quality),
hdr_mode=hdr_mode_value(),
- image_format=choice(
- "image_format", IMAGE_FORMAT_CHOICES, DEFAULT_SETTINGS.image_format
- ),
+ image_format=image_format,
image_quality=image_quality(),
+ image_bit_depth=image_bit_depth,
+ denoise_strength=integer("denoise_strength", 0, 100, DEFAULT_SETTINGS.denoise_strength),
+ denoise_deblock=boolean("denoise_deblock", DEFAULT_SETTINGS.denoise_deblock),
+ denoise_temporal=integer("denoise_temporal", 0, 100, DEFAULT_SETTINGS.denoise_temporal),
+ cas_sharpness=integer("cas_sharpness", 0, 100, DEFAULT_SETTINGS.cas_sharpness),
+ sharpening_method=choice("sharpening_method", SHARPENING_METHODS,
+ DEFAULT_SETTINGS.sharpening_method),
+ coloring_mode=("LUT" if section.get("coloring_mode") == "Mode 2" else
+ choice("coloring_mode", COLORING_MODES, DEFAULT_SETTINGS.coloring_mode)),
+ color_match_source=choice("color_match_source", COLOR_MATCH_SOURCES,
+ DEFAULT_SETTINGS.color_match_source),
+ color_match_reference=section.get("color_match_reference", "")[:4096],
+ lut_path=section.get("lut_path", "")[:4096],
+ lut_resolution=lut_resolution(),
+ **{key: (number(key, *bounds, getattr(DEFAULT_SETTINGS, key)) if key == "lut_exposure"
+ else integer(key, *bounds, getattr(DEFAULT_SETTINGS, key)))
+ for key, bounds in LUT_ADJUSTMENT_RANGES.items()},
image_rename_mode=image_rename_mode,
image_custom_suffix=image_custom_suffix,
video_rename_mode=video_rename_mode,
@@ -315,7 +361,48 @@ def load_settings(path: str | os.PathLike[str]) -> UISettings:
upscale_values[key] = value
except (ValueError, TypeError, OverflowError):
continue
- return replace(settings, **upscale_values)
+ settings = replace(settings, **upscale_values)
+
+ def stage_values(order_key: str, enabled_key: str, default_order: tuple[str, ...], video: bool):
+ try:
+ order = tuple(json.loads(section.get(order_key, json.dumps(default_order))))
+ enabled = tuple(json.loads(section.get(enabled_key, "[]")))
+ legacy_order = LEGACY_VIDEO_STAGE_ORDER if video else LEGACY_IMAGE_STAGE_ORDER
+ legacy = len(order) == len(legacy_order) and set(order) == set(legacy_order)
+ engine = settings.upscale_engine if video else settings.upscale_image_engine
+ migrated = migrate_stage_layout(order, enabled, video=video,
+ scale_method=settings.nr_scale_method,
+ upscale_engine=engine)
+ return migrated[0], migrated[1], (order, enabled) if legacy else None
+ except (TypeError, ValueError, json.JSONDecodeError):
+ return default_order, (), None
+
+ image_order, image_enabled, old_image = stage_values("image_stage_order", "image_enabled_stages", IMAGE_STAGE_ORDER, False)
+ video_order, video_enabled, old_video = stage_values("video_stage_order", "video_enabled_stages", VIDEO_STAGE_ORDER, True)
+
+ def scale_dlss_wins(old_layout, engine: str) -> bool:
+ if not old_layout or settings.nr_scale_method != "DLSS":
+ return False
+ order, enabled = old_layout
+ return ("scale_method" in enabled and
+ ("super_resolution" not in enabled or engine != "DLSS" or
+ order.index("scale_method") < order.index("super_resolution")))
+
+ image_scale_wins = scale_dlss_wins(old_image, settings.upscale_image_engine)
+ video_scale_wins = scale_dlss_wins(old_video, settings.upscale_engine)
+ return replace(
+ settings,
+ image_stage_order=image_order, image_enabled_stages=image_enabled,
+ video_stage_order=video_order, video_enabled_stages=video_enabled,
+ upscale_image_dlss_mode=settings.nr_dlss_mode if image_scale_wins else settings.upscale_image_dlss_mode,
+ upscale_image_dlss_preset=settings.nr_dlss_preset if image_scale_wins else settings.upscale_image_dlss_preset,
+ upscale_dlss_mode=settings.nr_dlss_mode if video_scale_wins else settings.upscale_dlss_mode,
+ upscale_dlss_preset=settings.nr_dlss_preset if video_scale_wins else settings.upscale_dlss_preset,
+ upscale_image_engine="RTX Video Super Resolution",
+ upscale_engine="RTX Video Super Resolution",
+ upscale_vsr_enabled=settings.upscale_vsr_enabled or not settings.upscale_hdr_enabled,
+ nr_scale_method="Standard",
+ )
def save_settings(path: str | os.PathLike[str], settings: UISettings) -> None:
@@ -324,6 +411,21 @@ def save_settings(path: str | os.PathLike[str], settings: UISettings) -> None:
config_path.parent.mkdir(parents=True, exist_ok=True)
parser = configparser.ConfigParser()
parser[CONFIG_SECTION] = {
+ "image_stage_order": json.dumps(settings.image_stage_order),
+ "video_stage_order": json.dumps(settings.video_stage_order),
+ "image_enabled_stages": json.dumps(settings.image_enabled_stages),
+ "video_enabled_stages": json.dumps(settings.video_enabled_stages),
+ "denoise_strength": str(settings.denoise_strength),
+ "denoise_deblock": str(settings.denoise_deblock).lower(),
+ "denoise_temporal": str(settings.denoise_temporal),
+ "cas_sharpness": str(settings.cas_sharpness),
+ "sharpening_method": settings.sharpening_method,
+ "coloring_mode": settings.coloring_mode,
+ "color_match_source": settings.color_match_source,
+ "color_match_reference": settings.color_match_reference.replace("%", "%%"),
+ "lut_path": settings.lut_path.replace("%", "%%"),
+ "lut_resolution": str(settings.lut_resolution),
+ **{key: str(getattr(settings, key)) for key in LUT_ADJUSTMENT_RANGES},
**{"upscale_image_" + name: str(getattr(settings, "upscale_image_" + name)) for name in IMAGE_UPSCALE_FIELDS},
**{"upscale_" + name: str(getattr(settings, "upscale_" + name)) for name in SETTING_FIELDS},
"upscale_mode": settings.upscale_mode,
@@ -344,6 +446,12 @@ def save_settings(path: str | os.PathLike[str], settings: UISettings) -> None:
"mask_feather": str(settings.mask_feather),
"automatic_mask": str(settings.automatic_mask).lower(),
"upscaling_factor": f"{settings.upscaling_factor:g}",
+ "image_scaling_filter": settings.image_scaling_filter,
+ "video_scaling_filter": settings.video_scaling_filter,
+ "nr_scale_method": settings.nr_scale_method,
+ "nr_dlss_mode": settings.nr_dlss_mode,
+ "nr_dlss_preset": settings.nr_dlss_preset,
+ "nr_preview_length": settings.nr_preview_length,
"live_nr_style": settings.live_nr_style,
"live_nr_intensity": f"{settings.live_nr_intensity:.2f}",
"live_nr_passes": str(settings.live_nr_passes),
@@ -364,6 +472,7 @@ def save_settings(path: str | os.PathLike[str], settings: UISettings) -> None:
"hdr_mode": str(settings.hdr_mode).lower(),
"image_format": settings.image_format,
"image_quality": str(settings.image_quality),
+ "image_bit_depth": str(settings.image_bit_depth),
"image_rename_mode": settings.image_rename_mode,
"image_custom_suffix": settings.image_custom_suffix,
"video_rename_mode": settings.video_rename_mode,
@@ -411,4 +520,3 @@ def current_preview_encoding() -> str:
with SETTINGS_STATE.lock:
settings = SETTINGS_STATE.current or load_settings(CONFIG_PATH)
return normalize_preview_encoding(settings.preview_encoding)
-
diff --git a/src/upscale/image/batch.py b/src/upscale/image/batch.py
index a135937..39c188f 100644
--- a/src/upscale/image/batch.py
+++ b/src/upscale/image/batch.py
@@ -28,7 +28,8 @@ def upscale_images(input_paths, options=None, progress=None, *, output_dir=None,
with active_job(controller):
if controller.cancel.is_set():
raise Cancelled("Stopped before rendering.")
- caps = probe_capabilities(options.ai_gpu_uuid, controller=controller)
+ caps = (probe_capabilities(options.ai_gpu_uuid, controller=controller)
+ if options.engine != "DLSS" else None)
for i, path in enumerate(paths):
if controller.cancel.is_set():
break
diff --git a/src/upscale/image/models.py b/src/upscale/image/models.py
index fb0a505..a77d07d 100644
--- a/src/upscale/image/models.py
+++ b/src/upscale/image/models.py
@@ -5,11 +5,15 @@ from dataclasses import dataclass, field, fields
from ..video.models import SCALE_FACTORS, SIZE_MODES, TEXTURE_LIMIT, VSR_QUALITIES, UpscaleOptions
from ...core.naming import validate_rename
+from ...core.dlss_modes import UPSCALE_ENGINES, dlss_output_size, validate_dlss
from ...neural_rendering.image.models import IMAGE_FORMATS, IMAGE_EXTENSIONS
@dataclass(slots=True)
class ImageUpscaleOptions:
+ engine: str = "RTX Video Super Resolution"
+ dlss_mode: str = "Quality"
+ dlss_preset: str = "Default"
vsr_quality: int = 4
size_mode: str = "Scale factor"
scale_factor: float = 2.0
@@ -18,12 +22,14 @@ class ImageUpscaleOptions:
aspect_lock: bool = True
output_format: str = "PNG"
quality: int = 95
- preserve_metadata: bool = True
rename_mode: str = "Auto"
custom_suffix: str = "_Upscale"
ai_gpu_uuid: str = "auto"
def validate(self, *, for_render: bool = True):
+ if self.engine not in UPSCALE_ENGINES:
+ raise ValueError(f"Unknown image upscale engine: {self.engine!r}.")
+ validate_dlss(self.dlss_mode, self.dlss_preset)
for name, low, high in (("vsr_quality", 1, 4), ("width", 1, TEXTURE_LIMIT),
("height", 1, TEXTURE_LIMIT), ("quality", 1, 100)):
value = getattr(self, name)
@@ -35,8 +41,8 @@ class ImageUpscaleOptions:
raise ValueError("Scale factor must be a finite number of at least 1.")
if self.size_mode not in SIZE_MODES or self.output_format not in IMAGE_FORMATS:
raise ValueError("Unknown image sizing mode or output format.")
- if not isinstance(self.aspect_lock, bool) or not isinstance(self.preserve_metadata, bool):
- raise ValueError("Aspect lock and metadata preservation must be on or off.")
+ if not isinstance(self.aspect_lock, bool):
+ raise ValueError("Aspect lock must be on or off.")
validate_rename(self.rename_mode, self.custom_suffix)
def native_options(self):
@@ -54,6 +60,8 @@ def options_from_settings(settings):
def output_size(width, height, options):
options.validate()
+ if options.engine == "DLSS":
+ return dlss_output_size(width, height, options.dlss_mode)
if min(width, height) < 1 or max(width, height) > TEXTURE_LIMIT:
raise ValueError("Input dimensions must be between 1 and 16384 pixels.")
if options.size_mode == "Scale factor":
diff --git a/src/upscale/image/processor.py b/src/upscale/image/processor.py
index 6db71ee..01c7c88 100644
--- a/src/upscale/image/processor.py
+++ b/src/upscale/image/processor.py
@@ -11,6 +11,7 @@ from PIL import Image
from ..video.native import RTXVideoSession, probe_capabilities
from ...core import app_log
+from ...core.dlss_bridge import process_image as process_dlss_image
from ...core.disk_paths import OutputFile, prepare_output_dir
from ...core.jobs import Cancelled, active_job
from ...core.naming import output_filename, unique_output_path
@@ -67,6 +68,25 @@ def preview_upscale_image(input_path, options=None, progress=None, *, controller
height, width = decoded.rgba.shape[:2]
ow, oh = output_size(width, height, options)
+ if options.engine == "DLSS":
+ update(.12, "Processing DLSS image")
+ processed, details = process_dlss_image(
+ decoded.rgba, options.dlss_mode, options.dlss_preset,
+ gpu_uuid=options.ai_gpu_uuid, controller=controller,
+ )
+ update(.88, "Preparing preview")
+ preview = save_full_size_image_preview(
+ processed, options.output_format, decoded.alpha is not None)
+ status = (
+ f"Preview complete: {source.name} | {width}×{height} → {ow}×{oh} | "
+ f"DLSS {options.dlss_mode}, preset {options.dlss_preset}, "
+ f"one evaluation | source-anchored DLSS | GPU: {details['gpu']} | "
+ f"{time.monotonic() - started:.2f}s.\n"
+ "Preview only — no production output image was saved."
+ )
+ update(1.0, "Preview ready")
+ return preview, status
+
update(.12, "Checking RTX Video capabilities")
caps = probe_capabilities(options.ai_gpu_uuid, controller=controller)
update(.24, "Processing with RTX VSR")
@@ -130,43 +150,35 @@ def _process(source, options, progress, output_dir, controller, generate_preview
decoded = decode_image(source)
height, width = decoded.rgba.shape[:2]
ow, oh = output_size(width, height, options)
- caps = capabilities or probe_capabilities(options.ai_gpu_uuid, controller=controller)
+ is_dlss = options.engine == "DLSS"
+ caps = None if is_dlss else (capabilities or probe_capabilities(options.ai_gpu_uuid, controller=controller))
output = unique_output_path(prepare_output_dir(output_dir) / output_filename(
source, IMAGE_EXTENSIONS[options.output_format], options.rename_mode, options.custom_suffix,
- f"{source.stem}_RTXIMAGE_{stamp}"))
+ f"{source.stem}_{'DLSS' if is_dlss else 'RTXIMAGE'}_{stamp}"))
destination_file = OutputFile(output)
- update(.15, "Processing with RTX VSR")
- key = (width, height, ow, oh, int(options.vsr_quality), str(caps.gpu.get("uuid", "")))
- if session_cache is None:
- session_context = RTXVideoSession(
- width, height, ow, oh, options.native_options(), 1, caps, controller,
- image_srgb=True)
+ update(.15, "Processing with DLSS" if is_dlss else "Processing with RTX VSR")
+ if is_dlss:
+ processed, details = process_dlss_image(
+ decoded.rgba, options.dlss_mode, options.dlss_preset,
+ gpu_uuid=options.ai_gpu_uuid, controller=controller,
+ )
+ app_log.info("upscale-image", f"DLSS mode={options.dlss_mode} preset={options.dlss_preset} evaluations={details['evaluations']} guides=estimated render={details['render_width']}x{details['render_height']}")
else:
- session = session_cache.get(key)
- if session is None or session.closed:
- session = RTXVideoSession(
- width, height, ow, oh, options.native_options(), 1, caps, controller,
- image_srgb=True)
- session_cache[key] = session
- session_context = nullcontext(session)
- with session_context as session:
- before = session.completed_frames
- processed = np.frombuffer(
- session.process_frame(np.ascontiguousarray(decoded.rgba)), dtype=np.uint8
- ).reshape(oh, ow, 4).copy()
- if session.completed_frames != before + 1:
- raise RuntimeError("RTX VSR did not process exactly one image.")
+ processed = None
+ if not is_dlss:
+ processed = _process_vsr_frame(decoded, width, height, ow, oh, options, caps, controller, session_cache)
+ assert processed is not None
update(.80, "Saving image")
export = ImageConversionOptions(output_format=options.output_format, quality=int(options.quality),
- preserve_metadata=options.preserve_metadata)
+ preserve_metadata=False)
warnings = list(decoded.warnings)
- warnings.extend(_encode_image(destination_file.temporary, processed, export, decoded.metadata,
+ warnings.extend(_encode_image(destination_file.temporary, processed, export, {},
generate_preview=generate_previews, preview_path=output, controller=controller,
has_transparency=decoded.alpha is not None))
with Image.open(destination_file.temporary) as saved:
saved.load()
if saved.size != (ow, oh):
- raise RuntimeError("Saved image dimensions do not match the VSR output.")
+ raise RuntimeError("Saved image dimensions do not match the upscale output.")
update(.98, "Verifying output")
elapsed = time.monotonic() - started
app_log.info("upscale-image", f"done src={source.name} out={output.name} elapsed={elapsed:.1f}s")
@@ -186,3 +198,27 @@ def _process(source, options, progress, output_dir, controller, generate_preview
finally:
if destination_file:
destination_file.cleanup()
+
+
+def _process_vsr_frame(decoded, width, height, ow, oh, options, caps, controller, session_cache):
+ key = (width, height, ow, oh, int(options.vsr_quality), str(caps.gpu.get("uuid", "")))
+ if session_cache is None:
+ session_context = RTXVideoSession(
+ width, height, ow, oh, options.native_options(), 1, caps, controller,
+ image_srgb=True)
+ else:
+ session = session_cache.get(key)
+ if session is None or session.closed:
+ session = RTXVideoSession(
+ width, height, ow, oh, options.native_options(), 1, caps, controller,
+ image_srgb=True)
+ session_cache[key] = session
+ session_context = nullcontext(session)
+ with session_context as session:
+ before = session.completed_frames
+ processed = np.frombuffer(
+ session.process_frame(np.ascontiguousarray(decoded.rgba)), dtype=np.uint8
+ ).reshape(oh, ow, 4).copy()
+ if session.completed_frames != before + 1:
+ raise RuntimeError("RTX VSR did not process exactly one image.")
+ return processed
diff --git a/src/upscale/video/batch.py b/src/upscale/video/batch.py
index 798888a..51fff6f 100644
--- a/src/upscale/video/batch.py
+++ b/src/upscale/video/batch.py
@@ -27,7 +27,8 @@ def upscale_videos(input_paths, options=None, progress=None, *, output_dir=None,
with active_job(controller):
if controller.cancel.is_set():
raise Cancelled("Stopped before rendering.")
- caps = probe_capabilities(options.ai_gpu_uuid, controller=controller)
+ caps = (probe_capabilities(options.ai_gpu_uuid, controller=controller)
+ if options.engine != "DLSS" or options.hdr_enabled else None)
for i, path in enumerate(paths):
if controller.cancel.is_set():
break
diff --git a/src/upscale/video/cuda_pipeline.py b/src/upscale/video/cuda_pipeline.py
index 5d0c469..91af397 100644
--- a/src/upscale/video/cuda_pipeline.py
+++ b/src/upscale/video/cuda_pipeline.py
@@ -12,6 +12,7 @@ import threading
import time
import uuid
from contextlib import suppress
+from dataclasses import replace
from fractions import Fraction
from pathlib import Path
from typing import Any, Callable
@@ -32,6 +33,86 @@ from .native import RTXVideoSession, probe_capabilities
from .cuda_transfer import CudaTransferPool
+class DLSSNeedsHostFallback(RuntimeError):
+ """The decoder could not expose a CUDA frame for this source."""
+
+
+class _DLSSVideoAdapter:
+ def __init__(self, width, height, options, output_p010, controller, capabilities):
+ from ...core.dlss_bridge import DLSSSession
+ self.dlss = DLSSSession(width, height, options.dlss_mode, options.dlss_preset,
+ gpu_uuid=options.ai_gpu_uuid, even=True)
+ self.options = options
+ self.output_p010 = output_p010
+ self.hdr = None
+ self.closed = False
+ self.cuts = 0
+ if options.hdr_enabled:
+ self.hdr = RTXVideoSession(
+ self.dlss.output_width, self.dlss.output_height,
+ self.dlss.output_width, self.dlss.output_height,
+ replace(options, vsr_enabled=False),
+ 2 if output_p010 else 1, capabilities, controller)
+
+ @property
+ def completed_frames(self):
+ return self.dlss.frames
+
+ def process_cuda_frame(self, frame, *, color_matrix=1, color_range=0,
+ color_primaries=1, color_transfer=0, chroma_location=1,
+ rotation=0, output_p010=False):
+ intermediate, detail = self.dlss.process_cuda_frame(
+ frame, color_matrix=color_matrix, color_range=color_range,
+ rotation=rotation, phase=self.dlss.frames,
+ output_p010=output_p010)
+ self.cuts += int(detail["scene_cut"])
+ if self.hdr is None:
+ return intermediate, detail
+ intermediate.pts = getattr(frame, "pts", None)
+ if getattr(frame, "time_base", None) is not None:
+ intermediate.time_base = frame.time_base
+ else:
+ intermediate.time_base = Fraction(1, 1000)
+ intermediate.duration = getattr(frame, "duration", None)
+ try:
+ processed, hdr_detail = self.hdr.process_cuda_frame(
+ intermediate, color_matrix=color_matrix, color_range=color_range,
+ color_primaries=color_primaries, color_transfer=color_transfer,
+ chroma_location=chroma_location, output_p010=True)
+ finally:
+ del intermediate
+ return processed, {
+ "input_ms": float(detail["input_ms"]) + float(hdr_detail["input_ms"]),
+ "ngx_ms": float(detail["ngx_ms"]) + float(hdr_detail["ngx_ms"]),
+ "output_ms": float(detail["output_ms"]) + float(hdr_detail["output_ms"]),
+ }
+
+ def structured_status(self, *, decode_backend, encode_backend):
+ result = self.dlss.last_result
+ status = {
+ "engine": "DLSS Super Resolution", "bridge_version": "DLSS ABI 1",
+ "mode": self.options.dlss_mode, "preset": self.options.dlss_preset,
+ "guide_estimated": True, "frames": self.dlss.frames,
+ "media_pipeline": "source-anchored DLSS", "synthetic_jitter": False,
+ "scene_cuts": self.cuts, "memory_path": "cuda_d3d12_shared",
+ "decode_backend": decode_backend, "encode_backend": encode_backend,
+ "render_width": result.render_width, "render_height": result.render_height,
+ "gpu_pre_resize": (result.render_width, result.render_height) != (
+ self.dlss.width, self.dlss.height),
+ }
+ if self.hdr is not None:
+ status["rtx_video_hdr"] = self.hdr.structured_status(
+ decode_backend="CUDA DLSS", encode_backend=encode_backend)
+ return status
+
+ def close(self, abort=False):
+ if not self.closed:
+ if self.hdr is not None:
+ self.hdr.close(abort=abort)
+ self.dlss.close()
+ self.closed = True
+
+
_NVENC_CODEC = {
"H.264 (NVIDIA NVENC)": "h264_nvenc",
"H.265 (NVIDIA NVENC)": "hevc_nvenc",
@@ -150,11 +231,17 @@ class _SoftwareNormalizer:
final_format = "gbrp10le" if ten_bit else "rgba"
graph = av.filter.Graph()
source = graph.add_buffer(template=frame)
- colors = graph.add(
- "colorspace",
- f"ispace={matrix}:iprimaries={primaries}:itrc={transfer}:irange={color_range}:"
- f"all=bt709:trc=gamma22:range=pc:format={precision}",
- )
+ if av.VideoFormat(str(stream.get("pix_fmt") or "yuv420p")).is_rgb:
+ # Lossless FFV1 intermediates in the ordered workflow are RGB.
+ # FFmpeg's colorspace filter does not accept ispace=gbr. Preserve
+ # the RGB pixels and depth directly at this stage boundary.
+ colors = graph.add("format", "gbrp10le" if ten_bit else "gbrp")
+ else:
+ colors = graph.add(
+ "colorspace",
+ f"ispace={matrix}:iprimaries={primaries}:itrc={transfer}:irange={color_range}:"
+ f"all=bt709:trc=gamma22:range=pc:format={precision}",
+ )
source.link_to(colors)
node = colors
rotation = int(metadata["rotation"])
@@ -252,14 +339,15 @@ def convert_video_cuda_nvenc(
stamp = time.strftime("%Y%m%d-%H%M%S") + "-" + uuid.uuid4().hex[:8]
extension = {"MP4": ".mp4", "MKV": ".mkv", "MOV": ".mov"}[options.container]
destination = prepare_output_dir(output_dir)
- kind = "RTXVIDEO_PREVIEW" if preview else "RTXVIDEO"
+ kind = ("DLSS_PREVIEW" if preview else "DLSS") if options.engine == "DLSS" else (
+ "RTXVIDEO_PREVIEW" if preview else "RTXVIDEO")
output = unique_output_path(destination / output_filename(
source, extension, "Auto" if preview else options.rename_mode,
options.custom_suffix, f"{source.stem}_{kind}_{stamp}",
))
destination_file = OutputFile(output)
JOBS.mkdir(exist_ok=True)
- session: RTXVideoSession | None = None
+ session: RTXVideoSession | _DLSSVideoAdapter | None = None
decoded_container: Any | None = None
encoded_container: Any | None = None
delivered = 0
@@ -305,6 +393,8 @@ def convert_video_cuda_nvenc(
except StopIteration as exc:
raise ValueError("The input contains no decodable video frames.") from exc
timings["decode_seconds"] += time.perf_counter() - decode_start
+ if options.engine == "DLSS" and first_frame.format.name != "cuda":
+ raise DLSSNeedsHostFallback("NVDEC did not expose a CUDA frame.")
encoded_container = av.open(str(temp_video), mode="w")
output_stream = encoded_container.add_stream(codec_name, rate=metadata["rate"], hwaccel=encode_device)
@@ -331,11 +421,16 @@ def convert_video_cuda_nvenc(
_set_color_properties(output_stream.codec_context, bool(options.hdr_enabled))
# Force decoder and encoder CUDA contexts to exist before NGX.
output_stream.codec_context.open()
- capabilities = capabilities or probe_capabilities(options.ai_gpu_uuid, controller=controller)
- session = RTXVideoSession(
- width, height, output_width, output_height, options, input_format,
- capabilities, controller,
- )
+ if options.engine == "DLSS":
+ capabilities = (capabilities or probe_capabilities(
+ options.ai_gpu_uuid, controller=controller)) if options.hdr_enabled else None
+ session = _DLSSVideoAdapter(
+ width, height, options, output_p010, controller, capabilities)
+ else:
+ capabilities = capabilities or probe_capabilities(options.ai_gpu_uuid, controller=controller)
+ session = RTXVideoSession(
+ width, height, output_width, output_height, options, input_format,
+ capabilities, controller)
if encode_ordinal != ai_ordinal:
transfer_pool = CudaTransferPool(ai_ordinal, encode_ordinal, controller)
@@ -449,6 +544,8 @@ def convert_video_cuda_nvenc(
rotation=int(metadata["rotation"]), output_p010=output_p010,
)
else:
+ if options.engine == "DLSS":
+ raise RuntimeError("DLSS CUDA decoding changed to software mid-stream.")
decode_backends.add("software")
tick = time.perf_counter()
if software_normalizer is None:
@@ -515,7 +612,7 @@ def convert_video_cuda_nvenc(
)
session.close()
if session.completed_frames != delivered:
- raise RuntimeError("RTX Video bridge completion does not match frame accounting.")
+ raise RuntimeError("GPU bridge completion does not match frame accounting.")
gc.collect()
if not preview and (not metadata["frames"] or delivered != metadata["frames"]):
@@ -586,7 +683,7 @@ def convert_video_cuda_nvenc(
return UpscaleResult(
str(output), report_path, delivered, output_width, output_height,
options.hdr_enabled, elapsed,
- bridge_version=str(capabilities.bridge_version),
+ bridge_version=("DLSS ABI 1" if options.engine == "DLSS" else str(capabilities.bridge_version)),
memory_path=str(session_status["memory_path"]),
decode_backend=str(session_status["decode_backend"]),
encode_backend=codec_name, timings=timings, bridge_status=session_status,
diff --git a/src/upscale/video/dlss_pipeline.py b/src/upscale/video/dlss_pipeline.py
new file mode 100644
index 0000000..aab7faa
--- /dev/null
+++ b/src/upscale/video/dlss_pipeline.py
@@ -0,0 +1,247 @@
+"""DLSS video route with separate optional RTX Video HDR evaluation."""
+
+from __future__ import annotations
+
+import math
+import tempfile
+import time
+import uuid
+from contextlib import suppress
+from fractions import Fraction
+from pathlib import Path
+
+import av
+import cv2
+import numpy as np
+from av.codec.hwaccel import HWAccel
+
+from ...core import app_log, ffmpeg
+from ...core.disk_paths import OutputFile, prepare_output_dir
+from ...core.dlss_bridge import DLSSSession
+from ...core.gpu_selection import detect_gpu
+from ...core.jobs import Cancelled
+from ...core.naming import output_filename, unique_output_path
+from ...core.paths import JOBS
+from ...neural_rendering.video.guides import TemporalGuideGenerator
+from .media import inspect_video, result_frame
+from .models import UpscaleResult, output_size
+from .native import FORMAT_RGBA8, FORMAT_R10, RTXVideoSession, probe_capabilities
+
+
+def convert_video_dlss(source, options, *, controller, progress=None, output_dir=None,
+ metadata=None, video_gpu=None):
+ started = time.perf_counter()
+ metadata = metadata or inspect_video(source, controller, reject_hdr=True)
+ width, height = int(metadata["width"]), int(metadata["height"])
+ ow, oh, _ = output_size(width, height, options)
+ gpu = detect_gpu(options.ai_gpu_uuid)
+ ordinal = int(gpu["cuda_ordinal"])
+ source_high_depth = int(metadata["depth"]) > 8
+ output_depth = ffmpeg.output_video_depth(metadata["depth"], options.codec, options.hdr_enabled)
+ preview = options.preview_frames is not None or options.preview_seconds is not None
+ extension = {"MP4": ".mp4", "MKV": ".mkv", "MOV": ".mov"}[options.container]
+ stamp = time.strftime("%Y%m%d-%H%M%S") + "-" + uuid.uuid4().hex[:8]
+ destination = prepare_output_dir(output_dir)
+ output = unique_output_path(destination / output_filename(
+ source, extension, "Auto" if preview else options.rename_mode,
+ options.custom_suffix, f"{source.stem}_DLSS_{stamp}"))
+ output_file = OutputFile(output)
+ report_path = app_log.session_path()
+ input_container = None
+ encoder = None
+ writer = None
+ hdr_session = None
+ dlss = None
+ delivered = 0
+ cuts = 0
+ timings = {"decode_seconds": 0.0, "dlss_seconds": 0.0,
+ "hdr_seconds": 0.0, "encode_seconds": 0.0}
+
+ def update(value, message):
+ if controller.cancel.is_set():
+ raise Cancelled("DLSS upscale stopped by user.")
+ if progress:
+ progress(value, message)
+
+ JOBS.mkdir(exist_ok=True)
+ try:
+ with tempfile.TemporaryDirectory(prefix="dlss-video-", dir=JOBS) as work:
+ temp_video = Path(work) / "encoded.mkv"
+ update(.01, "Starting DLSS Super Resolution")
+ dlss = DLSSSession(width, height, options.dlss_mode, options.dlss_preset,
+ gpu_uuid=options.ai_gpu_uuid, even=True)
+ if (dlss.output_width, dlss.output_height) != (ow, oh):
+ raise RuntimeError("DLSS output sizing differs from the video encoder size.")
+ if options.hdr_enabled:
+ from dataclasses import replace
+ caps = probe_capabilities(options.ai_gpu_uuid, controller=controller)
+ hdr_session = RTXVideoSession(
+ ow, oh, ow, oh, replace(options, vsr_enabled=False),
+ FORMAT_R10 if source_high_depth else FORMAT_RGBA8, caps, controller)
+ encoder, encoder_thread, encoder_logs, selected, quality = ffmpeg.start_encoder(
+ temp_video, options.codec, options.quality, controller, ow, oh,
+ float(metadata["rate"]),
+ None if video_gpu is None else int(video_gpu["cuda_ordinal"]),
+ video_gpu is not None, hdr_mode=options.hdr_enabled,
+ hdr_metadata={
+ "color_space": "bt2020nc" if options.hdr_enabled else "bt709",
+ "color_primaries": "bt2020" if options.hdr_enabled else "bt709",
+ "color_transfer": "smpte2084" if options.hdr_enabled else "bt709",
+ "color_range": "tv", "hdr": options.hdr_enabled,
+ }, preserve_timestamps=True, bounded_logs=True,
+ output_depth=output_depth)
+ decode_device = HWAccel(
+ "cuda", device=str(ordinal), allow_software_fallback=True,
+ options={"primary_ctx": "1"}, is_hw_owned=True)
+ input_container = av.open(str(source), hwaccel=decode_device)
+ stream = input_container.streams.video[0]
+ stream.thread_type = "AUTO"
+ stream_tb = stream.time_base or Fraction(1, max(1, round(float(metadata["rate"]))))
+ writer = ffmpeg.RawVideoPacketMuxer(
+ encoder.stdin, width=ow, height=oh, rate=metadata["rate"],
+ time_base=stream_tb, pix_fmt="rgba64le" if output_depth > 8 else "rgba")
+ guides = TemporalGuideGenerator(width, height, cut_threshold=0.10)
+ first_pts = None
+ last_pts = None
+ default_duration = max(1, round(Fraction(1) / metadata["rate"] / stream_tb))
+ estimated = int(metadata["frames"] or max(1, math.ceil(metadata["duration"] * float(metadata["rate"]))))
+ for frame in input_container.decode(stream):
+ if frame.is_corrupt:
+ raise RuntimeError("The source decoder returned a corrupt frame.")
+ decode_tick = time.perf_counter()
+ pts = round(Fraction(frame.pts) * (frame.time_base or stream_tb) / stream_tb) if frame.pts is not None else (
+ 0 if last_pts is None else last_pts + default_duration)
+ if last_pts is not None and pts <= last_pts:
+ pts = last_pts + default_duration
+ if first_pts is None:
+ first_pts = pts
+ if ((options.preview_frames is not None and delivered >= int(options.preview_frames)) or
+ (options.preview_seconds is not None and delivered and
+ float(Fraction(pts - first_pts) * stream_tb) >= options.preview_seconds)):
+ break
+ rgba = frame.to_ndarray(format="rgba64le" if source_high_depth else "rgba")
+ rotation = int(metadata["rotation"])
+ if rotation:
+ rgba = cv2.rotate(rgba, {90: cv2.ROTATE_90_CLOCKWISE,
+ 180: cv2.ROTATE_180,
+ 270: cv2.ROTATE_90_COUNTERCLOCKWISE}[rotation])
+ if rgba.shape[:2] != (height, width):
+ rgba = cv2.resize(rgba, (width, height), interpolation=cv2.INTER_LANCZOS4)
+ rgba = np.ascontiguousarray(rgba)
+ timings["decode_seconds"] += time.perf_counter() - decode_tick
+ guide = guides.process(rgba)
+ cuts += int(delivered > 0 and guide.reset)
+ dlss_tick = time.perf_counter()
+ result = dlss.process(rgba, reset=guide.reset, phase=delivered)
+ timings["dlss_seconds"] += time.perf_counter() - dlss_tick
+ processed_float = np.clip(result.astype(np.float32), 0, 1)
+ if hdr_session is not None:
+ hdr_tick = time.perf_counter()
+ if source_high_depth:
+ rgb10 = np.rint(processed_float[..., :3] * 1023).astype(np.uint32)
+ hdr_input = np.ascontiguousarray(
+ rgb10[..., 0] | (rgb10[..., 1] << 10) |
+ (rgb10[..., 2] << 20) | np.uint32(3 << 30))
+ else:
+ hdr_input = np.rint(processed_float * 255).astype(np.uint8)
+ hdr_input[..., 3] = 255
+ hdr_data = hdr_session.process_frame(hdr_input)
+ hdr_frame = result_frame(hdr_data, ow, oh, 2)
+ processed = np.ascontiguousarray(hdr_frame.to_ndarray(format="rgba64le"))
+ timings["hdr_seconds"] += time.perf_counter() - hdr_tick
+ else:
+ levels = 65535 if output_depth > 8 else 255
+ processed = np.rint(processed_float * levels).astype(
+ np.uint16 if output_depth > 8 else np.uint8)
+ processed[..., 3] = levels
+ encode_tick = time.perf_counter()
+ duration = round(Fraction(frame.duration or default_duration) *
+ (frame.time_base or stream_tb) / stream_tb)
+ writer.write(processed, pts - first_pts if preview else pts, max(1, duration))
+ timings["encode_seconds"] += time.perf_counter() - encode_tick
+ delivered += 1
+ last_pts = pts
+ if delivered % 4 == 0:
+ update(min(.86, .04 + .82 * delivered / max(1, estimated)), "DLSS video processing")
+ if not delivered:
+ raise ValueError("The source contains no decodable video frames.")
+ writer.close(); writer = None
+ encoder.stdin.close()
+ if encoder.wait(timeout=600) != 0:
+ encoder_thread.join(timeout=2)
+ raise RuntimeError("Video encoder failed: " + "\n".join(list(encoder_logs)[-20:]))
+ encoder_thread.join(timeout=2)
+ controller.unregister(encoder)
+ encoder = None
+ input_container.close(); input_container = None
+ if hdr_session:
+ if hdr_session.completed_frames != delivered:
+ raise RuntimeError("RTX Video HDR frame count does not match DLSS output.")
+ hdr_session.close(); hdr_session = None
+ if dlss.frames != delivered:
+ raise RuntimeError("DLSS frame count does not match the source.")
+ if not preview and (not metadata["frames"] or delivered != metadata["frames"]):
+ source_count = ffmpeg.probe_video(
+ source, count_mode="exact", strict_decode=True, controller=controller)
+ if int(source_count["frames"]) != delivered:
+ raise RuntimeError(
+ f"Source has {source_count['frames']} frames but DLSS processed {delivered}.")
+ render_w, render_h = dlss.last_result.render_width, dlss.last_result.render_height
+ dlss.close(); dlss = None
+ update(.90, "Muxing audio and metadata")
+ audio_info = {}
+ ffmpeg.final_mux(temp_video, source, output_file.temporary, options.container,
+ controller, preserve_supported_subtitles=True,
+ source_time_origin=metadata["origin"], audio_diagnostics=audio_info,
+ video_color_metadata={
+ "color_space": "bt2020nc" if options.hdr_enabled else "bt709",
+ "color_primaries": "bt2020" if options.hdr_enabled else "bt709",
+ "color_transfer": "smpte2084" if options.hdr_enabled else "bt709",
+ "color_range": "tv"})
+ update(.96, "Verifying output")
+ saved = ffmpeg.probe_video(output_file.temporary, count_mode="exact",
+ strict_decode=True, controller=controller)
+ if (int(saved["frames"]) != delivered or
+ (int(saved["width"]), int(saved["height"])) != (ow, oh)):
+ raise RuntimeError("DLSS output has an incorrect frame count or size.")
+ if options.hdr_enabled:
+ verified = inspect_video(output_file.temporary, controller)
+ if (not verified["hdr"] or verified["depth"] < 10 or
+ verified["stream"].get("color_primaries") != "bt2020" or
+ verified["stream"].get("color_space") != "bt2020nc"):
+ raise RuntimeError("DLSS → RTX Video HDR output lost HDR signaling.")
+ elapsed = time.perf_counter() - started
+ status = {
+ "engine": "DLSS Super Resolution", "mode": options.dlss_mode,
+ "preset": options.dlss_preset, "guide_estimated": True,
+ "media_pipeline": "source-anchored DLSS", "synthetic_jitter": False,
+ "render_width": render_w, "render_height": render_h,
+ "gpu_pre_resize": (render_w, render_h) != (width, height),
+ "scene_cuts": cuts, "frames": delivered,
+ "rtx_video_hdr": bool(options.hdr_enabled),
+ "audio_streams": audio_info.get("streams", []),
+ "timings": timings,
+ }
+ output_file.publish()
+ app_log.info("upscale-dlss", f"done src={source.name} out={output.name} frames={delivered} mode={options.dlss_mode} preset={options.dlss_preset} fps={delivered/max(elapsed, 1e-9):.2f}")
+ update(1.0, "Complete — DLSS evaluated")
+ return UpscaleResult(str(output), report_path, delivered, ow, oh,
+ options.hdr_enabled, elapsed, bridge_version="DLSS ABI 1",
+ memory_path="host_rgba_d3d12_host_encoder",
+ decode_backend="NVDEC/software", encode_backend=selected,
+ timings=timings, bridge_status=status)
+ finally:
+ if writer:
+ with suppress(Exception): writer.close()
+ if input_container:
+ with suppress(Exception): input_container.close()
+ if hdr_session:
+ with suppress(Exception): hdr_session.close(abort=True)
+ if dlss:
+ dlss.close()
+ if encoder:
+ with suppress(Exception):
+ if encoder.poll() is None: encoder.kill()
+ encoder.wait(timeout=5)
+ controller.unregister(encoder)
+ output_file.cleanup()
diff --git a/src/upscale/video/models.py b/src/upscale/video/models.py
index 6e2d0f3..adaebd1 100644
--- a/src/upscale/video/models.py
+++ b/src/upscale/video/models.py
@@ -6,6 +6,7 @@ from fractions import Fraction
from ...core.ffmpeg import CODEC_CHOICES, ENCODING_QUALITIES, container_for_codec, hdr_mode_supported, validate_codec_container
from ...core.naming import validate_rename
+from ...core.dlss_modes import UPSCALE_ENGINES, dlss_output_size, validate_dlss
VSR_QUALITIES = [("1 - Low", 1), ("2 - Medium", 2), ("3 - High", 3), ("4 - Ultra", 4)]
SCALE_FACTORS = [("1×", 1.0), ("1.5×", 1.5), ("2×", 2.0), ("3×", 3.0), ("4×", 4.0)]
@@ -17,6 +18,9 @@ TEXTURE_LIMIT = 16384
@dataclass(slots=True)
class UpscaleOptions:
+ engine: str = "RTX Video Super Resolution"
+ dlss_mode: str = "Quality"
+ dlss_preset: str = "Default"
vsr_enabled: bool = True
vsr_quality: int = 4
size_mode: str = "Scale factor"
@@ -41,6 +45,9 @@ class UpscaleOptions:
preview_frames: int | None = None
def validate(self, *, for_render: bool = True) -> None:
+ if self.engine not in UPSCALE_ENGINES:
+ raise ValueError(f"Unknown upscale engine: {self.engine!r}.")
+ validate_dlss(self.dlss_mode, self.dlss_preset)
for name in ("vsr_enabled", "hdr_enabled", "aspect_lock"):
if not isinstance(getattr(self, name), bool):
raise ValueError(f"{name} must be on or off.")
@@ -63,7 +70,7 @@ class UpscaleOptions:
if for_render:
validate_codec_container(self.codec, self.container)
validate_rename(self.rename_mode, self.custom_suffix)
- if for_render and not (self.vsr_enabled or self.hdr_enabled):
+ if for_render and self.engine != "DLSS" and not (self.vsr_enabled or self.hdr_enabled):
raise ValueError("Enable RTX Video Super Resolution or RTX Video HDR.")
if self.hdr_enabled and not hdr_mode_supported(self.codec):
raise ValueError("RTX Video HDR requires a 10-bit or higher video codec.")
@@ -96,6 +103,9 @@ def output_size(width: int, height: int, options: UpscaleOptions, sar: Fraction
"""Return square-pixel output dimensions; width drives a locked custom size."""
options.validate()
display_width = width * float(sar)
+ if options.engine == "DLSS":
+ ow, oh = dlss_output_size(math.ceil(display_width), height, options.dlss_mode, even=True)
+ return ow, oh, ""
if not options.vsr_enabled:
w, h = display_width, float(height)
elif options.size_mode == "Scale factor":
diff --git a/src/upscale/video/processor.py b/src/upscale/video/processor.py
index 861eecf..ffd4ddc 100644
--- a/src/upscale/video/processor.py
+++ b/src/upscale/video/processor.py
@@ -36,8 +36,33 @@ def _process(source, options, progress, output_dir, controller, capabilities):
metadata = inspect_video(source, controller, reject_hdr=True)
output_width, output_height, _ = output_size(
metadata["width"], metadata["height"], options)
- capabilities = capabilities or probe_capabilities(
+ capabilities = capabilities or (probe_capabilities(
options.ai_gpu_uuid, controller=controller)
+ if options.engine != "DLSS" or options.hdr_enabled else None)
+ if options.engine == "DLSS":
+ from ...core.gpu_selection import detect_gpu
+ from .dlss_pipeline import convert_video_dlss
+ from .cuda_pipeline import DLSSNeedsHostFallback
+ ai_gpu = detect_gpu(options.ai_gpu_uuid)
+ requested_video_gpu = (
+ str(ai_gpu["uuid"]) if options.video_gpu_uuid == "auto"
+ else options.video_gpu_uuid)
+ video_gpu = ffmpeg.resolve_video_gpu(
+ detect_gpus(), requested_video_gpu, options.codec,
+ output_width, output_height)
+ if is_nvenc(options.codec) and video_gpu is None:
+ raise RuntimeError("The selected NVIDIA encoder cannot encode this DLSS output size.")
+ if is_nvenc(options.codec):
+ try:
+ return convert_video_cuda_nvenc(
+ source, options, controller=controller, progress=progress,
+ output_dir=output_dir, metadata=metadata,
+ capabilities=capabilities, video_gpu=video_gpu)
+ except DLSSNeedsHostFallback:
+ app_log.info("upscale-dlss", "NVDEC unavailable; using the host frame boundary")
+ return convert_video_dlss(
+ source, options, controller=controller, progress=progress,
+ output_dir=output_dir, metadata=metadata, video_gpu=video_gpu)
requested_video_gpu = (
str(capabilities.gpu["uuid"])
if options.video_gpu_uuid == "auto"