Fix color inversion in video export

- Handle [-1, 1] range from diffusion models
- Properly normalize to [0, 1] before converting to uint8
- Add clipping to ensure valid color ranges
parent 40787d0a
......@@ -10184,11 +10184,13 @@ def main(args):
# Ensure frames are in 0-255 uint8 range for video export
if isinstance(frames, np.ndarray):
if frames.dtype == np.float32 or frames.dtype == np.float64:
# Assume 0-1 range, convert to 0-255
if frames.max() <= 1.0:
frames = (frames * 255).astype(np.uint8)
else:
frames = frames.astype(np.uint8)
# Check if values are in [-1, 1] range (common for diffusion models)
if frames.min() < 0:
# Convert from [-1, 1] to [0, 1]
frames = (frames + 1.0) / 2.0
# Now convert from [0, 1] to [0, 255]
frames = np.clip(frames, 0.0, 1.0) * 255
frames = frames.astype(np.uint8)
elif frames.dtype != np.uint8:
frames = frames.astype(np.uint8)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment