diff --git a/app/utils/creatomate.py b/app/utils/creatomate.py index cb76c61..abbfd51 100644 --- a/app/utils/creatomate.py +++ b/app/utils/creatomate.py @@ -147,6 +147,49 @@ text_template_h_1 = { ] } +autotext_template_v_1 = { + "type": "text", + "track": 4, + "time": 0, + "y": "87.9086%", + "width": "100%", + "height": "40%", + "x_alignment": "50%", + "y_alignment": "50%", + "font_family": "Noto Sans", + "font_weight": "700", + "font_size": "8 vmin", + "background_color": "rgba(216,216,216,0)", + "background_x_padding": "33%", + "background_y_padding": "7%", + "background_border_radius": "28%", + "transcript_source": "audio-music", # audio-music과 연동됨 + "transcript_effect": "karaoke", + "fill_color": "#ffffff", + "stroke_color": "rgba(51,51,51,1)", + "stroke_width": "0.6 vmin" +} +autotext_template_h_1 = { + "type": "text", + "track": 4, + "time": 0, + "x": "10%", + "y": "83.2953%", + "width": "80%", + "height": "15%", + "x_anchor": "0%", + "y_anchor": "0%", + "x_alignment": "50%", + "font_family": "Noto Sans", + "font_weight": "700", + "font_size": "5.9998 vmin", + "transcript_source": "audio-music", + "transcript_effect": "karaoke", + "fill_color": "#ffffff", + "stroke_color": "#333333", + "stroke_width": "0.2 vmin" +} + async def get_shared_client() -> httpx.AsyncClient: """공유 HTTP 클라이언트를 반환합니다. 없으면 생성합니다.""" global _shared_client @@ -693,7 +736,10 @@ class CreatomateService: text_scene["elements"][0]["name"] = f"lyric-{lyric_index}" text_scene["elements"][0]["text"] = lyric_text return text_scene - + + def auto_lyric(self, auto_text_template : dict): + text_scene = copy.deepcopy(auto_text_template) + return text_scene def get_text_template(self): match self.orientation: @@ -701,4 +747,11 @@ class CreatomateService: return text_template_v_2 case "horizontal": return text_template_h_1 - + + def get_auto_text_template(self): + match self.orientation: + case "vertical": + return autotext_template_v_1 + case "horizontal": + return autotext_template_h_1 + diff --git a/app/video/api/routers/v1/video.py b/app/video/api/routers/v1/video.py index 9f268b7..24ecfad 100644 --- a/app/video/api/routers/v1/video.py +++ b/app/video/api/routers/v1/video.py @@ -41,6 +41,8 @@ from app.video.schemas.video_schema import ( ) from app.video.worker.video_task import download_and_upload_video_to_blob +from config import creatomate_settings + logger = get_logger("video") router = APIRouter(prefix="/video", tags=["Video"]) @@ -348,17 +350,22 @@ async def generate_video( f"[generate_video] timestamp[{i}]: lyric_line={ts.lyric_line}, start_time={ts.start_time}, end_time={ts.end_time}" ) - 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, - ) - final_template["source"]["elements"].append(caption) - + # 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()) + 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, + ) + 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)}" # ) diff --git a/config.py b/config.py index a3be1b1..3ba74bd 100644 --- a/config.py +++ b/config.py @@ -155,6 +155,10 @@ class CreatomateSettings(BaseSettings): default=30.0, description="가로형 템플릿 기본 duration (초)", ) + DEBUG_AUTO_LYRIC: bool = Field( + default = False, + description = "Creatomate 자동 가사 생성 기능 사용 여부" + ) model_config = _base_config