update archive thumbnail
This commit is contained in:
1 parent
ca9e40f43d
commit
3555fa05a2
6 files changed
+27
-5
No files matched your search
@@ -28,6 +28,7 @@ class EndBandInfo(BaseModel):
|
|||||||
@dataclass
|
@dataclass
|
||||||
class LongcutResult:
|
class LongcutResult:
|
||||||
video: bytes
|
video: bytes
|
||||||
|
thumbnail: bytes # 첫 프레임. 0초가 포스터 원본이라 그대로 정지컷이 된다
|
||||||
duration: float
|
duration: float
|
||||||
frames: int
|
frames: int
|
||||||
plan: LongcutPlan
|
plan: LongcutPlan
|
||||||
|
|||||||
@@ -9,11 +9,18 @@ from utils import blob
|
|||||||
|
|
||||||
JPEG_QUALITY = 90
|
JPEG_QUALITY = 90
|
||||||
|
|
||||||
|
# 이름이 고정된 산출물. 경로가 정해져 있어 컬럼에 다시 적지 않고 만들어 쓴다
|
||||||
|
THUMBNAIL = "thumbnail.jpg"
|
||||||
|
|
||||||
|
|
||||||
def artifact_path(pipeline: str, task_id: str, name: str) -> str:
|
def artifact_path(pipeline: str, task_id: str, name: str) -> str:
|
||||||
return f"{pipeline}/{task_id}/{name}"
|
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, *,
|
async def store_bytes(pipeline: str, task_id: str, name: str, data: bytes, *,
|
||||||
download_as: str | None = None) -> str:
|
download_as: str | None = None) -> str:
|
||||||
"""download_as를 주면 브라우저가 그 주소를 열 때 그 이름으로 내려받는다"""
|
"""download_as를 주면 브라우저가 그 주소를 열 때 그 이름으로 내려받는다"""
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ from models.motion import MotionPlan
|
|||||||
from models.nol import NolMeta
|
from models.nol import NolMeta
|
||||||
from models.pipeline_state import PlayreelState, initial_timings
|
from models.pipeline_state import PlayreelState, initial_timings
|
||||||
from models.tts import NarrationTimeline, TypecastVoice
|
from models.tts import NarrationTimeline, TypecastVoice
|
||||||
from pipelines.artifact import (contact_sheet, load_image, load_optional, store_bytes,
|
from pipelines.artifact import (THUMBNAIL, artifact_url, contact_sheet, load_image,
|
||||||
store_image)
|
load_optional, store_bytes, store_image)
|
||||||
from services.analyze_poster import analyze_poster
|
from services.analyze_poster import analyze_poster
|
||||||
from services.bgm import DEFAULT_BGM_STYLE, generate_bgm
|
from services.bgm import DEFAULT_BGM_STYLE, generate_bgm
|
||||||
from services.build_layer_config import build_layer_config
|
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
|
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,
|
async def create_task(session: AsyncSession, url: str, goods_id: str,
|
||||||
slug: str) -> PlayreelTask:
|
slug: str) -> PlayreelTask:
|
||||||
task = PlayreelTask(source_url=url, goods_id=goods_id, slug=slug,
|
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"
|
filename = f"{task.slug}_30_v{task.version + 1}.mp4"
|
||||||
task.video_url = await store_bytes(PIPELINE, task.id, filename, result.video,
|
task.video_url = await store_bytes(PIPELINE, task.id, filename, result.video,
|
||||||
download_as=filename)
|
download_as=filename)
|
||||||
|
# 경로가 고정이라 URL은 남기지 않는다. 읽는 쪽이 thumbnail_url()로 만든다
|
||||||
|
await store_bytes(PIPELINE, task.id, THUMBNAIL, result.thumbnail)
|
||||||
task.scene_plan = result.plan.model_dump()
|
task.scene_plan = result.plan.model_dump()
|
||||||
task.video_duration = result.duration
|
task.video_duration = result.duration
|
||||||
task.video_frames = result.frames
|
task.video_frames = result.frames
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||||||
|
|
||||||
from models.nol import NolMeta
|
from models.nol import NolMeta
|
||||||
from pipelines.gate import period_text
|
from pipelines.gate import period_text
|
||||||
|
from pipelines.playreel import thumbnail_url
|
||||||
from pipelines.runner import DONE
|
from pipelines.runner import DONE
|
||||||
from routers.view import UNNAMED
|
from routers.view import UNNAMED
|
||||||
from tables.task import PlayreelTask, PosterAliveTask
|
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,
|
"narration": [line["text"] for line in task.narration_lines or []] or None,
|
||||||
"poster_url": task.upscaled_poster_url or task.poster_url,
|
"poster_url": task.upscaled_poster_url or task.poster_url,
|
||||||
"video_url": task.video_url,
|
"video_url": task.video_url,
|
||||||
"thumbnail_url": None,
|
"thumbnail_url": thumbnail_url(task),
|
||||||
"version": task.version,
|
"version": task.version,
|
||||||
"credits_used": task.credits_used,
|
"credits_used": task.credits_used,
|
||||||
"f2_variants": [],
|
"f2_variants": [],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
from models.motion import MotionPlan
|
from models.motion import MotionPlan
|
||||||
from models.pipeline_state import PlayreelState, PosterAliveState, stage_keys
|
from models.pipeline_state import PlayreelState, PosterAliveState, stage_keys
|
||||||
from pipelines.gate import build_review
|
from pipelines.gate import build_review
|
||||||
|
from pipelines.playreel import thumbnail_url
|
||||||
from tables.task import PlayreelTask, PosterAliveTask
|
from tables.task import PlayreelTask, PosterAliveTask
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +82,6 @@ def playreel_view(task: PlayreelTask) -> dict:
|
|||||||
"metadata": None,
|
"metadata": None,
|
||||||
"artifacts": {key: url for key, url in (
|
"artifacts": {key: url for key, url in (
|
||||||
("video", task.video_url),
|
("video", task.video_url),
|
||||||
("thumbnail", task.analysis_grid_url),
|
("thumbnail", thumbnail_url(task)),
|
||||||
) if url},
|
) if url},
|
||||||
}
|
}
|
||||||
@@ -36,6 +36,7 @@ SCROLL_SCREENS_PER_SECOND = 0.35
|
|||||||
PROOF_COUNT = 8 # 완성본 전체에서 고르게 뽑는 시점 수
|
PROOF_COUNT = 8 # 완성본 전체에서 고르게 뽑는 시점 수
|
||||||
PROOF_SIZE = (180, 320)
|
PROOF_SIZE = (180, 320)
|
||||||
PROOF_GAP = 10
|
PROOF_GAP = 10
|
||||||
|
THUMBNAIL_QUALITY = 90
|
||||||
|
|
||||||
BAND_HEIGHT = 300
|
BAND_HEIGHT = 300
|
||||||
BAND_RISE_SECONDS = 0.6
|
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)}
|
proof_at = {round(step * total_frames / PROOF_COUNT) for step in range(PROOF_COUNT)}
|
||||||
tiles: list[Image.Image] = []
|
tiles: list[Image.Image] = []
|
||||||
|
thumbnail = io.BytesIO()
|
||||||
|
|
||||||
def frames() -> Iterator[Image.Image]:
|
def frames() -> Iterator[Image.Image]:
|
||||||
for index, frame in enumerate(
|
for index, frame in enumerate(
|
||||||
compose_frames(timeline, plan, source, clip, images, info, qr)):
|
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:
|
if preview and index in proof_at:
|
||||||
tiles.append(frame.resize(PROOF_SIZE))
|
tiles.append(frame.resize(PROOF_SIZE))
|
||||||
yield frame
|
yield frame
|
||||||
|
|
||||||
video = encode_mp4(frames(), (W, H), mix_audio(narration_mp3, bgm_mp3, timeline.total),
|
video = encode_mp4(frames(), (W, H), mix_audio(narration_mp3, bgm_mp3, timeline.total),
|
||||||
fps=FPS)
|
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)
|
plan=plan, proof=proof_sheet(tiles) if tiles else None)
|
||||||
Reference in new issue
Block a user