Only add sharpness score metadata when scores are actually connected
Return None for scores_list when scores_info input is not connected, and skip writing score metadata in that case for both images and videos. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -152,7 +152,8 @@ class FastAbsoluteSaver:
|
||||
|
||||
def parse_info(self, info_str, batch_size):
|
||||
if not info_str:
|
||||
return ([0]*batch_size, [0.0]*batch_size)
|
||||
# No scores connected - return None for scores to indicate "not provided"
|
||||
return ([0]*batch_size, None)
|
||||
matches = re.findall(r"F:(\d+).*?Score:\s*(\d+(\.\d+)?)", info_str)
|
||||
frames = []
|
||||
scores = []
|
||||
@@ -200,8 +201,9 @@ class FastAbsoluteSaver:
|
||||
meta_png = PngInfo()
|
||||
exif_bytes = None
|
||||
|
||||
# 1. Custom Score Metadata
|
||||
# 1. Custom Score Metadata (only if score was actually provided)
|
||||
if fmt == "png":
|
||||
if score is not None:
|
||||
meta_png.add_text(key_name, str(score))
|
||||
meta_png.add_text("software", "ComfyUI_Parallel_Node")
|
||||
|
||||
@@ -224,6 +226,7 @@ class FastAbsoluteSaver:
|
||||
"workflow": extra_data.get("workflow", {}) if extra_data else {}
|
||||
}
|
||||
# We also add the custom score here for WebP readers that check Exif
|
||||
if score is not None:
|
||||
exif_payload[key_name] = score
|
||||
|
||||
user_comment = json.dumps(exif_payload)
|
||||
@@ -362,6 +365,20 @@ class FastAbsoluteSaver:
|
||||
except OSError:
|
||||
raise ValueError(f"Could not create directory: {output_path}")
|
||||
|
||||
if images is None or len(images) == 0:
|
||||
raise ValueError("No images provided to FastAbsoluteSaver.")
|
||||
|
||||
# --- VIDEO PATH (check early, before image-specific logic) ---
|
||||
if save_format in ("mp4", "webm"):
|
||||
batch_size = len(images)
|
||||
_, scores_list = self.parse_info(scores_info, batch_size)
|
||||
self.save_video(images, output_path, filename_prefix, use_timestamp,
|
||||
video_fps, video_crf, video_pixel_format, save_format,
|
||||
scores_list=scores_list, metadata_key=metadata_key,
|
||||
save_workflow=save_workflow_metadata, prompt_data=prompt,
|
||||
extra_data=extra_pnginfo)
|
||||
return {"ui": {"images": []}}
|
||||
|
||||
if max_threads == 0:
|
||||
max_threads = os.cpu_count() or 4
|
||||
|
||||
@@ -375,15 +392,6 @@ class FastAbsoluteSaver:
|
||||
if auto_increment and not use_timestamp and not using_real_frames:
|
||||
start_counter = self.get_start_index(output_path, filename_prefix)
|
||||
|
||||
# --- VIDEO PATH ---
|
||||
if save_format in ("mp4", "webm"):
|
||||
self.save_video(images, output_path, filename_prefix, use_timestamp,
|
||||
video_fps, video_crf, video_pixel_format, save_format,
|
||||
scores_list=scores_list, metadata_key=metadata_key,
|
||||
save_workflow=save_workflow_metadata, prompt_data=prompt,
|
||||
extra_data=extra_pnginfo)
|
||||
return {"ui": {"images": []}}
|
||||
|
||||
ts_str = f"_{int(time.time())}" if use_timestamp else ""
|
||||
|
||||
print(f"xx- FastSaver: Saving {batch_size} images to {output_path}...")
|
||||
@@ -393,7 +401,7 @@ class FastAbsoluteSaver:
|
||||
|
||||
for i, img_tensor in enumerate(images):
|
||||
real_frame_num = frame_indices[i]
|
||||
current_score = scores_list[i]
|
||||
current_score = scores_list[i] if scores_list else None
|
||||
|
||||
if real_frame_num > 0:
|
||||
number_part = real_frame_num
|
||||
@@ -405,7 +413,7 @@ class FastAbsoluteSaver:
|
||||
|
||||
base_name = f"{filename_prefix}{ts_str}_{number_str}"
|
||||
|
||||
if filename_with_score:
|
||||
if filename_with_score and current_score is not None:
|
||||
base_name += f"_{int(current_score)}"
|
||||
|
||||
ext = ".webp" if save_format == "webp" else ".png"
|
||||
|
||||
Reference in New Issue
Block a user