가사 대신 키워드 subtitle PoC 및 템플릿 추가
This commit is contained in:
1 parent
ce79cb5d04
commit
7da6ab6ec0
9 files changed
+304
-82
No files matched your search
@@ -23,10 +23,11 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.database.session import get_session
|
||||
from app.user.dependencies.auth import get_current_user
|
||||
from app.user.models import User
|
||||
from app.home.models import Image, Project
|
||||
from app.home.models import Image, Project, MarketingIntel
|
||||
from app.lyric.models import Lyric
|
||||
from app.song.models import Song, SongTimestamp
|
||||
from app.utils.creatomate import CreatomateService
|
||||
from app.utils.subtitles import SubtitleContentsGenerator
|
||||
from app.utils.logger import get_logger
|
||||
from app.video.models import Video
|
||||
from app.video.schemas.video_schema import (
|
||||
@@ -197,7 +198,15 @@ async def generate_video(
|
||||
detail=f"task_id '{task_id}'에 해당하는 Project를 찾을 수 없습니다.",
|
||||
)
|
||||
project_id = project.id
|
||||
marketing_intelligence = project.marketing_intelligence
|
||||
store_address = project.detail_region_info
|
||||
customer_name = project.store_name
|
||||
marketing_intelligence = project.marketing_intelligence
|
||||
|
||||
marketing_result = await session.execute(
|
||||
select(MarketingIntel).where(MarketingIntel.id == project.marketing_intelligence)
|
||||
)
|
||||
marketing_intelligence = marketing_result.scalar_one_or_none()
|
||||
|
||||
# ===== 결과 처리: Lyric =====
|
||||
lyric = lyric_result.scalar_one_or_none()
|
||||
@@ -287,16 +296,18 @@ async def generate_video(
|
||||
# 2단계: 외부 API 호출 (세션 사용 안함 - 커넥션 풀 점유 없음)
|
||||
# ==========================================================================
|
||||
stage2_start = time.perf_counter()
|
||||
|
||||
subtitle_generator = SubtitleContentsGenerator()
|
||||
|
||||
try:
|
||||
logger.info(
|
||||
f"[generate_video] Stage 2 START - Creatomate API - task_id: {task_id}"
|
||||
)
|
||||
creatomate_service = CreatomateService(
|
||||
orientation=orientation,
|
||||
target_duration=song_duration,
|
||||
orientation=orientation
|
||||
)
|
||||
logger.debug(
|
||||
f"[generate_video] Using template_id: {creatomate_service.template_id}, duration: {creatomate_service.target_duration} (song duration: {song_duration})"
|
||||
f"[generate_video] Using template_id: {creatomate_service.template_id}, (song duration: {song_duration})"
|
||||
)
|
||||
|
||||
# 6-1. 템플릿 조회 (비동기)
|
||||
@@ -309,29 +320,42 @@ async def generate_video(
|
||||
modifications = creatomate_service.elements_connect_resource_blackbox(
|
||||
elements=template["source"]["elements"],
|
||||
image_url_list=image_urls,
|
||||
lyric=lyrics,
|
||||
music_url=music_url,
|
||||
address=store_address
|
||||
)
|
||||
logger.debug(f"[generate_video] Modifications created - task_id: {task_id}")
|
||||
|
||||
pitchings = creatomate_service.extract_text_format_from_template(template)
|
||||
|
||||
generated_subtitles = await subtitle_generator.generate_subtitle_contents(
|
||||
marketing_intelligence = marketing_intelligence.intel_result,
|
||||
pitching_label_list = pitchings,
|
||||
customer_name = customer_name,
|
||||
detail_region_info = store_address,
|
||||
)
|
||||
pitching_output_list = generated_subtitles.pitching_results
|
||||
|
||||
subtitle_modifications = {pitching_output.pitching_tag : pitching_output.pitching_data for pitching_output in pitching_output_list}
|
||||
|
||||
modifications.update(subtitle_modifications)
|
||||
# 6-3. elements 수정
|
||||
new_elements = creatomate_service.modify_element(
|
||||
template["source"]["elements"],
|
||||
modifications,
|
||||
)
|
||||
template["source"]["elements"] = new_elements
|
||||
|
||||
logger.debug(f"[generate_video] Elements modified - task_id: {task_id}")
|
||||
|
||||
|
||||
# 6-4. duration 확장
|
||||
final_template = creatomate_service.extend_template_duration(
|
||||
template,
|
||||
creatomate_service.target_duration,
|
||||
)
|
||||
logger.debug(
|
||||
f"[generate_video] Duration extended to {creatomate_service.target_duration}s - task_id: {task_id}"
|
||||
song_duration,
|
||||
)
|
||||
|
||||
logger.debug(f"[generate_video] Duration extended - task_id: {task_id}")
|
||||
|
||||
song_timestamp_result = await session.execute(
|
||||
select(SongTimestamp).where(
|
||||
SongTimestamp.suno_audio_id == song.suno_audio_id
|
||||
@@ -339,13 +363,10 @@ async def generate_video(
|
||||
)
|
||||
song_timestamp_list = song_timestamp_result.scalars().all()
|
||||
|
||||
logger.debug(
|
||||
f"[generate_video] song_timestamp_list count: {len(song_timestamp_list)}"
|
||||
)
|
||||
logger.debug(f"[generate_video] song_timestamp_list count: {len(song_timestamp_list)}")
|
||||
|
||||
for i, ts in enumerate(song_timestamp_list):
|
||||
logger.debug(
|
||||
f"[generate_video] timestamp[{i}]: lyric_line={ts.lyric_line}, start_time={ts.start_time}, end_time={ts.end_time}"
|
||||
)
|
||||
logger.debug(f"[generate_video] timestamp[{i}]: lyric_line={ts.lyric_line}, start_time={ts.start_time}, end_time={ts.end_time}")
|
||||
|
||||
match lyric_language:
|
||||
case "English" :
|
||||
@@ -355,33 +376,32 @@ async def generate_video(
|
||||
lyric_font = "Noto Sans"
|
||||
|
||||
# LYRIC AUTO 결정부
|
||||
if (creatomate_settings.DEBUG_AUTO_LYRIC):
|
||||
auto_text_template = creatomate_service.get_auto_text_template()
|
||||
final_template["source"]["elements"].append(creatomate_service.auto_lyric(auto_text_template))
|
||||
else :
|
||||
text_template = creatomate_service.get_text_template()
|
||||
for idx, aligned in enumerate(song_timestamp_list):
|
||||
caption = creatomate_service.lining_lyric(
|
||||
text_template,
|
||||
idx,
|
||||
aligned.lyric_line,
|
||||
aligned.start_time,
|
||||
aligned.end_time,
|
||||
lyric_font
|
||||
)
|
||||
final_template["source"]["elements"].append(caption)
|
||||
if (creatomate_settings.LYRIC_SUBTITLE):
|
||||
if (creatomate_settings.DEBUG_AUTO_LYRIC):
|
||||
auto_text_template = creatomate_service.get_auto_text_template()
|
||||
final_template["source"]["elements"].append(creatomate_service.auto_lyric(auto_text_template))
|
||||
else :
|
||||
text_template = creatomate_service.get_text_template()
|
||||
for idx, aligned in enumerate(song_timestamp_list):
|
||||
caption = creatomate_service.lining_lyric(
|
||||
text_template,
|
||||
idx,
|
||||
aligned.lyric_line,
|
||||
aligned.start_time,
|
||||
aligned.end_time,
|
||||
lyric_font
|
||||
)
|
||||
final_template["source"]["elements"].append(caption)
|
||||
# END - LYRIC AUTO 결정부
|
||||
# logger.debug(
|
||||
# f"[generate_video] final_template: {json.dumps(final_template, indent=2, ensure_ascii=False)}"
|
||||
# )
|
||||
|
||||
# 6-5. 커스텀 렌더링 요청 (비동기)
|
||||
render_response = await creatomate_service.make_creatomate_custom_call_async(
|
||||
final_template["source"],
|
||||
)
|
||||
logger.debug(
|
||||
f"[generate_video] Creatomate API response - task_id: {task_id}, response: {render_response}"
|
||||
)
|
||||
|
||||
logger.debug(f"[generate_video] Creatomate API response - task_id: {task_id}, response: {render_response}")
|
||||
|
||||
# 렌더 ID 추출
|
||||
if isinstance(render_response, list) and len(render_response) > 0:
|
||||
@@ -402,6 +422,8 @@ async def generate_video(
|
||||
logger.error(
|
||||
f"[generate_video] Creatomate API EXCEPTION - task_id: {task_id}, error: {e}"
|
||||
)
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
# 외부 API 실패 시 Video 상태를 failed로 업데이트
|
||||
from app.database.session import AsyncSessionLocal
|
||||
|
||||
@@ -521,11 +543,7 @@ async def get_video_status(
|
||||
current_user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_session),
|
||||
) -> PollingVideoResponse:
|
||||
"""creatomate_render_id로 영상 생성 작업의 상태를 조회합니다.
|
||||
|
||||
succeeded 상태인 경우 백그라운드에서 MP4 파일을 다운로드하고
|
||||
Video 테이블의 status를 completed로, result_movie_url을 업데이트합니다.
|
||||
"""
|
||||
|
||||
logger.info(
|
||||
f"[get_video_status] START - creatomate_render_id: {creatomate_render_id}"
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user