영상생성 로직 및 검색 방식 추가

This commit is contained in:
skkim committed 2026-07-07 13:16:46 +09:00
1 parent b8be2a355a
commit 76485ebbcc
3 files changed
+171 -33

No files matched your search

+39 -14
View File
@@ -964,6 +964,43 @@ class CreatomateService:
return ranges
@staticmethod
def _scale_element(elem: dict, extend_rate: float) -> None:
"""element 하나의 time/duration/animations를 extend_rate만큼 스케일링합니다.
composition의 자식 element까지 재귀적으로 처리합니다. 재귀하지 않으면
부모 컴포지션(씬 슬롯)만 늘어나고 내부 leaf 이미지/애니메이션은 원래
길이에서 끝나버려, 슬롯이 끝나기 전 컴포지션의 fill_color(회색)가
노출되는 버그가 생긴다 — modify_element/parse_template_component_name과
동일하게 composition을 재귀 순회해야 함.
오디오 판별은 track 번호가 아닌 type == "audio"로 한다. composition
내부의 track 번호는 그 컴포지션 안에서만 유효한 로컬 레이어 인덱스라
전역 AUDIO_TRACK/KEYWORD_TRACK 상수와 우연히 값이 겹칠 수 있다
(실제 템플릿에도 다중 레이어 씬의 2번째/3번째 이미지가 track=2, track=4인
경우가 존재함).
"""
if elem.get("type") == "audio":
return
# "time"은 숫자 오프셋 대신 "end"(컴포지션 끝에 고정) 같은 특수 키워드일 수 있음 —
# 이런 값은 렌더 시점에 (이미 스케일링된) duration 기준으로 재계산되므로 그대로 둔다.
if "time" in elem and isinstance(elem["time"], (int, float)):
elem["time"] = elem["time"] * extend_rate
if "duration" in elem and isinstance(elem["duration"], (int, float)):
elem["duration"] = elem["duration"] * extend_rate
for animation in elem.get("animations", []):
anim_time = animation.get("time", 0)
if isinstance(anim_time, (int, float)) and anim_time != 0:
animation["time"] = anim_time * extend_rate
if isinstance(animation.get("duration"), (int, float)):
animation["duration"] = animation["duration"] * extend_rate
if elem.get("type") == "composition":
for child in elem.get("elements", []):
CreatomateService._scale_element(child, extend_rate)
def extend_template_duration(self, template: dict, target_duration: float) -> dict:
"""템플릿의 duration을 target_duration으로 확장합니다."""
# template["duration"] = target_duration + 0.5 # 늘린것보단 짧게
@@ -974,22 +1011,10 @@ class CreatomateService:
for elem in new_template["source"]["elements"]:
try:
# if elem["type"] == "audio":
# continue
if elem["track"] == AUDIO_TRACK : # audio track은 패스
if elem["track"] == AUDIO_TRACK : # audio track(최상위 음악 트랙)은 패스
continue
if "time" in elem:
elem["time"] = elem["time"] * extend_rate
if "duration" in elem:
elem["duration"] = elem["duration"] * extend_rate
if "animations" not in elem:
continue
for animation in elem["animations"]:
if animation.get("time", 0) != 0:
animation["time"] = animation["time"] * extend_rate
animation["duration"] = animation["duration"] * extend_rate
self._scale_element(elem, extend_rate)
except Exception as e:
logger.error(
f"[extend_template_duration] Error processing element: {elem}, {e}"