Deforum_Soonr / dev /video_utils2.py
AlekseyCalvin's picture
Rename video_utils2.py to dev/video_utils2.py
f95c3b7 verified
import cv2
import os
import zipfile
from PIL import Image
def frames_to_video(frames, output_path, fps=10):
"""Compiles a list of PIL images into an MP4 video."""
if not frames: return None
width, height = frames[0].size
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
for frame in frames:
out.write(cv2.cvtColor(np.array(frame), cv2.COLOR_RGB2BGR))
out.release()
return output_path
def export_to_zip(frames, zip_name="frames.zip"):
"""Saves all frames to a temporary ZIP for batch download."""
with zipfile.ZipFile(zip_name, 'w') as zipf:
for i, frame in enumerate(frames):
frame_path = f"frame_{i:04d}.png"
frame.save(frame_path)
zipf.write(frame_path)
os.remove(frame_path)
return zip_name