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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Simple Video Editor - Canvas 기반 렌더링
|
| 3 |
+
블러 배경 내보내기 수정: 프레임 기반 동기식 렌더링
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import base64
|
| 8 |
+
import os
|
| 9 |
+
import json
|
| 10 |
+
import subprocess
|
| 11 |
+
import tempfile
|
| 12 |
+
import shutil
|
| 13 |
+
import time
|
| 14 |
+
|
| 15 |
+
UPLOAD_DIR = tempfile.mkdtemp()
|
| 16 |
+
uploaded_files = {}
|
| 17 |
+
|
| 18 |
+
def get_editor_html(media_data="[]"):
|
| 19 |
+
return f'''<!DOCTYPE html>
|
| 20 |
+
<html lang="ko">
|
| 21 |
+
<head>
|
| 22 |
+
<meta charset="UTF-8">
|
| 23 |
+
<style>
|
| 24 |
+
*{{margin:0;padding:0;box-sizing:border-box}}
|
| 25 |
+
body{{font-family:-apple-system,BlinkMacSystemFont,sans-serif;background:#f5f5f7;font-size:13px}}
|
| 26 |
+
.editor{{display:flex;flex-direction:column;height:100vh}}
|
| 27 |
+
.toolbar{{height:44px;background:#fff;border-bottom:1px solid #ddd;display:flex;align-items:center;justify-content:space-between;padding:0 12px}}
|
| 28 |
+
.toolbar-title{{font-size:15px;font-weight:600}}
|
| 29 |
+
.btn{{padding:5px 10px;border:none;border-radius:5px;cursor:pointer;font-size:11px;font-weight:500}}
|
| 30 |
+
.btn-secondary{{background:#f0f0f0;color:#333}}
|
| 31 |
+
.btn-secondary:hover{{background:#e0e0e0}}
|
| 32 |
+
.btn-success{{background:#10b981;color:#fff}}
|
| 33 |
+
.btn-danger{{background:#ef4444;color:#fff}}
|
| 34 |
+
.main{{display:flex;flex:1;overflow:hidden}}
|
| 35 |
+
.library{{width:160px;background:#fff;border-right:1px solid #ddd;display:flex;flex-direction:column}}
|
| 36 |
+
.lib-header{{padding:8px;border-bottom:1px solid #eee;font-size:10px;font-weight:600;color:#666}}
|
| 37 |
+
.lib-content{{flex:1;overflow-y:auto;padding:6px}}
|
| 38 |
+
.lib-hint{{text-align:center;padding:15px;color:#999;font-size:10px}}
|
| 39 |
+
.media-grid{{display:grid;grid-template-columns:repeat(2,1fr);gap:4px}}
|
| 40 |
+
.media-item{{aspect-ratio:16/9;background:#f0f0f0;border-radius:4px;overflow:hidden;cursor:grab;position:relative;border:1px solid #e0e0e0}}
|
| 41 |
+
.media-item:hover{{border-color:#6366f1}}
|
| 42 |
+
.media-item img{{width:100%;height:100%;object-fit:cover}}
|
| 43 |
+
.media-item-icon{{width:100%;height:100%;display:flex;align-items:center;justify-content:center;font-size:18px}}
|
| 44 |
+
.media-item-dur{{position:absolute;top:2px;right:2px;background:rgba(0,0,0,0.7);padding:1px 3px;border-radius:2px;font-size:8px;color:#fff}}
|
| 45 |
+
.preview-area{{flex:1;display:flex;flex-direction:column;background:#1a1a1a;margin:6px;border-radius:8px;overflow:hidden}}
|
| 46 |
+
.preview-box{{flex:1;display:flex;align-items:center;justify-content:center;background:#000;overflow:hidden}}
|
| 47 |
+
#previewCanvas{{background:#000;box-shadow:0 0 20px rgba(0,0,0,0.5);cursor:default}}
|
| 48 |
+
.controls{{height:45px;background:#222;display:flex;align-items:center;justify-content:center;gap:6px}}
|
| 49 |
+
.ctrl-btn{{width:28px;height:28px;border:none;border-radius:50%;background:rgba(255,255,255,0.1);color:#fff;cursor:pointer;font-size:12px}}
|
| 50 |
+
.ctrl-btn:hover{{background:rgba(255,255,255,0.2)}}
|
| 51 |
+
.ctrl-btn.play{{width:36px;height:36px;background:#6366f1}}
|
| 52 |
+
.time-display{{font-family:monospace;font-size:10px;color:#aaa;min-width:90px;text-align:center}}
|
| 53 |
+
.props{{width:140px;background:#fff;border-left:1px solid #ddd}}
|
| 54 |
+
.props-header{{padding:8px;border-bottom:1px solid #eee;font-size:10px;font-weight:600;color:#666}}
|
| 55 |
+
.props-content{{padding:8px}}
|
| 56 |
+
.no-sel{{color:#999;text-align:center;padding:15px;font-size:10px}}
|
| 57 |
+
.prop-group{{margin-bottom:10px}}
|
| 58 |
+
.prop-label{{font-size:9px;color:#666;margin-bottom:2px}}
|
| 59 |
+
.prop-input{{width:100%;padding:4px;border:1px solid #ddd;border-radius:3px;font-size:10px}}
|
| 60 |
+
.timeline{{height:180px;background:#fff;border-top:1px solid #ddd;display:flex;flex-direction:column}}
|
| 61 |
+
.tl-toolbar{{height:28px;background:#fafafa;border-bottom:1px solid #eee;display:flex;align-items:center;padding:0 6px;gap:4px}}
|
| 62 |
+
.tl-toolbar .btn{{padding:2px 6px;font-size:9px}}
|
| 63 |
+
.tl-zoom{{display:flex;align-items:center;gap:3px;margin-left:auto;font-size:9px;color:#666}}
|
| 64 |
+
.tl-zoom input{{width:50px}}
|
| 65 |
+
.tl-container{{flex:1;overflow-x:auto;position:relative}}
|
| 66 |
+
.tl-ruler{{height:18px;background:#fff;border-bottom:1px solid #eee}}
|
| 67 |
+
.tl-tracks{{position:relative}}
|
| 68 |
+
.tl-track{{height:45px;border-bottom:1px solid #eee;display:flex}}
|
| 69 |
+
.tl-track:nth-child(2){{background:#fffbeb}}
|
| 70 |
+
.tl-track:nth-child(3){{background:#fdf2f8}}
|
| 71 |
+
.track-label{{width:50px;padding:0 4px;font-size:8px;color:#666;background:#fafafa;display:flex;align-items:center;border-right:1px solid #eee}}
|
| 72 |
+
.track-content{{flex:1;position:relative;min-width:600px}}
|
| 73 |
+
.clip{{position:absolute;height:36px;top:4px;border-radius:4px;cursor:grab;display:flex;align-items:center;overflow:hidden}}
|
| 74 |
+
.clip:hover{{box-shadow:0 0 0 2px #6366f1}}
|
| 75 |
+
.clip.selected{{box-shadow:0 0 0 2px #6366f1}}
|
| 76 |
+
.clip.video{{background:linear-gradient(135deg,#818cf8,#6366f1)}}
|
| 77 |
+
.clip.image{{background:linear-gradient(135deg,#34d399,#10b981)}}
|
| 78 |
+
.clip.audio{{background:linear-gradient(135deg,#fbbf24,#f59e0b)}}
|
| 79 |
+
.clip.text{{background:linear-gradient(135deg,#f472b6,#ec4899)}}
|
| 80 |
+
.clip-thumb{{width:36px;height:100%;object-fit:cover}}
|
| 81 |
+
.clip-info{{padding:0 4px;flex:1;overflow:hidden}}
|
| 82 |
+
.clip-name{{font-size:8px;color:#fff;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}}
|
| 83 |
+
.clip-dur{{font-size:7px;color:rgba(255,255,255,0.7)}}
|
| 84 |
+
.clip-handle{{position:absolute;top:0;bottom:0;width:8px;background:rgba(255,255,255,0.5);cursor:ew-resize;opacity:0}}
|
| 85 |
+
.clip:hover .clip-handle{{opacity:1}}
|
| 86 |
+
.clip-handle-l{{left:0;border-radius:4px 0 0 4px}}
|
| 87 |
+
.clip-handle-r{{right:0;border-radius:0 4px 4px 0}}
|
| 88 |
+
.playhead{{position:absolute;top:0;bottom:0;width:2px;background:#ef4444;z-index:10;pointer-events:none}}
|
| 89 |
+
.playhead::before{{content:"";position:absolute;top:0;left:-4px;border-left:5px solid transparent;border-right:5px solid transparent;border-top:7px solid #ef4444}}
|
| 90 |
+
.drop-zone{{background:rgba(99,102,241,0.1)!important;outline:2px dashed #6366f1!important}}
|
| 91 |
+
.status{{height:20px;background:#f5f5f5;border-top:1px solid #ddd;display:flex;align-items:center;padding:0 8px;font-size:9px;color:#666}}
|
| 92 |
+
.ctx-menu{{position:fixed;background:#fff;border:1px solid #ddd;border-radius:5px;padding:3px 0;min-width:100px;z-index:1000;box-shadow:0 4px 12px rgba(0,0,0,0.15);display:none}}
|
| 93 |
+
.ctx-item{{padding:5px 10px;cursor:pointer;font-size:10px}}
|
| 94 |
+
.ctx-item:hover{{background:#f5f5f5}}
|
| 95 |
+
.ctx-item.danger{{color:#ef4444}}
|
| 96 |
+
.modal{{position:fixed;inset:0;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;z-index:1000}}
|
| 97 |
+
.modal-box{{background:#fff;border-radius:8px;padding:16px;min-width:240px;text-align:center}}
|
| 98 |
+
.modal-box h3{{margin-bottom:8px;font-size:13px}}
|
| 99 |
+
.progress{{height:5px;background:#eee;border-radius:3px;overflow:hidden;margin:10px 0}}
|
| 100 |
+
.progress-bar{{height:100%;background:#6366f1;transition:width 0.2s}}
|
| 101 |
+
.hidden-media{{position:absolute;left:-9999px;top:-9999px;width:1px;height:1px;opacity:0;pointer-events:none}}
|
| 102 |
+
</style>
|
| 103 |
+
</head>
|
| 104 |
+
<body>
|
| 105 |
+
<div class="editor">
|
| 106 |
+
<div class="toolbar">
|
| 107 |
+
<div class="toolbar-title">🎬 Video Editor</div>
|
| 108 |
+
<div style="display:flex;gap:8px;align-items:center">
|
| 109 |
+
<select id="ratioSelect" onchange="setRatio(this.value)" style="padding:4px 8px;border-radius:4px;border:1px solid #ddd;font-size:11px">
|
| 110 |
+
<option value="16:9">16:9 (가로)</option>
|
| 111 |
+
<option value="9:16">9:16 (세로)</option>
|
| 112 |
+
<option value="1:1">1:1 (정사각)</option>
|
| 113 |
+
<option value="4:3">4:3</option>
|
| 114 |
+
<option value="4:5">4:5 (인스타)</option>
|
| 115 |
+
</select>
|
| 116 |
+
<select id="fillMode" onchange="setFillMode(this.value)" style="padding:4px 8px;border-radius:4px;border:1px solid #ddd;font-size:11px">
|
| 117 |
+
<option value="fit">맞춤 (여백)</option>
|
| 118 |
+
<option value="fill">채우기 (확대)</option>
|
| 119 |
+
<option value="blur">블러 배경</option>
|
| 120 |
+
</select>
|
| 121 |
+
<button class="btn btn-secondary" onclick="undo()">↩ 실행취소</button>
|
| 122 |
+
<button class="btn btn-success" onclick="exportVideo()">📥 내보내기</button>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
<div class="main">
|
| 126 |
+
<div class="library">
|
| 127 |
+
<div class="lib-header">📁 미디어</div>
|
| 128 |
+
<div class="lib-content">
|
| 129 |
+
<div class="lib-hint" id="hint">파일을 업로드하세요</div>
|
| 130 |
+
<div class="media-grid" id="mediaGrid"></div>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
<div class="preview-area">
|
| 134 |
+
<div class="preview-box">
|
| 135 |
+
<canvas id="previewCanvas" width="640" height="360"></canvas>
|
| 136 |
+
</div>
|
| 137 |
+
<div class="controls">
|
| 138 |
+
<button class="ctrl-btn" onclick="seek(0)">⏮</button>
|
| 139 |
+
<button class="ctrl-btn" onclick="seek(S.time-5)">⏪</button>
|
| 140 |
+
<button class="ctrl-btn play" onclick="togglePlay()" id="playBtn">▶</button>
|
| 141 |
+
<button class="ctrl-btn" onclick="seek(S.time+5)">⏩</button>
|
| 142 |
+
<button class="ctrl-btn" onclick="seek(S.dur)">⏭</button>
|
| 143 |
+
<div class="time-display"><span id="curT">00:00.00</span> / <span id="totT">00:00.00</span></div>
|
| 144 |
+
<button class="ctrl-btn" onclick="toggleMute()" id="muteBtn">🔊</button>
|
| 145 |
+
</div>
|
| 146 |
+
</div>
|
| 147 |
+
<div class="props">
|
| 148 |
+
<div class="props-header">⚙️ 속성</div>
|
| 149 |
+
<div class="props-content" id="propsBox"><div class="no-sel">클립 선택</div></div>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
<div class="timeline">
|
| 153 |
+
<div class="tl-toolbar">
|
| 154 |
+
<button class="btn btn-secondary" onclick="addTextClip()">📝 텍스트</button>
|
| 155 |
+
<button class="btn btn-secondary" onclick="splitClip()">✂ 자르기</button>
|
| 156 |
+
<button class="btn btn-secondary" onclick="dupeClip()">📋 복제</button>
|
| 157 |
+
<button class="btn btn-danger" onclick="delClip()">🗑 삭제</button>
|
| 158 |
+
<div class="tl-zoom">🔍<input type="range" min="0.5" max="3" step="0.1" value="1" oninput="setZoom(this.value)"></div>
|
| 159 |
+
</div>
|
| 160 |
+
<div class="tl-container" id="tlBox" onclick="tlClick(event)">
|
| 161 |
+
<div class="tl-ruler" id="ruler"></div>
|
| 162 |
+
<div class="tl-tracks">
|
| 163 |
+
<div class="tl-track"><div class="track-label">🎬 영상</div><div class="track-content" id="t0"></div></div>
|
| 164 |
+
<div class="tl-track"><div class="track-label">🎵 오디오</div><div class="track-content" id="t1"></div></div>
|
| 165 |
+
<div class="tl-track"><div class="track-label">📝 텍스트</div><div class="track-content" id="t2"></div></div>
|
| 166 |
+
</div>
|
| 167 |
+
<div class="playhead" id="playhead" style="left:50px"></div>
|
| 168 |
+
</div>
|
| 169 |
+
</div>
|
| 170 |
+
<div class="status" id="status">준비됨</div>
|
| 171 |
+
</div>
|
| 172 |
+
<div class="ctx-menu" id="ctx">
|
| 173 |
+
<div class="ctx-item" onclick="splitClip()">✂ 자르기</div>
|
| 174 |
+
<div class="ctx-item" onclick="dupeClip()">📋 복제</div>
|
| 175 |
+
<div class="ctx-item danger" onclick="delClip()">🗑 삭제</div>
|
| 176 |
+
</div>
|
| 177 |
+
<div class="modal" id="exportModal" style="display:none">
|
| 178 |
+
<div class="modal-box">
|
| 179 |
+
<h3>🎬 영상 내보내기</h3>
|
| 180 |
+
<p id="exportMsg">��비중...</p>
|
| 181 |
+
<div class="progress"><div class="progress-bar" id="exportBar"></div></div>
|
| 182 |
+
<button class="btn btn-secondary" onclick="cancelExport()">취소</button>
|
| 183 |
+
</div>
|
| 184 |
+
</div>
|
| 185 |
+
<div class="modal" id="textModal" style="display:none">
|
| 186 |
+
<div class="modal-box" style="min-width:320px">
|
| 187 |
+
<h3>📝 텍스트 추가</h3>
|
| 188 |
+
<div style="margin:10px 0;text-align:left">
|
| 189 |
+
<div style="margin-bottom:8px">
|
| 190 |
+
<label style="font-size:11px;color:#666">텍스트 내용</label>
|
| 191 |
+
<input type="text" id="textInput" placeholder="텍스트 입력..." style="width:100%;padding:8px;border:1px solid #ddd;border-radius:4px;margin-top:4px">
|
| 192 |
+
</div>
|
| 193 |
+
<div style="display:flex;gap:8px;margin-bottom:8px">
|
| 194 |
+
<div style="flex:1">
|
| 195 |
+
<label style="font-size:11px;color:#666">글자 크기</label>
|
| 196 |
+
<select id="textSize" style="width:100%;padding:6px;border:1px solid #ddd;border-radius:4px;margin-top:4px">
|
| 197 |
+
<option value="24">작게 (24px)</option>
|
| 198 |
+
<option value="36">보통 (36px)</option>
|
| 199 |
+
<option value="48" selected>크게 (48px)</option>
|
| 200 |
+
<option value="64">매우 크게 (64px)</option>
|
| 201 |
+
<option value="96">최대 (96px)</option>
|
| 202 |
+
</select>
|
| 203 |
+
</div>
|
| 204 |
+
<div style="flex:1">
|
| 205 |
+
<label style="font-size:11px;color:#666">글자 색상</label>
|
| 206 |
+
<input type="color" id="textColor" value="#ffffff" style="width:100%;height:32px;border:1px solid #ddd;border-radius:4px;margin-top:4px;cursor:pointer">
|
| 207 |
+
</div>
|
| 208 |
+
</div>
|
| 209 |
+
<div style="display:flex;gap:8px;margin-bottom:8px">
|
| 210 |
+
<div style="flex:1">
|
| 211 |
+
<label style="font-size:11px;color:#666">배경 스타일</label>
|
| 212 |
+
<select id="textBgStyle" onchange="toggleBgColor()" style="width:100%;padding:6px;border:1px solid #ddd;border-radius:4px;margin-top:4px">
|
| 213 |
+
<option value="none">배경 없음</option>
|
| 214 |
+
<option value="solid" selected>단색 배경</option>
|
| 215 |
+
<option value="rounded">둥근 배경</option>
|
| 216 |
+
</select>
|
| 217 |
+
</div>
|
| 218 |
+
<div style="flex:1" id="bgColorBox">
|
| 219 |
+
<label style="font-size:11px;color:#666">배경 색상</label>
|
| 220 |
+
<input type="color" id="textBgColor" value="#000000" style="width:100%;height:32px;border:1px solid #ddd;border-radius:4px;margin-top:4px;cursor:pointer">
|
| 221 |
+
</div>
|
| 222 |
+
</div>
|
| 223 |
+
<div style="margin-bottom:8px">
|
| 224 |
+
<label style="font-size:11px;color:#666">표시 시간 (초)</label>
|
| 225 |
+
<input type="number" id="textDuration" value="5" min="1" max="60" step="0.5" style="width:100%;padding:6px;border:1px solid #ddd;border-radius:4px;margin-top:4px">
|
| 226 |
+
</div>
|
| 227 |
+
</div>
|
| 228 |
+
<div style="display:flex;gap:8px;justify-content:center">
|
| 229 |
+
<button class="btn btn-secondary" onclick="closeTextModal()">취소</button>
|
| 230 |
+
<button class="btn btn-success" onclick="confirmAddText()">추가</button>
|
| 231 |
+
</div>
|
| 232 |
+
</div>
|
| 233 |
+
</div>
|
| 234 |
+
<div id="hiddenMedia" class="hidden-media"></div>
|
| 235 |
+
<script>
|
| 236 |
+
var S={{
|
| 237 |
+
media:[],
|
| 238 |
+
clips:[],
|
| 239 |
+
sel:null,
|
| 240 |
+
playing:false,
|
| 241 |
+
muted:false,
|
| 242 |
+
time:0,
|
| 243 |
+
dur:0,
|
| 244 |
+
zoom:1,
|
| 245 |
+
pps:80,
|
| 246 |
+
history:[],
|
| 247 |
+
animId:null,
|
| 248 |
+
cancelled:false,
|
| 249 |
+
els:{{}},
|
| 250 |
+
canvas:null,
|
| 251 |
+
ctx:null,
|
| 252 |
+
lastClipId:null,
|
| 253 |
+
ratio:'16:9',
|
| 254 |
+
fillMode:'fit',
|
| 255 |
+
ratioSizes:{{
|
| 256 |
+
'16:9':{{w:1280,h:720,pw:640,ph:360}},
|
| 257 |
+
'9:16':{{w:720,h:1280,pw:203,ph:360}},
|
| 258 |
+
'1:1':{{w:1080,h:1080,pw:360,ph:360}},
|
| 259 |
+
'4:3':{{w:1280,h:960,pw:480,ph:360}},
|
| 260 |
+
'4:5':{{w:1080,h:1350,pw:288,ph:360}}
|
| 261 |
+
}}
|
| 262 |
+
}};
|
| 263 |
+
|
| 264 |
+
function init(){{
|
| 265 |
+
S.canvas=document.getElementById('previewCanvas');
|
| 266 |
+
S.ctx=S.canvas.getContext('2d');
|
| 267 |
+
updateCanvasSize();
|
| 268 |
+
drawPlaceholder();
|
| 269 |
+
setupCanvasDrag();
|
| 270 |
+
}}
|
| 271 |
+
|
| 272 |
+
function setupCanvasDrag(){{
|
| 273 |
+
var canvas=S.canvas;
|
| 274 |
+
var dragging=null;
|
| 275 |
+
var dragOffsetX=0,dragOffsetY=0;
|
| 276 |
+
|
| 277 |
+
canvas.addEventListener('mousedown',function(e){{
|
| 278 |
+
var rect=canvas.getBoundingClientRect();
|
| 279 |
+
var scaleX=canvas.width/rect.width;
|
| 280 |
+
var scaleY=canvas.height/rect.height;
|
| 281 |
+
var mx=(e.clientX-rect.left)*scaleX;
|
| 282 |
+
var my=(e.clientY-rect.top)*scaleY;
|
| 283 |
+
|
| 284 |
+
var textClips=getTextClipsAt(S.time);
|
| 285 |
+
for(var i=textClips.length-1;i>=0;i--){{
|
| 286 |
+
var tc=textClips[i];
|
| 287 |
+
if(tc._bounds){{
|
| 288 |
+
var b=tc._bounds;
|
| 289 |
+
if(mx>=b.x&&mx<=b.x+b.w&&my>=b.y&&my<=b.y+b.h){{
|
| 290 |
+
dragging=tc;
|
| 291 |
+
selClip(tc.id);
|
| 292 |
+
var size=S.ratioSizes[S.ratio];
|
| 293 |
+
dragOffsetX=mx-size.pw*tc.posX;
|
| 294 |
+
dragOffsetY=my-size.ph*tc.posY;
|
| 295 |
+
canvas.style.cursor='move';
|
| 296 |
+
e.preventDefault();
|
| 297 |
+
return;
|
| 298 |
+
}}
|
| 299 |
+
}}
|
| 300 |
+
}}
|
| 301 |
+
}});
|
| 302 |
+
|
| 303 |
+
canvas.addEventListener('mousemove',function(e){{
|
| 304 |
+
var rect=canvas.getBoundingClientRect();
|
| 305 |
+
var scaleX=canvas.width/rect.width;
|
| 306 |
+
var scaleY=canvas.height/rect.height;
|
| 307 |
+
var mx=(e.clientX-rect.left)*scaleX;
|
| 308 |
+
var my=(e.clientY-rect.top)*scaleY;
|
| 309 |
+
|
| 310 |
+
if(dragging){{
|
| 311 |
+
var size=S.ratioSizes[S.ratio];
|
| 312 |
+
dragging.posX=Math.max(0.1,Math.min(0.9,(mx-dragOffsetX)/size.pw));
|
| 313 |
+
dragging.posY=Math.max(0.1,Math.min(0.9,(my-dragOffsetY)/size.ph));
|
| 314 |
+
drawFrame();
|
| 315 |
+
}}else{{
|
| 316 |
+
var textClips=getTextClipsAt(S.time);
|
| 317 |
+
var onText=false;
|
| 318 |
+
for(var i=0;i<textClips.length;i++){{
|
| 319 |
+
var tc=textClips[i];
|
| 320 |
+
if(tc._bounds){{
|
| 321 |
+
var b=tc._bounds;
|
| 322 |
+
if(mx>=b.x&&mx<=b.x+b.w&&my>=b.y&&my<=b.y+b.h){{
|
| 323 |
+
onText=true;
|
| 324 |
+
break;
|
| 325 |
+
}}
|
| 326 |
+
}}
|
| 327 |
+
}}
|
| 328 |
+
canvas.style.cursor=onText?'move':'default';
|
| 329 |
+
}}
|
| 330 |
+
}});
|
| 331 |
+
|
| 332 |
+
canvas.addEventListener('mouseup',function(){{
|
| 333 |
+
if(dragging){{
|
| 334 |
+
save();
|
| 335 |
+
dragging=null;
|
| 336 |
+
canvas.style.cursor='default';
|
| 337 |
+
renderProps();
|
| 338 |
+
}}
|
| 339 |
+
}});
|
| 340 |
+
|
| 341 |
+
canvas.addEventListener('mouseleave',function(){{
|
| 342 |
+
if(dragging){{
|
| 343 |
+
save();
|
| 344 |
+
dragging=null;
|
| 345 |
+
canvas.style.cursor='default';
|
| 346 |
+
}}
|
| 347 |
+
}});
|
| 348 |
+
}}
|
| 349 |
+
|
| 350 |
+
function updateCanvasSize(){{
|
| 351 |
+
var size=S.ratioSizes[S.ratio];
|
| 352 |
+
S.canvas.width=size.pw;
|
| 353 |
+
S.canvas.height=size.ph;
|
| 354 |
+
S.canvas.style.width=size.pw+'px';
|
| 355 |
+
S.canvas.style.height=size.ph+'px';
|
| 356 |
+
}}
|
| 357 |
+
|
| 358 |
+
function setRatio(r){{
|
| 359 |
+
S.ratio=r;
|
| 360 |
+
updateCanvasSize();
|
| 361 |
+
drawFrame();
|
| 362 |
+
stat('화면 비율: '+r);
|
| 363 |
+
}}
|
| 364 |
+
|
| 365 |
+
function setFillMode(m){{
|
| 366 |
+
S.fillMode=m;
|
| 367 |
+
drawFrame();
|
| 368 |
+
stat('채우기 모드: '+(m==='fit'?'맞춤 (여백)':m==='fill'?'채우기 (확대)':'블러 배경'));
|
| 369 |
+
}}
|
| 370 |
+
|
| 371 |
+
function id(){{return Math.random().toString(36).substr(2,9)}}
|
| 372 |
+
function fmt(t){{if(!t||isNaN(t))t=0;var m=Math.floor(t/60),s=Math.floor(t%60),ms=Math.floor((t%1)*100);return String(m).padStart(2,'0')+':'+String(s).padStart(2,'0')+'.'+String(ms).padStart(2,'0')}}
|
| 373 |
+
function r(n){{return Math.round(n*1000)/1000}}
|
| 374 |
+
function stat(m){{document.getElementById('status').textContent=m}}
|
| 375 |
+
function save(){{S.history.push(JSON.stringify(S.clips));if(S.history.length>30)S.history.shift()}}
|
| 376 |
+
|
| 377 |
+
function drawPlaceholder(){{
|
| 378 |
+
var size=S.ratioSizes[S.ratio];
|
| 379 |
+
var pw=size.pw,ph=size.ph;
|
| 380 |
+
S.ctx.fillStyle='#000';
|
| 381 |
+
S.ctx.fillRect(0,0,pw,ph);
|
| 382 |
+
S.ctx.fillStyle='#444';
|
| 383 |
+
S.ctx.font='14px sans-serif';
|
| 384 |
+
S.ctx.textAlign='center';
|
| 385 |
+
S.ctx.fillText('타임라인에 미디어를 추가하세요',pw/2,ph/2);
|
| 386 |
+
}}
|
| 387 |
+
|
| 388 |
+
function addMedia(name,type,url,filePath){{
|
| 389 |
+
var m={{id:id(),name:name,type:type,url:url,filePath:filePath||name,dur:type==='image'?5:0,thumb:type==='image'?url:null}};
|
| 390 |
+
S.media.push(m);
|
| 391 |
+
var container=document.getElementById('hiddenMedia');
|
| 392 |
+
if(type==='video'){{
|
| 393 |
+
var v=document.createElement('video');
|
| 394 |
+
v.src=url;
|
| 395 |
+
v.muted=true;
|
| 396 |
+
v.playsInline=true;
|
| 397 |
+
v.preload='auto';
|
| 398 |
+
v.crossOrigin='anonymous';
|
| 399 |
+
container.appendChild(v);
|
| 400 |
+
S.els[m.id]=v;
|
| 401 |
+
v.onloadedmetadata=function(){{
|
| 402 |
+
m.dur=r(v.duration);
|
| 403 |
+
renderLib();
|
| 404 |
+
v.currentTime=0.5;
|
| 405 |
+
}};
|
| 406 |
+
v.onseeked=function(){{
|
| 407 |
+
if(!m.thumb){{
|
| 408 |
+
try{{
|
| 409 |
+
var c=document.createElement('canvas');
|
| 410 |
+
c.width=160;c.height=90;
|
| 411 |
+
c.getContext('2d').drawImage(v,0,0,160,90);
|
| 412 |
+
m.thumb=c.toDataURL();
|
| 413 |
+
renderLib();
|
| 414 |
+
}}catch(e){{}}
|
| 415 |
+
}}
|
| 416 |
+
}};
|
| 417 |
+
}}else if(type==='audio'){{
|
| 418 |
+
var a=document.createElement('audio');
|
| 419 |
+
a.src=url;
|
| 420 |
+
a.preload='auto';
|
| 421 |
+
container.appendChild(a);
|
| 422 |
+
S.els[m.id]=a;
|
| 423 |
+
a.onloadedmetadata=function(){{m.dur=r(a.duration);renderLib()}};
|
| 424 |
+
}}else if(type==='image'){{
|
| 425 |
+
var img=new Image();
|
| 426 |
+
img.src=url;
|
| 427 |
+
img.crossOrigin='anonymous';
|
| 428 |
+
S.els[m.id]=img;
|
| 429 |
+
}}
|
| 430 |
+
renderLib();
|
| 431 |
+
stat('미디어 추가: '+name);
|
| 432 |
+
setTimeout(function(){{addClip(m)}},400);
|
| 433 |
+
}}
|
| 434 |
+
|
| 435 |
+
function renderLib(){{
|
| 436 |
+
var g=document.getElementById('mediaGrid');
|
| 437 |
+
var h=document.getElementById('hint');
|
| 438 |
+
h.style.display=S.media.length?'none':'block';
|
| 439 |
+
g.innerHTML='';
|
| 440 |
+
S.media.forEach(function(m){{
|
| 441 |
+
var d=document.createElement('div');
|
| 442 |
+
d.className='media-item';
|
| 443 |
+
d.draggable=true;
|
| 444 |
+
d.ondblclick=function(){{addClip(m)}};
|
| 445 |
+
d.ondragstart=function(e){{e.dataTransfer.setData('mid',m.id)}};
|
| 446 |
+
var th=m.thumb?'<img src="'+m.thumb+'">':'<div class="media-item-icon">'+(m.type==='video'?'🎬':m.type==='audio'?'🎵':'🖼')+'</div>';
|
| 447 |
+
d.innerHTML=th+(m.dur?'<div class="media-item-dur">'+fmt(m.dur)+'</div>':'');
|
| 448 |
+
g.appendChild(d);
|
| 449 |
+
}});
|
| 450 |
+
}}
|
| 451 |
+
|
| 452 |
+
function trackEnd(tr){{
|
| 453 |
+
var end=0;
|
| 454 |
+
for(var i=0;i<S.clips.length;i++){{
|
| 455 |
+
var c=S.clips[i];
|
| 456 |
+
if(c.track===tr){{
|
| 457 |
+
var e=r(c.start+(c.te-c.ts));
|
| 458 |
+
if(e>end)end=e;
|
| 459 |
+
}}
|
| 460 |
+
}}
|
| 461 |
+
return end;
|
| 462 |
+
}}
|
| 463 |
+
|
| 464 |
+
function addClip(m,at){{
|
| 465 |
+
save();
|
| 466 |
+
var tr=m.type==='audio'?1:0;
|
| 467 |
+
var st=at!==undefined?r(at):trackEnd(tr);
|
| 468 |
+
S.clips.push({{
|
| 469 |
+
id:id(),
|
| 470 |
+
mid:m.id,
|
| 471 |
+
name:m.name,
|
| 472 |
+
type:m.type,
|
| 473 |
+
track:tr,
|
| 474 |
+
start:st,
|
| 475 |
+
dur:m.dur,
|
| 476 |
+
ts:0,
|
| 477 |
+
te:m.dur,
|
| 478 |
+
vol:1,
|
| 479 |
+
filePath:m.filePath
|
| 480 |
+
}});
|
| 481 |
+
renderTL();
|
| 482 |
+
updateDur();
|
| 483 |
+
stat('클립 추가: '+m.name);
|
| 484 |
+
drawFrame();
|
| 485 |
+
}}
|
| 486 |
+
|
| 487 |
+
function renderTL(){{
|
| 488 |
+
['t0','t1','t2'].forEach(function(tid){{document.getElementById(tid).innerHTML=''}});
|
| 489 |
+
S.clips.forEach(function(c){{
|
| 490 |
+
var tr=document.getElementById('t'+c.track);
|
| 491 |
+
var el=document.createElement('div');
|
| 492 |
+
el.className='clip '+c.type+(S.sel===c.id?' selected':'');
|
| 493 |
+
var len=r(c.te-c.ts);
|
| 494 |
+
el.style.left=r(c.start*S.pps*S.zoom)+'px';
|
| 495 |
+
el.style.width=Math.max(25,r(len*S.pps*S.zoom))+'px';
|
| 496 |
+
el.draggable=true;
|
| 497 |
+
el.onclick=function(e){{e.stopPropagation();selClip(c.id)}};
|
| 498 |
+
el.oncontextmenu=function(e){{e.preventDefault();selClip(c.id);showCtx(e.clientX,e.clientY)}};
|
| 499 |
+
el.ondragstart=function(e){{e.dataTransfer.setData('cid',c.id);e.dataTransfer.setData('ox',e.offsetX)}};
|
| 500 |
+
var m=S.media.find(function(x){{return x.id===c.mid}});
|
| 501 |
+
var th=m&&m.thumb?'<img class="clip-thumb" src="'+m.thumb+'">':'';
|
| 502 |
+
var clipName=c.type==='text'?('📝 '+c.text.substring(0,8)):c.name;
|
| 503 |
+
el.innerHTML=th+'<div class="clip-info"><div class="clip-name">'+clipName+'</div><div class="clip-dur">'+fmt(len)+'</div></div><div class="clip-handle clip-handle-l"></div><div class="clip-handle clip-handle-r"></div>';
|
| 504 |
+
el.querySelector('.clip-handle-l').onmousedown=function(e){{e.stopPropagation();startTrim(c.id,'l',e)}};
|
| 505 |
+
el.querySelector('.clip-handle-r').onmousedown=function(e){{e.stopPropagation();startTrim(c.id,'r',e)}};
|
| 506 |
+
tr.appendChild(el);
|
| 507 |
+
}});
|
| 508 |
+
renderRuler();
|
| 509 |
+
setupDrop();
|
| 510 |
+
}}
|
| 511 |
+
|
| 512 |
+
function renderRuler(){{
|
| 513 |
+
var ru=document.getElementById('ruler');
|
| 514 |
+
var w=Math.max(r(S.dur*S.pps*S.zoom)+150,600);
|
| 515 |
+
ru.style.width=w+'px';
|
| 516 |
+
var h='<svg width="100%" height="18" style="position:absolute;left:50px">';
|
| 517 |
+
var step=S.zoom<0.7?5:S.zoom<1.5?2:1;
|
| 518 |
+
for(var i=0;i<=S.dur+10;i+=step){{
|
| 519 |
+
var x=r(i*S.pps*S.zoom);
|
| 520 |
+
h+='<line x1="'+x+'" y1="13" x2="'+x+'" y2="18" stroke="#ccc"/>';
|
| 521 |
+
h+='<text x="'+x+'" y="10" fill="#999" font-size="8" text-anchor="middle">'+fmt(i)+'</text>';
|
| 522 |
+
}}
|
| 523 |
+
ru.innerHTML=h+'</svg>';
|
| 524 |
+
}}
|
| 525 |
+
|
| 526 |
+
function setupDrop(){{
|
| 527 |
+
['t0','t1','t2'].forEach(function(tid,idx){{
|
| 528 |
+
var tr=document.getElementById(tid);
|
| 529 |
+
tr.ondragover=function(e){{e.preventDefault();tr.classList.add('drop-zone')}};
|
| 530 |
+
tr.ondragleave=function(){{tr.classList.remove('drop-zone')}};
|
| 531 |
+
tr.ondrop=function(e){{
|
| 532 |
+
e.preventDefault();
|
| 533 |
+
tr.classList.remove('drop-zone');
|
| 534 |
+
var rect=tr.getBoundingClientRect();
|
| 535 |
+
var t=r(Math.max(0,(e.clientX-rect.left)/(S.pps*S.zoom)));
|
| 536 |
+
var mid=e.dataTransfer.getData('mid');
|
| 537 |
+
var cid=e.dataTransfer.getData('cid');
|
| 538 |
+
var ox=parseFloat(e.dataTransfer.getData('ox')||0);
|
| 539 |
+
if(mid){{
|
| 540 |
+
var m=S.media.find(function(x){{return x.id===mid}});
|
| 541 |
+
if(m)addClip(m,t);
|
| 542 |
+
}}else if(cid){{
|
| 543 |
+
save();
|
| 544 |
+
var c=S.clips.find(function(x){{return x.id===cid}});
|
| 545 |
+
if(c){{
|
| 546 |
+
c.start=r(Math.max(0,t-ox/(S.pps*S.zoom)));
|
| 547 |
+
if(c.type==='text'){{
|
| 548 |
+
c.track=2;
|
| 549 |
+
}}else if(c.type==='audio'){{
|
| 550 |
+
c.track=1;
|
| 551 |
+
}}else{{
|
| 552 |
+
c.track=idx===2?0:idx;
|
| 553 |
+
}}
|
| 554 |
+
renderTL();
|
| 555 |
+
updateDur();
|
| 556 |
+
drawFrame();
|
| 557 |
+
}}
|
| 558 |
+
}}
|
| 559 |
+
}};
|
| 560 |
+
}});
|
| 561 |
+
}}
|
| 562 |
+
|
| 563 |
+
var trimData=null;
|
| 564 |
+
function startTrim(cid,side,e){{
|
| 565 |
+
e.preventDefault();
|
| 566 |
+
var c=S.clips.find(function(x){{return x.id===cid}});
|
| 567 |
+
if(!c)return;
|
| 568 |
+
save();
|
| 569 |
+
trimData={{cid:cid,side:side,sx:e.clientX,ots:c.ts,ote:c.te,ost:c.start}};
|
| 570 |
+
document.addEventListener('mousemove',doTrim);
|
| 571 |
+
document.addEventListener('mouseup',endTrim);
|
| 572 |
+
}}
|
| 573 |
+
function doTrim(e){{
|
| 574 |
+
if(!trimData)return;
|
| 575 |
+
var c=S.clips.find(function(x){{return x.id===trimData.cid}});
|
| 576 |
+
if(!c)return;
|
| 577 |
+
var dx=e.clientX-trimData.sx;
|
| 578 |
+
var dt=r(dx/(S.pps*S.zoom));
|
| 579 |
+
if(trimData.side==='l'){{
|
| 580 |
+
var newTs=Math.max(0,Math.min(c.te-0.1,trimData.ots+dt));
|
| 581 |
+
c.ts=r(newTs);
|
| 582 |
+
c.start=r(trimData.ost+(newTs-trimData.ots));
|
| 583 |
+
}}else{{
|
| 584 |
+
c.te=r(Math.max(c.ts+0.1,Math.min(c.dur,trimData.ote+dt)));
|
| 585 |
+
}}
|
| 586 |
+
renderTL();
|
| 587 |
+
updateDur();
|
| 588 |
+
}}
|
| 589 |
+
function endTrim(){{
|
| 590 |
+
trimData=null;
|
| 591 |
+
document.removeEventListener('mousemove',doTrim);
|
| 592 |
+
document.removeEventListener('mouseup',endTrim);
|
| 593 |
+
}}
|
| 594 |
+
|
| 595 |
+
function selClip(cid){{S.sel=cid;renderTL();renderProps()}}
|
| 596 |
+
|
| 597 |
+
function renderProps(){{
|
| 598 |
+
var box=document.getElementById('propsBox');
|
| 599 |
+
var c=S.clips.find(function(x){{return x.id===S.sel}});
|
| 600 |
+
if(!c){{box.innerHTML='<div class="no-sel">클립 선택</div>';return}}
|
| 601 |
+
var len=r(c.te-c.ts);
|
| 602 |
+
|
| 603 |
+
if(c.type==='text'){{
|
| 604 |
+
box.innerHTML='<div class="prop-group"><div class="prop-label">텍스트</div><input class="prop-input" value="'+c.text+'" onchange="setProp(\\'text\\',this.value)"></div>'+
|
| 605 |
+
'<div class="prop-group"><div class="prop-label">시작</div><input class="prop-input" type="number" step="0.1" value="'+c.start+'" onchange="setProp(\\'start\\',parseFloat(this.value))"></div>'+
|
| 606 |
+
'<div class="prop-group"><div class="prop-label">길이: '+fmt(len)+'</div></div>'+
|
| 607 |
+
'<div class="prop-group"><div class="prop-label">위치 X ('+Math.round((c.posX||0.5)*100)+'%)</div><input class="prop-input" type="range" min="0.05" max="0.95" step="0.01" value="'+(c.posX||0.5)+'" oninput="setProp(\\'posX\\',parseFloat(this.value))"></div>'+
|
| 608 |
+
'<div class="prop-group"><div class="prop-label">위치 Y ('+Math.round((c.posY||0.85)*100)+'%)</div><input class="prop-input" type="range" min="0.05" max="0.95" step="0.01" value="'+(c.posY||0.85)+'" oninput="setProp(\\'posY\\',parseFloat(this.value))"></div>'+
|
| 609 |
+
'<div class="prop-group"><div class="prop-label">글자 크기</div><select class="prop-input" onchange="setProp(\\'fontSize\\',parseInt(this.value))">'+
|
| 610 |
+
'<option value="24"'+(c.fontSize===24?' selected':'')+'>작게</option>'+
|
| 611 |
+
'<option value="36"'+(c.fontSize===36?' selected':'')+'>보통</option>'+
|
| 612 |
+
'<option value="48"'+(c.fontSize===48?' selected':'')+'>크게</option>'+
|
| 613 |
+
'<option value="64"'+(c.fontSize===64?' selected':'')+'>매우 크게</option>'+
|
| 614 |
+
'<option value="96"'+(c.fontSize===96?' selected':'')+'>최대</option>'+
|
| 615 |
+
'</select></div>'+
|
| 616 |
+
'<div class="prop-group"><div class="prop-label">글자 색상</div><input class="prop-input" type="color" value="'+c.fontColor+'" onchange="setProp(\\'fontColor\\',this.value)"></div>'+
|
| 617 |
+
'<div class="prop-group"><div class="prop-label">배경 스타일</div><select class="prop-input" onchange="setProp(\\'bgStyle\\',this.value)">'+
|
| 618 |
+
'<option value="none"'+(c.bgStyle==='none'?' selected':'')+'>없음</option>'+
|
| 619 |
+
'<option value="solid"'+(c.bgStyle==='solid'?' selected':'')+'>단색</option>'+
|
| 620 |
+
'<option value="rounded"'+(c.bgStyle==='rounded'?' selected':'')+'>둥근</option>'+
|
| 621 |
+
'</select></div>'+
|
| 622 |
+
'<div class="prop-group"><div class="prop-label">배경 색상</div><input class="prop-input" type="color" value="'+c.bgColor+'" onchange="setProp(\\'bgColor\\',this.value)"></div>';
|
| 623 |
+
}}else{{
|
| 624 |
+
box.innerHTML='<div class="prop-group"><div class="prop-label">이름</div><input class="prop-input" value="'+c.name+'" onchange="setProp(\\'name\\',this.value)"></div>'+
|
| 625 |
+
'<div class="prop-group"><div class="prop-label">시작</div><input class="prop-input" type="number" step="0.1" value="'+c.start+'" onchange="setProp(\\'start\\',parseFloat(this.value))"></div>'+
|
| 626 |
+
'<div class="prop-group"><div class="prop-label">길이: '+fmt(len)+'</div></div>'+
|
| 627 |
+
(c.type!=='image'?'<div class="prop-group"><div class="prop-label">볼륨 '+Math.round(c.vol*100)+'%</div><input class="prop-input" type="range" min="0" max="1" step="0.05" value="'+c.vol+'" oninput="setProp(\\'vol\\',parseFloat(this.value))"></div>':'');
|
| 628 |
+
}}
|
| 629 |
+
}}
|
| 630 |
+
|
| 631 |
+
function setProp(p,v){{
|
| 632 |
+
save();
|
| 633 |
+
var c=S.clips.find(function(x){{return x.id===S.sel}});
|
| 634 |
+
if(c){{c[p]=p==='start'?r(v):v;renderTL();updateDur();renderProps();drawFrame()}}
|
| 635 |
+
}}
|
| 636 |
+
|
| 637 |
+
function splitClip(){{
|
| 638 |
+
if(!S.sel){{alert('클립을 선택하세요');return}}
|
| 639 |
+
var c=S.clips.find(function(x){{return x.id===S.sel}});
|
| 640 |
+
if(!c)return;
|
| 641 |
+
var cEnd=r(c.start+c.te-c.ts);
|
| 642 |
+
if(S.time<=c.start||S.time>=cEnd){{alert('플레이헤드가 클립 안에 있어야 합니다');return}}
|
| 643 |
+
save();
|
| 644 |
+
var splitAt=r(S.time-c.start);
|
| 645 |
+
var c2=JSON.parse(JSON.stringify(c));
|
| 646 |
+
c2.id=id();
|
| 647 |
+
c2.start=r(S.time);
|
| 648 |
+
c2.ts=r(c.ts+splitAt);
|
| 649 |
+
c.te=r(c.ts+splitAt);
|
| 650 |
+
S.clips.push(c2);
|
| 651 |
+
renderTL();updateDur();hideCtx();stat('클립 분할됨');
|
| 652 |
+
}}
|
| 653 |
+
|
| 654 |
+
function dupeClip(){{
|
| 655 |
+
if(!S.sel)return;
|
| 656 |
+
var c=S.clips.find(function(x){{return x.id===S.sel}});
|
| 657 |
+
if(!c)return;
|
| 658 |
+
save();
|
| 659 |
+
var len=r(c.te-c.ts);
|
| 660 |
+
var nc=JSON.parse(JSON.stringify(c));
|
| 661 |
+
nc.id=id();
|
| 662 |
+
nc.start=r(c.start+len);
|
| 663 |
+
S.clips.push(nc);
|
| 664 |
+
renderTL();updateDur();hideCtx();stat('클립 복제됨');
|
| 665 |
+
}}
|
| 666 |
+
|
| 667 |
+
function delClip(){{
|
| 668 |
+
if(!S.sel)return;
|
| 669 |
+
save();
|
| 670 |
+
S.clips=S.clips.filter(function(x){{return x.id!==S.sel}});
|
| 671 |
+
S.sel=null;
|
| 672 |
+
renderTL();renderProps();updateDur();hideCtx();stat('클립 삭제됨');
|
| 673 |
+
drawFrame();
|
| 674 |
+
}}
|
| 675 |
+
|
| 676 |
+
function undo(){{if(S.history.length){{S.clips=JSON.parse(S.history.pop());renderTL();updateDur();stat('실행취소');drawFrame()}}}}
|
| 677 |
+
|
| 678 |
+
function updateDur(){{
|
| 679 |
+
var mx=0;
|
| 680 |
+
for(var i=0;i<S.clips.length;i++){{
|
| 681 |
+
var c=S.clips[i];
|
| 682 |
+
var e=r(c.start+c.te-c.ts);
|
| 683 |
+
if(e>mx)mx=e;
|
| 684 |
+
}}
|
| 685 |
+
S.dur=mx;
|
| 686 |
+
document.getElementById('totT').textContent=fmt(mx);
|
| 687 |
+
}}
|
| 688 |
+
|
| 689 |
+
function togglePlay(){{
|
| 690 |
+
S.playing=!S.playing;
|
| 691 |
+
document.getElementById('playBtn').textContent=S.playing?'⏸':'▶';
|
| 692 |
+
if(S.playing)play();else stop();
|
| 693 |
+
}}
|
| 694 |
+
|
| 695 |
+
function play(){{
|
| 696 |
+
var last=performance.now();
|
| 697 |
+
function loop(now){{
|
| 698 |
+
if(!S.playing)return;
|
| 699 |
+
var dt=(now-last)/1000;
|
| 700 |
+
last=now;
|
| 701 |
+
S.time=S.time+dt;
|
| 702 |
+
if(S.time>=S.dur){{
|
| 703 |
+
S.time=0;
|
| 704 |
+
if(S.dur===0){{S.playing=false;document.getElementById('playBtn').textContent='▶';return}}
|
| 705 |
+
}}
|
| 706 |
+
updateHead();
|
| 707 |
+
drawFrame();
|
| 708 |
+
S.animId=requestAnimationFrame(loop);
|
| 709 |
+
}}
|
| 710 |
+
S.animId=requestAnimationFrame(loop);
|
| 711 |
+
}}
|
| 712 |
+
|
| 713 |
+
function stop(){{
|
| 714 |
+
if(S.animId){{cancelAnimationFrame(S.animId);S.animId=null}}
|
| 715 |
+
Object.keys(S.els).forEach(function(k){{
|
| 716 |
+
var el=S.els[k];
|
| 717 |
+
if(el&&el.pause)el.pause();
|
| 718 |
+
}});
|
| 719 |
+
}}
|
| 720 |
+
|
| 721 |
+
function seek(t){{
|
| 722 |
+
S.time=Math.max(0,Math.min(S.dur||0,t));
|
| 723 |
+
updateHead();
|
| 724 |
+
drawFrame();
|
| 725 |
+
}}
|
| 726 |
+
|
| 727 |
+
function updateHead(){{
|
| 728 |
+
document.getElementById('playhead').style.left=(50+S.time*S.pps*S.zoom)+'px';
|
| 729 |
+
document.getElementById('curT').textContent=fmt(S.time);
|
| 730 |
+
}}
|
| 731 |
+
|
| 732 |
+
function getClipAt(t,type){{
|
| 733 |
+
var sorted=S.clips.filter(function(c){{
|
| 734 |
+
if(type==='visual')return c.type==='video'||c.type==='image';
|
| 735 |
+
if(type==='audio')return c.type==='audio';
|
| 736 |
+
return true;
|
| 737 |
+
}}).sort(function(a,b){{return a.start-b.start}});
|
| 738 |
+
for(var i=0;i<sorted.length;i++){{
|
| 739 |
+
var c=sorted[i];
|
| 740 |
+
var cEnd=c.start+(c.te-c.ts);
|
| 741 |
+
if(t>=c.start&&t<cEnd)return c;
|
| 742 |
+
}}
|
| 743 |
+
return null;
|
| 744 |
+
}}
|
| 745 |
+
|
| 746 |
+
function drawFrame(){{
|
| 747 |
+
var t=S.time;
|
| 748 |
+
var vc=getClipAt(t,'visual');
|
| 749 |
+
var size=S.ratioSizes[S.ratio];
|
| 750 |
+
var pw=size.pw,ph=size.ph;
|
| 751 |
+
|
| 752 |
+
S.ctx.fillStyle='#000';
|
| 753 |
+
S.ctx.fillRect(0,0,pw,ph);
|
| 754 |
+
|
| 755 |
+
if(vc){{
|
| 756 |
+
var el=S.els[vc.mid];
|
| 757 |
+
if(el){{
|
| 758 |
+
if(vc.type==='video'){{
|
| 759 |
+
var clipT=t-vc.start+vc.ts;
|
| 760 |
+
if(Math.abs(el.currentTime-clipT)>0.05){{
|
| 761 |
+
el.currentTime=clipT;
|
| 762 |
+
}}
|
| 763 |
+
if(S.playing&&el.paused)el.play().catch(function(){{}});
|
| 764 |
+
if(!S.playing&&!el.paused)el.pause();
|
| 765 |
+
el.volume=S.muted?0:vc.vol;
|
| 766 |
+
}}
|
| 767 |
+
try{{
|
| 768 |
+
var sw=el.videoWidth||el.naturalWidth||el.width||pw;
|
| 769 |
+
var sh=el.videoHeight||el.naturalHeight||el.height||ph;
|
| 770 |
+
drawWithMode(S.ctx,el,sw,sh,pw,ph,S.fillMode);
|
| 771 |
+
}}catch(e){{}}
|
| 772 |
+
}}
|
| 773 |
+
}}else if(S.clips.length===0){{
|
| 774 |
+
S.ctx.fillStyle='#444';
|
| 775 |
+
S.ctx.font='14px sans-serif';
|
| 776 |
+
S.ctx.textAlign='center';
|
| 777 |
+
S.ctx.fillText('타임라인에 미디어를 추가하세요',pw/2,ph/2);
|
| 778 |
+
}}
|
| 779 |
+
|
| 780 |
+
var audioClips=S.clips.filter(function(c){{
|
| 781 |
+
if(c.type!=='audio')return false;
|
| 782 |
+
var cEnd=c.start+(c.te-c.ts);
|
| 783 |
+
return t>=c.start&&t<cEnd;
|
| 784 |
+
}});
|
| 785 |
+
audioClips.forEach(function(ac){{
|
| 786 |
+
var el=S.els[ac.mid];
|
| 787 |
+
if(el){{
|
| 788 |
+
var clipT=t-ac.start+ac.ts;
|
| 789 |
+
if(Math.abs(el.currentTime-clipT)>0.1)el.currentTime=clipT;
|
| 790 |
+
el.volume=S.muted?0:ac.vol;
|
| 791 |
+
if(S.playing&&el.paused)el.play().catch(function(){{}});
|
| 792 |
+
if(!S.playing&&!el.paused)el.pause();
|
| 793 |
+
}}
|
| 794 |
+
}});
|
| 795 |
+
S.clips.forEach(function(c){{
|
| 796 |
+
if(c.type!=='audio')return;
|
| 797 |
+
var cEnd=c.start+(c.te-c.ts);
|
| 798 |
+
if(t<c.start||t>=cEnd){{
|
| 799 |
+
var el=S.els[c.mid];
|
| 800 |
+
if(el&&!el.paused)el.pause();
|
| 801 |
+
}}
|
| 802 |
+
}});
|
| 803 |
+
if(!vc&&!audioClips.length&&S.clips.length>0){{
|
| 804 |
+
var hasText=getTextClipsAt(t).length>0;
|
| 805 |
+
if(!hasText){{
|
| 806 |
+
S.ctx.fillStyle='#333';
|
| 807 |
+
S.ctx.font='12px sans-serif';
|
| 808 |
+
S.ctx.textAlign='center';
|
| 809 |
+
S.ctx.fillText('재생 위치에 미디어가 없습니다',pw/2,ph/2);
|
| 810 |
+
}}
|
| 811 |
+
}}
|
| 812 |
+
|
| 813 |
+
var textClips=getTextClipsAt(t);
|
| 814 |
+
textClips.forEach(function(tc){{
|
| 815 |
+
drawText(S.ctx,tc,pw,ph);
|
| 816 |
+
}});
|
| 817 |
+
}}
|
| 818 |
+
|
| 819 |
+
function drawWithMode(ctx,el,sw,sh,dw,dh,mode){{
|
| 820 |
+
if(mode==='fill'){{
|
| 821 |
+
var scale=Math.max(dw/sw,dh/sh);
|
| 822 |
+
var nw=sw*scale,nh=sh*scale;
|
| 823 |
+
var ox=(dw-nw)/2,oy=(dh-nh)/2;
|
| 824 |
+
ctx.drawImage(el,ox,oy,nw,nh);
|
| 825 |
+
}}else if(mode==='blur'){{
|
| 826 |
+
var frameCanvas=document.createElement('canvas');
|
| 827 |
+
frameCanvas.width=sw;frameCanvas.height=sh;
|
| 828 |
+
var frameCtx=frameCanvas.getContext('2d');
|
| 829 |
+
frameCtx.drawImage(el,0,0,sw,sh);
|
| 830 |
+
|
| 831 |
+
var blurCanvas=document.createElement('canvas');
|
| 832 |
+
blurCanvas.width=16;blurCanvas.height=16;
|
| 833 |
+
var blurCtx=blurCanvas.getContext('2d');
|
| 834 |
+
blurCtx.drawImage(frameCanvas,0,0,16,16);
|
| 835 |
+
|
| 836 |
+
ctx.imageSmoothingEnabled=true;
|
| 837 |
+
ctx.imageSmoothingQuality='high';
|
| 838 |
+
var scale=Math.max(dw/sw,dh/sh)*1.1;
|
| 839 |
+
var nw=sw*scale,nh=sh*scale;
|
| 840 |
+
var ox=(dw-nw)/2,oy=(dh-nh)/2;
|
| 841 |
+
ctx.drawImage(blurCanvas,ox,oy,nw,nh);
|
| 842 |
+
|
| 843 |
+
ctx.fillStyle='rgba(0,0,0,0.4)';
|
| 844 |
+
ctx.fillRect(0,0,dw,dh);
|
| 845 |
+
|
| 846 |
+
var fitScale=Math.min(dw/sw,dh/sh);
|
| 847 |
+
var fw=sw*fitScale,fh=sh*fitScale;
|
| 848 |
+
var fx=(dw-fw)/2,fy=(dh-fh)/2;
|
| 849 |
+
ctx.drawImage(frameCanvas,fx,fy,fw,fh);
|
| 850 |
+
}}else{{
|
| 851 |
+
var scale=Math.min(dw/sw,dh/sh);
|
| 852 |
+
var nw=sw*scale,nh=sh*scale;
|
| 853 |
+
var ox=(dw-nw)/2,oy=(dh-nh)/2;
|
| 854 |
+
ctx.drawImage(el,ox,oy,nw,nh);
|
| 855 |
+
}}
|
| 856 |
+
}}
|
| 857 |
+
|
| 858 |
+
function toggleMute(){{S.muted=!S.muted;document.getElementById('muteBtn').textContent=S.muted?'🔇':'🔊'}}
|
| 859 |
+
|
| 860 |
+
function addTextClip(){{
|
| 861 |
+
document.getElementById('textModal').style.display='flex';
|
| 862 |
+
document.getElementById('textInput').value='';
|
| 863 |
+
document.getElementById('textInput').focus();
|
| 864 |
+
}}
|
| 865 |
+
|
| 866 |
+
function closeTextModal(){{
|
| 867 |
+
document.getElementById('textModal').style.display='none';
|
| 868 |
+
}}
|
| 869 |
+
|
| 870 |
+
function toggleBgColor(){{
|
| 871 |
+
var style=document.getElementById('textBgStyle').value;
|
| 872 |
+
document.getElementById('bgColorBox').style.opacity=style==='none'?'0.5':'1';
|
| 873 |
+
}}
|
| 874 |
+
|
| 875 |
+
function confirmAddText(){{
|
| 876 |
+
var text=document.getElementById('textInput').value.trim();
|
| 877 |
+
if(!text){{alert('텍스트를 입력하세요');return}}
|
| 878 |
+
save();
|
| 879 |
+
var duration=parseFloat(document.getElementById('textDuration').value)||5;
|
| 880 |
+
S.clips.push({{
|
| 881 |
+
id:id(),
|
| 882 |
+
type:'text',
|
| 883 |
+
track:2,
|
| 884 |
+
start:S.time,
|
| 885 |
+
dur:duration,
|
| 886 |
+
ts:0,
|
| 887 |
+
te:duration,
|
| 888 |
+
text:text,
|
| 889 |
+
fontSize:parseInt(document.getElementById('textSize').value),
|
| 890 |
+
fontColor:document.getElementById('textColor').value,
|
| 891 |
+
bgStyle:document.getElementById('textBgStyle').value,
|
| 892 |
+
bgColor:document.getElementById('textBgColor').value,
|
| 893 |
+
posX:0.5,
|
| 894 |
+
posY:0.85
|
| 895 |
+
}});
|
| 896 |
+
closeTextModal();
|
| 897 |
+
renderTL();
|
| 898 |
+
updateDur();
|
| 899 |
+
drawFrame();
|
| 900 |
+
stat('텍스트 추가: '+text);
|
| 901 |
+
}}
|
| 902 |
+
|
| 903 |
+
function getTextClipsAt(t){{
|
| 904 |
+
return S.clips.filter(function(c){{
|
| 905 |
+
if(c.type!=='text')return false;
|
| 906 |
+
var cEnd=c.start+(c.te-c.ts);
|
| 907 |
+
return t>=c.start&&t<cEnd;
|
| 908 |
+
}});
|
| 909 |
+
}}
|
| 910 |
+
|
| 911 |
+
function drawText(ctx,clip,dw,dh){{
|
| 912 |
+
var text=clip.text;
|
| 913 |
+
var fontSize=clip.fontSize||48;
|
| 914 |
+
var fontColor=clip.fontColor||'#ffffff';
|
| 915 |
+
var bgStyle=clip.bgStyle||'none';
|
| 916 |
+
var bgColor=clip.bgColor||'#000000';
|
| 917 |
+
var posX=clip.posX!==undefined?clip.posX:0.5;
|
| 918 |
+
var posY=clip.posY!==undefined?clip.posY:0.85;
|
| 919 |
+
|
| 920 |
+
ctx.font='bold '+fontSize+'px -apple-system,BlinkMacSystemFont,sans-serif';
|
| 921 |
+
ctx.textAlign='center';
|
| 922 |
+
ctx.textBaseline='middle';
|
| 923 |
+
|
| 924 |
+
var metrics=ctx.measureText(text);
|
| 925 |
+
var textW=metrics.width;
|
| 926 |
+
var textH=fontSize;
|
| 927 |
+
var x=dw*posX;
|
| 928 |
+
var y=dh*posY;
|
| 929 |
+
|
| 930 |
+
clip._bounds={{
|
| 931 |
+
x:x-textW/2-fontSize*0.3,
|
| 932 |
+
y:y-textH/2-fontSize*0.15,
|
| 933 |
+
w:textW+fontSize*0.6,
|
| 934 |
+
h:textH+fontSize*0.3
|
| 935 |
+
}};
|
| 936 |
+
|
| 937 |
+
if(bgStyle!=='none'){{
|
| 938 |
+
var padding=fontSize*0.3;
|
| 939 |
+
var bgX=x-textW/2-padding;
|
| 940 |
+
var bgY=y-textH/2-padding/2;
|
| 941 |
+
var bgW=textW+padding*2;
|
| 942 |
+
var bgH=textH+padding;
|
| 943 |
+
|
| 944 |
+
ctx.fillStyle=bgColor+'cc';
|
| 945 |
+
if(bgStyle==='rounded'){{
|
| 946 |
+
ctx.beginPath();
|
| 947 |
+
ctx.roundRect(bgX,bgY,bgW,bgH,10);
|
| 948 |
+
ctx.fill();
|
| 949 |
+
}}else{{
|
| 950 |
+
ctx.fillRect(bgX,bgY,bgW,bgH);
|
| 951 |
+
}}
|
| 952 |
+
}}
|
| 953 |
+
|
| 954 |
+
ctx.fillStyle='rgba(0,0,0,0.5)';
|
| 955 |
+
ctx.fillText(text,x+2,y+2);
|
| 956 |
+
|
| 957 |
+
ctx.fillStyle=fontColor;
|
| 958 |
+
ctx.fillText(text,x,y);
|
| 959 |
+
|
| 960 |
+
if(S.sel===clip.id){{
|
| 961 |
+
ctx.strokeStyle='#6366f1';
|
| 962 |
+
ctx.lineWidth=2;
|
| 963 |
+
ctx.setLineDash([5,3]);
|
| 964 |
+
ctx.strokeRect(clip._bounds.x,clip._bounds.y,clip._bounds.w,clip._bounds.h);
|
| 965 |
+
ctx.setLineDash([]);
|
| 966 |
+
}}
|
| 967 |
+
}}
|
| 968 |
+
|
| 969 |
+
function setZoom(v){{S.zoom=parseFloat(v);renderTL();updateHead()}}
|
| 970 |
+
function tlClick(e){{
|
| 971 |
+
if(e.target.closest('.clip'))return;
|
| 972 |
+
var rect=document.getElementById('tlBox').getBoundingClientRect();
|
| 973 |
+
var scrollL=document.getElementById('tlBox').scrollLeft;
|
| 974 |
+
S.time=Math.max(0,Math.min(S.dur||0,(e.clientX-rect.left-50+scrollL)/(S.pps*S.zoom)));
|
| 975 |
+
updateHead();
|
| 976 |
+
drawFrame();
|
| 977 |
+
}}
|
| 978 |
+
|
| 979 |
+
function showCtx(x,y){{var m=document.getElementById('ctx');m.style.display='block';m.style.left=x+'px';m.style.top=y+'px'}}
|
| 980 |
+
function hideCtx(){{document.getElementById('ctx').style.display='none'}}
|
| 981 |
+
document.addEventListener('click',function(e){{if(!e.target.closest('.ctx-menu'))hideCtx()}});
|
| 982 |
+
|
| 983 |
+
function exportVideo(){{
|
| 984 |
+
if(!S.clips.length){{alert('클립을 추가하세요');return}}
|
| 985 |
+
S.cancelled=false;
|
| 986 |
+
document.getElementById('exportModal').style.display='flex';
|
| 987 |
+
document.getElementById('exportBar').style.width='0%';
|
| 988 |
+
document.getElementById('exportMsg').textContent='녹화 준비 중...';
|
| 989 |
+
doExport();
|
| 990 |
+
}}
|
| 991 |
+
|
| 992 |
+
// ============================================
|
| 993 |
+
// 핵심 수정: 프레임 기반 동기식 렌더링
|
| 994 |
+
// ============================================
|
| 995 |
+
|
| 996 |
+
function sleep(ms){{
|
| 997 |
+
return new Promise(function(resolve){{setTimeout(resolve,ms)}});
|
| 998 |
+
}}
|
| 999 |
+
|
| 1000 |
+
function seekVideoAndWait(video,targetTime){{
|
| 1001 |
+
return new Promise(function(resolve){{
|
| 1002 |
+
if(Math.abs(video.currentTime-targetTime)<0.02){{
|
| 1003 |
+
resolve();
|
| 1004 |
+
return;
|
| 1005 |
+
}}
|
| 1006 |
+
var resolved=false;
|
| 1007 |
+
function onSeeked(){{
|
| 1008 |
+
if(resolved)return;
|
| 1009 |
+
resolved=true;
|
| 1010 |
+
video.removeEventListener('seeked',onSeeked);
|
| 1011 |
+
resolve();
|
| 1012 |
+
}}
|
| 1013 |
+
video.addEventListener('seeked',onSeeked);
|
| 1014 |
+
video.currentTime=targetTime;
|
| 1015 |
+
// 타임아웃 (시킹이 오래 걸릴 경우 대비)
|
| 1016 |
+
setTimeout(function(){{
|
| 1017 |
+
if(!resolved){{
|
| 1018 |
+
resolved=true;
|
| 1019 |
+
video.removeEventListener('seeked',onSeeked);
|
| 1020 |
+
resolve();
|
| 1021 |
+
}}
|
| 1022 |
+
}},300);
|
| 1023 |
+
}});
|
| 1024 |
+
}}
|
| 1025 |
+
|
| 1026 |
+
async function doExport(){{
|
| 1027 |
+
var size=S.ratioSizes[S.ratio];
|
| 1028 |
+
var exportW=size.w,exportH=size.h;
|
| 1029 |
+
|
| 1030 |
+
// 메인 캔버스 (MediaRecorder용)
|
| 1031 |
+
var canvas=document.createElement('canvas');
|
| 1032 |
+
canvas.width=exportW;canvas.height=exportH;
|
| 1033 |
+
var ctx=canvas.getContext('2d');
|
| 1034 |
+
|
| 1035 |
+
// 초기 검은 화면
|
| 1036 |
+
ctx.fillStyle='#000';
|
| 1037 |
+
ctx.fillRect(0,0,exportW,exportH);
|
| 1038 |
+
|
| 1039 |
+
var stream=canvas.captureStream(30);
|
| 1040 |
+
|
| 1041 |
+
var opts={{mimeType:'video/webm;codecs=vp9',videoBitsPerSecond:8000000}};
|
| 1042 |
+
if(!MediaRecorder.isTypeSupported(opts.mimeType)){{
|
| 1043 |
+
opts={{mimeType:'video/webm;codecs=vp8',videoBitsPerSecond:8000000}};
|
| 1044 |
+
}}
|
| 1045 |
+
if(!MediaRecorder.isTypeSupported(opts.mimeType)){{
|
| 1046 |
+
opts={{mimeType:'video/webm',videoBitsPerSecond:5000000}};
|
| 1047 |
+
}}
|
| 1048 |
+
|
| 1049 |
+
var rec=new MediaRecorder(stream,opts);
|
| 1050 |
+
var chunks=[];
|
| 1051 |
+
rec.ondataavailable=function(e){{if(e.data.size>0)chunks.push(e.data)}};
|
| 1052 |
+
|
| 1053 |
+
document.getElementById('exportMsg').textContent='녹화 중... ('+S.ratio+')';
|
| 1054 |
+
rec.start(100);
|
| 1055 |
+
|
| 1056 |
+
var dur=S.dur;
|
| 1057 |
+
var fps=30;
|
| 1058 |
+
var totalFrames=Math.ceil(dur*fps);
|
| 1059 |
+
var fillMode=S.fillMode;
|
| 1060 |
+
|
| 1061 |
+
// 모든 비디오 일시정지
|
| 1062 |
+
Object.keys(S.els).forEach(function(k){{
|
| 1063 |
+
var el=S.els[k];
|
| 1064 |
+
if(el&&el.pause)el.pause();
|
| 1065 |
+
}});
|
| 1066 |
+
|
| 1067 |
+
// 블러용 캔버스 (재사용)
|
| 1068 |
+
var frameCanvas=document.createElement('canvas');
|
| 1069 |
+
var frameCtx=frameCanvas.getContext('2d');
|
| 1070 |
+
var blurCanvas=document.createElement('canvas');
|
| 1071 |
+
blurCanvas.width=16;blurCanvas.height=16;
|
| 1072 |
+
var blurCtx=blurCanvas.getContext('2d');
|
| 1073 |
+
|
| 1074 |
+
// ★ 프레임 단위 순차 렌더링 ★
|
| 1075 |
+
for(var frame=0;frame<=totalFrames;frame++){{
|
| 1076 |
+
if(S.cancelled)break;
|
| 1077 |
+
|
| 1078 |
+
var t=frame/fps;
|
| 1079 |
+
|
| 1080 |
+
// 진행률 업데이트
|
| 1081 |
+
var pct=Math.round(frame/totalFrames*100);
|
| 1082 |
+
document.getElementById('exportBar').style.width=pct+'%';
|
| 1083 |
+
document.getElementById('exportMsg').textContent='녹화 중... '+pct+'% ('+t.toFixed(1)+'/'+dur.toFixed(1)+'초)';
|
| 1084 |
+
|
| 1085 |
+
// 검은 배경
|
| 1086 |
+
ctx.fillStyle='#000';
|
| 1087 |
+
ctx.fillRect(0,0,exportW,exportH);
|
| 1088 |
+
|
| 1089 |
+
// 현재 시간의 비주얼 클립 가져오기
|
| 1090 |
+
var vc=getClipAt(t,'visual');
|
| 1091 |
+
if(vc){{
|
| 1092 |
+
var el=S.els[vc.mid];
|
| 1093 |
+
if(el){{
|
| 1094 |
+
// 비디오인 경우 시킹 후 대기
|
| 1095 |
+
if(vc.type==='video'){{
|
| 1096 |
+
var clipT=t-vc.start+vc.ts;
|
| 1097 |
+
await seekVideoAndWait(el,clipT);
|
| 1098 |
+
}}
|
| 1099 |
+
|
| 1100 |
+
try{{
|
| 1101 |
+
var sw=el.videoWidth||el.naturalWidth||el.width||exportW;
|
| 1102 |
+
var sh=el.videoHeight||el.naturalHeight||el.height||exportH;
|
| 1103 |
+
|
| 1104 |
+
if(fillMode==='blur'){{
|
| 1105 |
+
// ★ 블러 모드: 프레임을 먼저 캡처 후 처리 ★
|
| 1106 |
+
frameCanvas.width=sw;
|
| 1107 |
+
frameCanvas.height=sh;
|
| 1108 |
+
frameCtx.drawImage(el,0,0,sw,sh);
|
| 1109 |
+
|
| 1110 |
+
// 블러용 축소
|
| 1111 |
+
blurCtx.drawImage(frameCanvas,0,0,16,16);
|
| 1112 |
+
|
| 1113 |
+
// 배경 (블러된 이미지 확대)
|
| 1114 |
+
ctx.imageSmoothingEnabled=true;
|
| 1115 |
+
ctx.imageSmoothingQuality='high';
|
| 1116 |
+
var scale=Math.max(exportW/sw,exportH/sh)*1.1;
|
| 1117 |
+
var nw=sw*scale,nh=sh*scale;
|
| 1118 |
+
var ox=(exportW-nw)/2,oy=(exportH-nh)/2;
|
| 1119 |
+
ctx.drawImage(blurCanvas,ox,oy,nw,nh);
|
| 1120 |
+
|
| 1121 |
+
// 어둡게
|
| 1122 |
+
ctx.fillStyle='rgba(0,0,0,0.4)';
|
| 1123 |
+
ctx.fillRect(0,0,exportW,exportH);
|
| 1124 |
+
|
| 1125 |
+
// 원본 (캡처된 프레임)
|
| 1126 |
+
var fitScale=Math.min(exportW/sw,exportH/sh);
|
| 1127 |
+
var fw=sw*fitScale,fh=sh*fitScale;
|
| 1128 |
+
var fx=(exportW-fw)/2,fy=(exportH-fh)/2;
|
| 1129 |
+
ctx.drawImage(frameCanvas,fx,fy,fw,fh);
|
| 1130 |
+
}}else if(fillMode==='fill'){{
|
| 1131 |
+
var scale=Math.max(exportW/sw,exportH/sh);
|
| 1132 |
+
var nw=sw*scale,nh=sh*scale;
|
| 1133 |
+
var ox=(exportW-nw)/2,oy=(exportH-nh)/2;
|
| 1134 |
+
ctx.drawImage(el,ox,oy,nw,nh);
|
| 1135 |
+
}}else{{
|
| 1136 |
+
// fit
|
| 1137 |
+
var scale=Math.min(exportW/sw,exportH/sh);
|
| 1138 |
+
var nw=sw*scale,nh=sh*scale;
|
| 1139 |
+
var ox=(exportW-nw)/2,oy=(exportH-nh)/2;
|
| 1140 |
+
ctx.drawImage(el,ox,oy,nw,nh);
|
| 1141 |
+
}}
|
| 1142 |
+
}}catch(e){{console.error('Draw error:',e)}}
|
| 1143 |
+
}}
|
| 1144 |
+
}}
|
| 1145 |
+
|
| 1146 |
+
// 텍스트 오버레이 렌더링
|
| 1147 |
+
var textClips=getTextClipsAt(t);
|
| 1148 |
+
textClips.forEach(function(tc){{
|
| 1149 |
+
drawTextExport(ctx,tc,exportW,exportH);
|
| 1150 |
+
}});
|
| 1151 |
+
|
| 1152 |
+
// ★ 프레임 간격 대기 - MediaRecorder가 프레임 캡처할 시간 ★
|
| 1153 |
+
await sleep(1000/fps);
|
| 1154 |
+
}}
|
| 1155 |
+
|
| 1156 |
+
// 녹화 종료
|
| 1157 |
+
rec.stop();
|
| 1158 |
+
await sleep(300);
|
| 1159 |
+
|
| 1160 |
+
// 모든 미디어 정지
|
| 1161 |
+
Object.keys(S.els).forEach(function(k){{
|
| 1162 |
+
var el=S.els[k];
|
| 1163 |
+
if(el&&el.pause)el.pause();
|
| 1164 |
+
}});
|
| 1165 |
+
|
| 1166 |
+
if(S.cancelled)return;
|
| 1167 |
+
|
| 1168 |
+
var webmBlob=new Blob(chunks,{{type:'video/webm'}});
|
| 1169 |
+
if(webmBlob.size<1000){{
|
| 1170 |
+
document.getElementById('exportMsg').textContent='녹화 실패';
|
| 1171 |
+
return;
|
| 1172 |
+
}}
|
| 1173 |
+
|
| 1174 |
+
document.getElementById('exportBar').style.width='100%';
|
| 1175 |
+
document.getElementById('exportMsg').textContent='완료! ('+Math.round(webmBlob.size/1024/1024*10)/10+'MB, '+S.ratio+') - 아래에서 다운로드';
|
| 1176 |
+
|
| 1177 |
+
var downloadDiv=document.createElement('div');
|
| 1178 |
+
downloadDiv.style.marginTop='10px';
|
| 1179 |
+
var webmLink=document.createElement('a');
|
| 1180 |
+
webmLink.href=URL.createObjectURL(webmBlob);
|
| 1181 |
+
webmLink.download='video_'+S.ratio.replace(':','x')+'_'+Date.now()+'.webm';
|
| 1182 |
+
webmLink.className='btn btn-success';
|
| 1183 |
+
webmLink.textContent='📥 WebM 다운로드';
|
| 1184 |
+
webmLink.style.marginRight='5px';
|
| 1185 |
+
downloadDiv.appendChild(webmLink);
|
| 1186 |
+
|
| 1187 |
+
var copyBtn=document.createElement('button');
|
| 1188 |
+
copyBtn.className='btn btn-secondary';
|
| 1189 |
+
copyBtn.textContent='📋 MP4변환용 복사';
|
| 1190 |
+
copyBtn.onclick=async function(){{
|
| 1191 |
+
document.getElementById('exportMsg').textContent='데이터 준비 중...';
|
| 1192 |
+
var reader=new FileReader();
|
| 1193 |
+
reader.onload=function(){{
|
| 1194 |
+
var base64=reader.result.split(',')[1];
|
| 1195 |
+
navigator.clipboard.writeText(base64).then(function(){{
|
| 1196 |
+
document.getElementById('exportMsg').textContent='복사 완료! 위 입력란에 붙여넣기';
|
| 1197 |
+
alert('복사 완료!\\n\\nGradio의 "WebM 데이터" 입력란에 붙여넣기(Ctrl+V) 후\\n"MP4 변환" 버튼을 클릭하세요.');
|
| 1198 |
+
}}).catch(function(){{
|
| 1199 |
+
prompt('아래 데이터를 복사하세요:', base64.substring(0,100)+'...');
|
| 1200 |
+
}});
|
| 1201 |
+
}};
|
| 1202 |
+
reader.readAsDataURL(webmBlob);
|
| 1203 |
+
}};
|
| 1204 |
+
downloadDiv.appendChild(copyBtn);
|
| 1205 |
+
document.querySelector('.modal-box').appendChild(downloadDiv);
|
| 1206 |
+
}}
|
| 1207 |
+
|
| 1208 |
+
// 내보내기용 텍스트 렌더링
|
| 1209 |
+
function drawTextExport(ctx,clip,dw,dh){{
|
| 1210 |
+
var text=clip.text;
|
| 1211 |
+
var fontSize=Math.round(clip.fontSize*(dw/640))||72;
|
| 1212 |
+
var fontColor=clip.fontColor||'#ffffff';
|
| 1213 |
+
var bgStyle=clip.bgStyle||'none';
|
| 1214 |
+
var bgColor=clip.bgColor||'#000000';
|
| 1215 |
+
var posX=clip.posX!==undefined?clip.posX:0.5;
|
| 1216 |
+
var posY=clip.posY!==undefined?clip.posY:0.85;
|
| 1217 |
+
|
| 1218 |
+
ctx.font='bold '+fontSize+'px -apple-system,BlinkMacSystemFont,sans-serif';
|
| 1219 |
+
ctx.textAlign='center';
|
| 1220 |
+
ctx.textBaseline='middle';
|
| 1221 |
+
|
| 1222 |
+
var metrics=ctx.measureText(text);
|
| 1223 |
+
var textW=metrics.width;
|
| 1224 |
+
var textH=fontSize;
|
| 1225 |
+
var x=dw*posX;
|
| 1226 |
+
var y=dh*posY;
|
| 1227 |
+
|
| 1228 |
+
if(bgStyle!=='none'){{
|
| 1229 |
+
var padding=fontSize*0.3;
|
| 1230 |
+
var bgX=x-textW/2-padding;
|
| 1231 |
+
var bgY=y-textH/2-padding/2;
|
| 1232 |
+
var bgW=textW+padding*2;
|
| 1233 |
+
var bgH=textH+padding;
|
| 1234 |
+
|
| 1235 |
+
ctx.fillStyle=bgColor+'cc';
|
| 1236 |
+
if(bgStyle==='rounded'){{
|
| 1237 |
+
ctx.beginPath();
|
| 1238 |
+
ctx.roundRect(bgX,bgY,bgW,bgH,15);
|
| 1239 |
+
ctx.fill();
|
| 1240 |
+
}}else{{
|
| 1241 |
+
ctx.fillRect(bgX,bgY,bgW,bgH);
|
| 1242 |
+
}}
|
| 1243 |
+
}}
|
| 1244 |
+
|
| 1245 |
+
ctx.fillStyle='rgba(0,0,0,0.5)';
|
| 1246 |
+
ctx.fillText(text,x+3,y+3);
|
| 1247 |
+
|
| 1248 |
+
ctx.fillStyle=fontColor;
|
| 1249 |
+
ctx.fillText(text,x,y);
|
| 1250 |
+
}}
|
| 1251 |
+
|
| 1252 |
+
function cancelExport(){{S.cancelled=true;document.getElementById('exportModal').style.display='none'}}
|
| 1253 |
+
|
| 1254 |
+
document.addEventListener('keydown',function(e){{
|
| 1255 |
+
if(e.target.tagName==='INPUT')return;
|
| 1256 |
+
if(e.code==='Space'){{e.preventDefault();togglePlay()}}
|
| 1257 |
+
else if(e.code==='Delete'){{e.preventDefault();delClip()}}
|
| 1258 |
+
else if(e.code==='ArrowLeft'){{seek(S.time-0.1)}}
|
| 1259 |
+
else if(e.code==='ArrowRight'){{seek(S.time+0.1)}}
|
| 1260 |
+
}});
|
| 1261 |
+
|
| 1262 |
+
init();
|
| 1263 |
+
renderTL();
|
| 1264 |
+
stat('준비됨');
|
| 1265 |
+
var initData={media_data};
|
| 1266 |
+
if(initData&&initData.length)initData.forEach(function(m){{addMedia(m.name,m.type,m.dataUrl,m.filePath)}});
|
| 1267 |
+
</script>
|
| 1268 |
+
</body>
|
| 1269 |
+
</html>'''
|
| 1270 |
+
|
| 1271 |
+
def process_file(files):
|
| 1272 |
+
global uploaded_files
|
| 1273 |
+
if not files:
|
| 1274 |
+
return []
|
| 1275 |
+
results = []
|
| 1276 |
+
file_list = files if isinstance(files, list) else [files]
|
| 1277 |
+
for f in file_list:
|
| 1278 |
+
if not f:
|
| 1279 |
+
continue
|
| 1280 |
+
path = f.name if hasattr(f, 'name') else f
|
| 1281 |
+
name = os.path.basename(path)
|
| 1282 |
+
ext = name.lower().split('.')[-1]
|
| 1283 |
+
if ext in ['mp4', 'webm', 'mov', 'avi', 'mkv']:
|
| 1284 |
+
t, m = 'video', f'video/{ext}'
|
| 1285 |
+
elif ext in ['jpg', 'jpeg', 'png', 'gif', 'webp']:
|
| 1286 |
+
t, m = 'image', f'image/{ext}'
|
| 1287 |
+
elif ext in ['mp3', 'wav', 'ogg', 'm4a', 'aac']:
|
| 1288 |
+
t, m = 'audio', f'audio/{ext}'
|
| 1289 |
+
else:
|
| 1290 |
+
continue
|
| 1291 |
+
|
| 1292 |
+
dst_path = os.path.join(UPLOAD_DIR, f"{int(time.time()*1000)}_{name}")
|
| 1293 |
+
shutil.copy(path, dst_path)
|
| 1294 |
+
uploaded_files[name] = dst_path
|
| 1295 |
+
|
| 1296 |
+
with open(path, 'rb') as fp:
|
| 1297 |
+
d = base64.b64encode(fp.read()).decode()
|
| 1298 |
+
results.append({'name': name, 'type': t, 'dataUrl': f'data:{m};base64,{d}', 'filePath': name})
|
| 1299 |
+
return results
|
| 1300 |
+
|
| 1301 |
+
def make_iframe(data):
|
| 1302 |
+
j = json.dumps(data, ensure_ascii=False)
|
| 1303 |
+
h = get_editor_html(j).replace("'", "'")
|
| 1304 |
+
return f"<iframe srcdoc='{h}' style='width:100%;height:750px;border:none;border-radius:10px'></iframe>"
|
| 1305 |
+
|
| 1306 |
+
def convert_webm_to_mp4(webm_base64):
|
| 1307 |
+
if not webm_base64 or len(webm_base64) < 100:
|
| 1308 |
+
return None
|
| 1309 |
+
|
| 1310 |
+
try:
|
| 1311 |
+
webm_data = base64.b64decode(webm_base64)
|
| 1312 |
+
|
| 1313 |
+
temp_dir = tempfile.mkdtemp()
|
| 1314 |
+
webm_path = os.path.join(temp_dir, 'input.webm')
|
| 1315 |
+
mp4_path = os.path.join(temp_dir, f'output_{int(time.time())}.mp4')
|
| 1316 |
+
|
| 1317 |
+
with open(webm_path, 'wb') as f:
|
| 1318 |
+
f.write(webm_data)
|
| 1319 |
+
|
| 1320 |
+
cmd = [
|
| 1321 |
+
'ffmpeg', '-y',
|
| 1322 |
+
'-i', webm_path,
|
| 1323 |
+
'-c:v', 'libx264',
|
| 1324 |
+
'-preset', 'fast',
|
| 1325 |
+
'-crf', '23',
|
| 1326 |
+
'-c:a', 'aac',
|
| 1327 |
+
'-b:a', '128k',
|
| 1328 |
+
'-movflags', '+faststart',
|
| 1329 |
+
mp4_path
|
| 1330 |
+
]
|
| 1331 |
+
|
| 1332 |
+
subprocess.run(cmd, capture_output=True, text=True, timeout=300)
|
| 1333 |
+
|
| 1334 |
+
try:
|
| 1335 |
+
os.remove(webm_path)
|
| 1336 |
+
except:
|
| 1337 |
+
pass
|
| 1338 |
+
|
| 1339 |
+
if os.path.exists(mp4_path) and os.path.getsize(mp4_path) > 0:
|
| 1340 |
+
return mp4_path
|
| 1341 |
+
|
| 1342 |
+
return None
|
| 1343 |
+
|
| 1344 |
+
except Exception as e:
|
| 1345 |
+
print(f"[Convert] Error: {e}")
|
| 1346 |
+
return None
|
| 1347 |
+
|
| 1348 |
+
with gr.Blocks() as demo:
|
| 1349 |
+
gr.Markdown("## 🎬 Video Editor (블러 수정)")
|
| 1350 |
+
|
| 1351 |
+
f = gr.File(label="📁 파일 업로드", file_count="multiple", file_types=["video", "image", "audio"])
|
| 1352 |
+
e = gr.HTML(value=make_iframe([]))
|
| 1353 |
+
|
| 1354 |
+
gr.Markdown("---")
|
| 1355 |
+
gr.Markdown("### 📥 MP4 변환")
|
| 1356 |
+
gr.Markdown("에디터에서 '내보내기' → 'MP4변환용 복사' 클릭 후 아래에 붙여넣기")
|
| 1357 |
+
|
| 1358 |
+
with gr.Row():
|
| 1359 |
+
webm_data = gr.Textbox(label="WebM 데이터 (base64)", placeholder="여기에 붙여넣기 (Ctrl+V)", lines=2, scale=4)
|
| 1360 |
+
convert_btn = gr.Button("🎬 MP4 변환", variant="primary", scale=1)
|
| 1361 |
+
|
| 1362 |
+
mp4_output = gr.File(label="📥 MP4 다운로드")
|
| 1363 |
+
|
| 1364 |
+
f.change(fn=lambda x: make_iframe(process_file(x)), inputs=[f], outputs=[e])
|
| 1365 |
+
convert_btn.click(fn=convert_webm_to_mp4, inputs=[webm_data], outputs=[mp4_output])
|
| 1366 |
+
|
| 1367 |
+
if __name__ == "__main__":
|
| 1368 |
+
demo.launch()
|