forked from william-murray1204/stable-diffusion-cpp-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
45 lines (36 loc) · 1.1 KB
/
conftest.py
File metadata and controls
45 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
from typing import List
import numpy as np
import ffmpeg
from PIL import Image
OUTPUT_DIR = "tests/outputs"
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
SD_CPP_CLI = "C:\\Users\\Willi\\Documents\\GitHub\\stable-diffusion.cpp\\build\\bin\\sd-cli"
# ===========================================
# Video Saving
# ===========================================
def save_video_ffmpeg(frames: List[Image.Image], fps: int, out_path: str) -> None:
if not frames:
raise ValueError("No frames provided")
width, height = frames[0].size
# Concatenate frames into raw RGB bytes
raw_bytes = b"".join(np.array(frame.convert("RGB"), dtype=np.uint8).tobytes() for frame in frames)
(
ffmpeg.input(
"pipe:",
format="rawvideo",
pix_fmt="rgb24",
s=f"{width}x{height}",
r=fps,
)
.output(
out_path,
vcodec="libx264",
pix_fmt="yuv420p",
r=fps,
movflags="+faststart",
)
.overwrite_output()
.run(input=raw_bytes)
)