Gravo / utils.py
aexyb's picture
Create utils.py
2abb2c3 verified
Raw
History Blame Contribute Delete
788 Bytes
import os
import time
from pathlib import Path
OUTPUT_DIR = Path("outputs")
OUTPUT_DIR.mkdir(exist_ok=True)
def cleanup_outputs(max_age_hours=2):
"""
Delete old generated videos.
"""
now = time.time()
for file in OUTPUT_DIR.glob("*.mp4"):
age = now - file.stat().st_mtime
if age > max_age_hours * 3600:
try:
file.unlink()
except Exception:
pass
def random_seed():
import random
return random.randint(0, 2**31 - 1)
def validate_frames(frames):
# Wan requires 4k+1
if frames < 5:
frames = 5
remainder = (frames - 1) % 4
if remainder != 0:
frames += 4 - remainder
return frames
def ensure_output_dir():
OUTPUT_DIR.mkdir(exist_ok=True)