From 5a8f1af2e82d99fe545dbabbb494647af0b19bbb Mon Sep 17 00:00:00 2001 From: sakura1bgx Date: Mon, 4 Nov 2024 13:39:41 +0900 Subject: [PATCH] Add files via upload - Fix videosrc function. --- flipstreamviewer.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/flipstreamviewer.py b/flipstreamviewer.py index c329571..ec75c79 100644 --- a/flipstreamviewer.py +++ b/flipstreamviewer.py @@ -24,7 +24,7 @@ checkpoints_list = folder_paths.get_filename_list("checkpoints") allowed_ips = ["127.0.0.1"] param = {"prompt": "", "negativePrompt": "", "seed": 0, "keepSeed": 0, "steps": 13, "cfg": 4, "interval": 30, "sampler": "dpmpp_2m,sgm_uniform", "checkpoint": "", "lora": "", "startstep": 0, "frames": 1, "framewait": 1, "videosrc": "", "videofst": 0, "videomax": 0, "videoskp": 8, "videostr": 1, "offsetX": 0, "offsetY": 0, "scale": 100} -state = {"mode": "", "height": 512, "autoUpdate": False, "presetTitle": time.strftime("%Y%m%d-%H%M"), "presetFolder": "", "presetFile": "", "loraRate": "1", "loraRank": "0", "checkpointFolder": "", "loraFolder": "", "loraFile": "", "loraTagOptions": "[]", "loraTag": "", "loraLinkHref": "", "loraPreviewSrc": "", "wd14th": 0.35, "wd14cth": 0.85} +state = {"mode": "", "width": 512, "height": 512, "autoUpdate": False, "presetTitle": time.strftime("%Y%m%d-%H%M"), "presetFolder": "", "presetFile": "", "loraRate": "1", "loraRank": "0", "checkpointFolder": "", "loraFolder": "", "loraFile": "", "loraTagOptions": "[]", "loraTag": "", "loraLinkHref": "", "loraPreviewSrc": "", "wd14th": 0.35, "wd14cth": 0.85} frame_updating = False frame_buffer = [] exclude_tags = "" @@ -990,7 +990,7 @@ async def viewer(request):
- + {param["videofst"]}fst
@@ -1161,7 +1161,7 @@ async def set_frame(request): return web.Response(status=200) -def load_video(path, height, videofst, videoskp, maxcount): +def load_video(path, maxwidth, height, videofst, videoskp, maxcount): cap = cv2.VideoCapture(path) if not cap.isOpened(): return [], 0 @@ -1180,6 +1180,9 @@ def load_video(path, height, videofst, videoskp, maxcount): scale = height / frame.shape[0] width = int(frame.shape[1] * scale // 8 * 8) frame = cv2.resize(frame, (width, height), interpolation=cv2.INTER_LANCZOS4) + if width > maxwidth: + x = int(frame.shape[1] / 2 - maxwidth / 2) + frame = frame[:, x:x + maxwidth] buf.append(frame) return buf, total_frames @@ -1191,7 +1194,7 @@ async def preview_video(request): raise HTTPForbidden() videosrc, videofst, videoskp, frames = await request.json() - buf, total_frames = load_video(str(Path("videosrc", videosrc)), state["height"], videofst, videoskp, frames) + buf, total_frames = load_video(str(Path("videosrc", videosrc)), state["width"], state["height"], videofst, videoskp, frames) buf = [BytesIO(cv2.imencode(".webp", frame)[1]).getvalue() for frame in buf] buf += buf[::-1] frame_buffer = buf @@ -1332,6 +1335,7 @@ class FlipStreamSource: @classmethod def IS_CHANGED(cls, vae, width, height): + state["width"] = width state["height"] = height return hash((width, height, param["frames"], param["videosrc"], param["videofst"], param["videoskp"], param["videostr"])) @@ -1342,7 +1346,7 @@ class FlipStreamSource: latent = None bypass = False if videopath: - buf, _ = load_video(videopath, height, param["videofst"], param["videoskp"], frames) + buf, _ = load_video(videopath, width, height, param["videofst"], param["videoskp"], frames) if buf: buf = [np.array(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), dtype=np.float32) / 255 for frame in buf] image = torch.zeros([frames, height, width, 3])