feat(generator): 카메라 모션을 media.py 로 통합하고 스토리보드가 컷별로 선택하도록 확장

This commit is contained in:
skkim committed 2026-08-11 15:01:23 +09:00
1 parent 434d0ca9c0
commit e1dca36d21
31 files changed
+485 -295

No files matched your search

+4 -25
View File
@@ -575,30 +575,6 @@ _wrap_lines = MU._wrap_lines
mix_bgm = MU.mix_bgm
def _scene_motion(idx: int, n: int, frames: int) -> str:
"""장면별 zoompan 카메라 모션(z/x/y 표현식만 반환 — d/s/fps 는 호출부에서 붙임).
- 1번 컷(훅): 펀치인 — 1.30 에서 확 들어와 시선 고정 후 서서히 줌
- 뒤에서 3번째 컷(피벗 추정 — 억지 광고 전환): 셰이크. 장면 역할 태그가
스토리보드에 없어 위치 휴리스틱(hook→story→pivot→cta 순서상 cta 직전)
- 나머지: 줌인 / 줌아웃 / 좌→우 팬 / 우→좌 팬 순환
"""
center = "x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'"
f = max(frames, 1)
if idx == 1: # 훅: 리빌(살짝 당김→전체)
return f"zoompan=z='max(1.10-0.10*on/{f},1.0)':{center}"
if n >= 6 and idx == n - 2: # 피벗: 아주 약한 흔들림(줌 1.06 유지)
return ("zoompan=z='1.06':"
"x='iw/2-(iw/zoom/2)+8*sin(on*1.6)':"
"y='ih/2-(ih/zoom/2)+6*cos(on*2.2)'")
kind = idx % 4
if kind == 0: # 줌아웃(끝에 전체)
return f"zoompan=z='max(1.10-0.10*on/{f},1.0)':{center}"
if kind == 1: # 줌인(시작에 전체)
return f"zoompan=z='min(1.0+0.10*on/{f},1.10)':{center}"
if kind == 2: # 약한 좌→우 팬(줌 1.06, ~6%만 이동)
return f"zoompan=z='1.06':x='(iw-iw/zoom)*on/{f}':y='ih/2-(ih/zoom/2)'"
return f"zoompan=z='1.06':x='(iw-iw/zoom)*(1-on/{f})':y='ih/2-(ih/zoom/2)'"
def build_video(scenes, audio_paths, img_paths, out_path, link=None, link_seconds=3.0,
store=None, cta=None, speed=1.0, trim_silence=True, tail=0.15,
@@ -619,6 +595,9 @@ def build_video(scenes, audio_paths, img_paths, out_path, link=None, link_second
tmp.mkdir(exist_ok=True)
segs = []
total = 0.0
# 카메라 순환 시작점 — 콘텐츠마다 다르되 같은 콘텐츠면 항상 같다.
# (media.motion_seed 주석 참조)
cam_seed = MU.motion_seed("".join(str(s.get("narration", "")) for s in scenes))
for idx, (sc, ap, ip) in enumerate(zip(scenes, audio_paths, img_paths), 1):
# 컷편집용으로 음성 가공(빠르게 + 침묵 제거) 후 그 길이를 컷 길이로 사용
@@ -635,7 +614,7 @@ def build_video(scenes, audio_paths, img_paths, out_path, link=None, link_second
band_h = int(H * BAND_RATIO)
img_h = H - band_h
bw, bh = int(W * 3), int(img_h * 3) # zoompan 정수픽셀 반올림 떨림 방지용 업스케일(2배는 떨림 재발, 3배로 메모리·화질 절충)
motion = _scene_motion(idx, len(scenes), frames)
motion = MU.scene_motion(sc, idx, len(scenes), frames, cam_seed)
fd = min(0.18, dur / 4) # 컷 전환 화이트 페이드(짧은 컷은 비례 축소)
# 페이드는 '그림'에만 → 캡션(자막)은 그 위에 나중에 얹어 항상 선명하게 유지.
# 첫 컷(hook)은 흰 화면 없이 바로 이미지로 시작 → 페이드인은 2번째 컷부터.