From 3555fa05a2955973b91beb7717d7380b35129505 Mon Sep 17 00:00:00 2001 From: jaehwang Date: Wed, 9 Sep 2026 09:51:50 +0900 Subject: [PATCH] update archive thumbnail --- backend/models/longcut.py | 1 + backend/pipelines/artifact.py | 7 +++++++ backend/pipelines/playreel.py | 11 +++++++++-- backend/routers/archive.py | 3 ++- backend/routers/view.py | 3 ++- backend/services/compose_long.py | 7 ++++++- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/backend/models/longcut.py b/backend/models/longcut.py index e035433..7a8bfba 100644 --- a/backend/models/longcut.py +++ b/backend/models/longcut.py @@ -28,6 +28,7 @@ class EndBandInfo(BaseModel): @dataclass class LongcutResult: video: bytes + thumbnail: bytes # 첫 프레임. 0초가 포스터 원본이라 그대로 정지컷이 된다 duration: float frames: int plan: LongcutPlan diff --git a/backend/pipelines/artifact.py b/backend/pipelines/artifact.py index aaa4afe..0725fdc 100644 --- a/backend/pipelines/artifact.py +++ b/backend/pipelines/artifact.py @@ -9,11 +9,18 @@ from utils import blob JPEG_QUALITY = 90 +# 이름이 고정된 산출물. 경로가 정해져 있어 컬럼에 다시 적지 않고 만들어 쓴다 +THUMBNAIL = "thumbnail.jpg" + def artifact_path(pipeline: str, task_id: str, name: str) -> str: return f"{pipeline}/{task_id}/{name}" +def artifact_url(pipeline: str, task_id: str, name: str) -> str: + return blob.public_url(artifact_path(pipeline, task_id, name)) + + async def store_bytes(pipeline: str, task_id: str, name: str, data: bytes, *, download_as: str | None = None) -> str: """download_as를 주면 브라우저가 그 주소를 열 때 그 이름으로 내려받는다""" diff --git a/backend/pipelines/playreel.py b/backend/pipelines/playreel.py index f48759f..4c6e54f 100644 --- a/backend/pipelines/playreel.py +++ b/backend/pipelines/playreel.py @@ -17,8 +17,8 @@ from models.motion import MotionPlan from models.nol import NolMeta from models.pipeline_state import PlayreelState, initial_timings from models.tts import NarrationTimeline, TypecastVoice -from pipelines.artifact import (contact_sheet, load_image, load_optional, store_bytes, - store_image) +from pipelines.artifact import (THUMBNAIL, artifact_url, contact_sheet, load_image, + load_optional, store_bytes, store_image) from services.analyze_poster import analyze_poster from services.bgm import DEFAULT_BGM_STYLE, generate_bgm from services.build_layer_config import build_layer_config @@ -60,6 +60,11 @@ def working_poster_url(task: PlayreelTask) -> str: return task.upscaled_poster_url or task.poster_url +def thumbnail_url(task: PlayreelTask) -> str | None: + """compose가 끝났으면 정지컷이 정해진 경로에 있다""" + return artifact_url(PIPELINE, task.id, THUMBNAIL) if task.video_url else None + + async def create_task(session: AsyncSession, url: str, goods_id: str, slug: str) -> PlayreelTask: task = PlayreelTask(source_url=url, goods_id=goods_id, slug=slug, @@ -245,6 +250,8 @@ async def run_compose(session: AsyncSession, task: PlayreelTask) -> None: filename = f"{task.slug}_30_v{task.version + 1}.mp4" task.video_url = await store_bytes(PIPELINE, task.id, filename, result.video, download_as=filename) + # 경로가 고정이라 URL은 남기지 않는다. 읽는 쪽이 thumbnail_url()로 만든다 + await store_bytes(PIPELINE, task.id, THUMBNAIL, result.thumbnail) task.scene_plan = result.plan.model_dump() task.video_duration = result.duration task.video_frames = result.frames diff --git a/backend/routers/archive.py b/backend/routers/archive.py index 594218a..4769362 100644 --- a/backend/routers/archive.py +++ b/backend/routers/archive.py @@ -9,6 +9,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from models.nol import NolMeta from pipelines.gate import period_text +from pipelines.playreel import thumbnail_url from pipelines.runner import DONE from routers.view import UNNAMED from tables.task import PlayreelTask, PosterAliveTask @@ -52,7 +53,7 @@ def playreel_entry(task: PlayreelTask) -> dict: "narration": [line["text"] for line in task.narration_lines or []] or None, "poster_url": task.upscaled_poster_url or task.poster_url, "video_url": task.video_url, - "thumbnail_url": None, + "thumbnail_url": thumbnail_url(task), "version": task.version, "credits_used": task.credits_used, "f2_variants": [], diff --git a/backend/routers/view.py b/backend/routers/view.py index 7698464..e6cd499 100644 --- a/backend/routers/view.py +++ b/backend/routers/view.py @@ -4,6 +4,7 @@ from models.motion import MotionPlan from models.pipeline_state import PlayreelState, PosterAliveState, stage_keys from pipelines.gate import build_review +from pipelines.playreel import thumbnail_url from tables.task import PlayreelTask, PosterAliveTask @@ -81,6 +82,6 @@ def playreel_view(task: PlayreelTask) -> dict: "metadata": None, "artifacts": {key: url for key, url in ( ("video", task.video_url), - ("thumbnail", task.analysis_grid_url), + ("thumbnail", thumbnail_url(task)), ) if url}, } diff --git a/backend/services/compose_long.py b/backend/services/compose_long.py index 09b05b0..62a590a 100644 --- a/backend/services/compose_long.py +++ b/backend/services/compose_long.py @@ -36,6 +36,7 @@ SCROLL_SCREENS_PER_SECOND = 0.35 PROOF_COUNT = 8 # 완성본 전체에서 고르게 뽑는 시점 수 PROOF_SIZE = (180, 320) PROOF_GAP = 10 +THUMBNAIL_QUALITY = 90 BAND_HEIGHT = 300 BAND_RISE_SECONDS = 0.6 @@ -278,15 +279,19 @@ def compose_longcut(poster: bytes | Path | Image.Image, clip: bytes, # 훅 구간만 보면 뒤쪽 스크롤과 엔드밴드를 검수할 수 없어 전체에서 고르게 뽑는다 proof_at = {round(step * total_frames / PROOF_COUNT) for step in range(PROOF_COUNT)} tiles: list[Image.Image] = [] + thumbnail = io.BytesIO() def frames() -> Iterator[Image.Image]: for index, frame in enumerate( compose_frames(timeline, plan, source, clip, images, info, qr)): + if index == 0: + frame.save(thumbnail, "JPEG", quality=THUMBNAIL_QUALITY) if preview and index in proof_at: tiles.append(frame.resize(PROOF_SIZE)) yield frame video = encode_mp4(frames(), (W, H), mix_audio(narration_mp3, bgm_mp3, timeline.total), fps=FPS) - return LongcutResult(video=video, duration=timeline.total, frames=total_frames, + return LongcutResult(video=video, thumbnail=thumbnail.getvalue(), + duration=timeline.total, frames=total_frames, plan=plan, proof=proof_sheet(tiles) if tiles else None)