썸네일 생성 기능 추가

This commit is contained in:
skkim committed 2026-07-16 13:37:13 +09:00
1 parent 7ec9e9749d
commit 153484f2bd
11 files changed
+1688 -1132

No files matched your search

+56 -4
View File
@@ -32,6 +32,9 @@ from app.utils.address_parser import SIDO_CITIES, SIDO_SEARCH_ALIASES
from app.lyric.models import Lyric
from app.song.models import Song, SongTimestamp
from app.utils.creatomate import CreatomateService
# 썸네일 인트로 오버레이 잠정 비활성화 — 재활성화 시 주석 해제 (generate_video 내 블록 참조)
# from app.utils.thumbnail import build_thumbnail_intro_element
# from app.video.services.video import get_image_tags_by_task_id
from app.comment.models import Comment
from app.database.like_cache import (
@@ -57,6 +60,7 @@ from app.video.schemas.video_schema import (
VideoRenderData,
VideoThumbnailItem,
)
from app.video.worker.thumbnail_task import generate_thumbnail_background
from app.video.worker.video_task import download_and_upload_video_to_blob
@@ -125,6 +129,7 @@ curl -X GET "http://localhost:8000/video/generate/0694b716-dbff-7219-8000-d08cb5
)
async def generate_video(
task_id: str,
background_tasks: BackgroundTasks,
orientation: Literal["horizontal", "vertical"] = Query(
default="vertical",
description="영상 방향 (horizontal: 가로형, vertical: 세로형)",
@@ -221,10 +226,24 @@ async def generate_video(
category_definition = marketing_intelligence.intel_result["market_positioning"]["category_definition"]
target_keywords = marketing_intelligence.intel_result["target_keywords"]
brand_concept = ""
for sp in marketing_intelligence.intel_result["selling_points"]:
if "concept" in sp["english_category"].lower():
brand_concept = sp["description"]
# 썸네일 헤드라인(thumb-headline-hook_claim-aspirational)용 문구 추출.
# 1순위: 마케팅 분석 시 LLM이 5~15자로 축약 생성한 hook_headline (신규 데이터)
# 폴백: hook_headline이 없는 구 데이터는 concept 셀링포인트 → core_value →
# 최고점 셀링포인트 순으로 추출 (make_thumbnail_modification에서 15자 절단 안전망 적용)
brand_concept = marketing_intelligence.intel_result.get("hook_headline", "") or ""
selling_points = marketing_intelligence.intel_result["selling_points"]
if not brand_concept:
for sp in selling_points:
if "concept" in sp["english_category"].lower():
brand_concept = sp["description"]
break
if not brand_concept:
brand_concept = marketing_intelligence.intel_result["market_positioning"].get("core_value", "")
if brand_concept:
logger.info(f"[generate_video] brand_concept 폴백(core_value) 사용 - task_id: {task_id}")
if not brand_concept and selling_points:
brand_concept = max(selling_points, key=lambda sp: sp.get("score", 0))["description"]
logger.info(f"[generate_video] brand_concept 폴백(최고점 셀링포인트) 사용 - task_id: {task_id}")
# Lyric 조회
lyric_result = await session.execute(
@@ -336,6 +355,19 @@ async def generate_video(
)
# 세션이 여기서 자동으로 닫힘 (async with 블록 종료)
# 썸네일 백그라운드 생성 (세로형만, 응답 비차단) — 실패해도 영상 생성에 영향 없음
background_tasks.add_task(
generate_thumbnail_background,
video_id=video_id,
task_id=task_id,
orientation=orientation,
brand_name=brand_name,
region=region,
brand_concept=brand_concept,
category_definition=category_definition,
target_keywords=target_keywords,
)
except HTTPException:
raise
except Exception as e:
@@ -360,6 +392,7 @@ async def generate_video(
creatomate_service = CreatomateService(
orientation=orientation,
industry=industry,
project_id=project_id,
)
logger.debug(
f"[generate_video] Using template_id: {creatomate_service.template_id}, (song duration: {song_duration})"
@@ -445,6 +478,24 @@ async def generate_video(
)
final_template["source"]["elements"].append(caption)
# END - LYRIC AUTO 결정부
# 썸네일 인트로 오버레이 (세로형만) — SNS 첫 프레임용 0.1초 정지 화면.
# duration 스케일링·자막 append 이후에 붙여야 노출 시간이 유지되며,
# 실패해도 영상 생성 자체에는 영향을 주지 않는다.
# NOTE: 잠정 비활성화 — 재활성화 시 아래 블록과 상단 import 주석 해제
# if orientation == "vertical":
# try:
# taged_image_list = await get_image_tags_by_task_id(task_id)
# thumb_image_url = creatomate_service.select_thumbnail_image(taged_image_list)
# if thumb_image_url:
# final_template["source"]["elements"].append(
# build_thumbnail_intro_element(thumb_image_url, thumbnail_modifications)
# )
# logger.info(f"[generate_video] Thumbnail intro overlay added - task_id: {task_id}")
# else:
# logger.warning(f"[generate_video] 썸네일 인트로 배경 이미지 없음 — skip - task_id: {task_id}")
# except Exception as e:
# logger.warning(f"[generate_video] 썸네일 인트로 추가 실패(무시) - task_id: {task_id}, error: {e}")
# logger.debug(
# f"[generate_video] final_template: {json.dumps(final_template, indent=2, ensure_ascii=False)}"
# )
@@ -977,6 +1028,7 @@ async def get_all_videos(
video_id=v.id,
store_name=p.store_name,
result_movie_url=v.result_movie_url,
thumbnail_url=v.video_thumbnail_url,
created_at=v.created_at,
like_count=like_count_map.get(v.id) or 0,
is_liked_by_me=liked_map.get(v.id, False),