Update app.py
Browse files
app.py
CHANGED
|
@@ -98,7 +98,7 @@ body{{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Noto Sans
|
|
| 98 |
.clip-info{{padding:0 6px;flex:1;overflow:hidden}}
|
| 99 |
.clip-name{{font-size:10px;font-weight:500;color:#fff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}}
|
| 100 |
.clip-duration{{font-size:9px;color:rgba(255,255,255,0.7)}}
|
| 101 |
-
.clip-handles{{position:absolute;top:0;bottom:0;width:
|
| 102 |
.timeline-clip:hover .clip-handles{{opacity:1}}
|
| 103 |
.clip-handle-left{{left:0;border-radius:6px 0 0 6px}}
|
| 104 |
.clip-handle-right{{right:0;border-radius:0 6px 6px 0}}
|
|
@@ -208,7 +208,7 @@ Simple Video Editor
|
|
| 208 |
</div>
|
| 209 |
</div>
|
| 210 |
<script>
|
| 211 |
-
var S={{mediaLibrary:[],timelineClips:[],selectedClipId:null,isPlaying:false,isMuted:false,currentTime:0,totalDuration:0,zoom:1,pps:80,undoStack:[],animId:null,audioElements:{{}}}};
|
| 212 |
function gid(){{return Date.now().toString(36)+Math.random().toString(36).substr(2)}}
|
| 213 |
function fmt(s){{if(!s||isNaN(s))s=0;var m=Math.floor(s/60),sec=Math.floor(s%60),ms=Math.floor((s%1)*100);return(m<10?'0':'')+m+':'+(sec<10?'0':'')+sec+'.'+(ms<10?'0':'')+ms}}
|
| 214 |
function upStat(msg){{var e=document.getElementById('statusBar');if(e)e.textContent=msg+' | ๋ฏธ๋์ด: '+S.mediaLibrary.length+'๊ฐ | ํด๋ฆฝ: '+S.timelineClips.length+'๊ฐ'}}
|
|
@@ -249,7 +249,7 @@ var c={{id:gid(),mid:m.id,name:m.name,type:m.type,url:m.url,thumb:m.thumb,track:
|
|
| 249 |
S.timelineClips.push(c);
|
| 250 |
renderTL();upDur();upStat('ํด๋ฆฝ ์ถ๊ฐ๋จ: '+c.name);
|
| 251 |
}}
|
| 252 |
-
function getTrEnd(tr){{var mx=0;S.timelineClips.forEach(function(c){{if(c.track===tr){{var e=c.start+(c.te-c.ts);if(e>mx)mx=e}}}});return mx}}
|
| 253 |
function renderTL(){{
|
| 254 |
var t0=document.getElementById('track0'),t1=document.getElementById('track1');
|
| 255 |
if(t0)t0.innerHTML='';if(t1)t1.innerHTML='';
|
|
@@ -263,11 +263,44 @@ d.onclick=function(e){{e.stopPropagation();selClip(c.id)}};
|
|
| 263 |
d.oncontextmenu=function(e){{e.preventDefault();selClip(c.id);showCtx(e.clientX,e.clientY)}};
|
| 264 |
d.ondragstart=function(e){{e.dataTransfer.setData('cid',c.id);e.dataTransfer.setData('ox',e.offsetX.toString())}};
|
| 265 |
var th=c.thumb?'<img class="clip-thumbnail" src="'+c.thumb+'">':'';
|
| 266 |
-
d.innerHTML=th+'<div class="clip-info"><div class="clip-name">'+c.name+'</div><div class="clip-duration">'+fmt(cd)+'</div></div><div class="clip-handles clip-handle-left"></div><div class="clip-handles clip-handle-right"></div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
tr.appendChild(d);
|
| 268 |
}});
|
| 269 |
renderRuler();setupDrop();
|
| 270 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
function renderRuler(){{
|
| 272 |
var r=document.getElementById('timelineRuler');if(!r)return;
|
| 273 |
var w=Math.max(S.totalDuration*S.pps*S.zoom+300,1000);r.style.width=w+'px';
|
|
@@ -306,12 +339,19 @@ ct.innerHTML=h;
|
|
| 306 |
}}
|
| 307 |
function upProp(p,v){{save();var c=S.timelineClips.find(function(x){{return x.id===S.selectedClipId}});if(c){{c[p]=v;renderTL();upDur();renderProps()}}}}
|
| 308 |
function editorSplit(){{
|
| 309 |
-
if(!S.selectedClipId)
|
| 310 |
var c=S.timelineClips.find(function(x){{return x.id===S.selectedClipId}});if(!c)return;
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
S.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
}}
|
| 316 |
function editorDuplicate(){{
|
| 317 |
if(!S.selectedClipId)return;
|
|
@@ -418,58 +458,82 @@ function editorExport(){{
|
|
| 418 |
if(S.timelineClips.length===0){{alert('ํ์๋ผ์ธ์ ํด๋ฆฝ์ ์ถ๊ฐํด์ฃผ์ธ์.');return}}
|
| 419 |
document.getElementById('exportModal').style.display='flex';
|
| 420 |
document.getElementById('exportProgress').style.width='0%';
|
| 421 |
-
document.getElementById('exportStatus').textContent='
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
var
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
}}),
|
| 441 |
-
media:S.mediaLibrary.map(function(m){{
|
| 442 |
-
return {{id:m.id,name:m.name,type:m.type,duration:m.duration}};
|
| 443 |
-
}})
|
| 444 |
-
}};
|
| 445 |
-
var json=JSON.stringify(project,null,2);
|
| 446 |
-
var blob=new Blob([json],{{type:'application/json'}});
|
| 447 |
var url=URL.createObjectURL(blob);
|
| 448 |
var a=document.createElement('a');
|
| 449 |
-
a.href=url;
|
| 450 |
-
|
| 451 |
-
document.body.appendChild(a);
|
| 452 |
-
a.click();
|
| 453 |
-
document.body.removeChild(a);
|
| 454 |
URL.revokeObjectURL(url);
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
var
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
document.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
}}
|
| 468 |
-
|
|
|
|
| 469 |
}}
|
|
|
|
| 470 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
}}
|
| 472 |
-
function editorCancelExport(){{document.getElementById('exportModal').style.display='none';document.getElementById('cancelExportBtn').textContent='์ทจ์'}}
|
| 473 |
document.addEventListener('keydown',function(e){{
|
| 474 |
if(e.target.tagName==='INPUT')return;
|
| 475 |
if(e.code==='Space'){{e.preventDefault();editorTogglePlay()}}
|
|
|
|
| 98 |
.clip-info{{padding:0 6px;flex:1;overflow:hidden}}
|
| 99 |
.clip-name{{font-size:10px;font-weight:500;color:#fff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}}
|
| 100 |
.clip-duration{{font-size:9px;color:rgba(255,255,255,0.7)}}
|
| 101 |
+
.clip-handles{{position:absolute;top:0;bottom:0;width:10px;background:rgba(255,255,255,0.5);cursor:ew-resize;opacity:0;transition:opacity 0.15s;z-index:10}}
|
| 102 |
.timeline-clip:hover .clip-handles{{opacity:1}}
|
| 103 |
.clip-handle-left{{left:0;border-radius:6px 0 0 6px}}
|
| 104 |
.clip-handle-right{{right:0;border-radius:0 6px 6px 0}}
|
|
|
|
| 208 |
</div>
|
| 209 |
</div>
|
| 210 |
<script>
|
| 211 |
+
var S={{mediaLibrary:[],timelineClips:[],selectedClipId:null,isPlaying:false,isMuted:false,currentTime:0,totalDuration:0,zoom:1,pps:80,undoStack:[],animId:null,audioElements:{{}},trimData:null,exportCancelled:false}};
|
| 212 |
function gid(){{return Date.now().toString(36)+Math.random().toString(36).substr(2)}}
|
| 213 |
function fmt(s){{if(!s||isNaN(s))s=0;var m=Math.floor(s/60),sec=Math.floor(s%60),ms=Math.floor((s%1)*100);return(m<10?'0':'')+m+':'+(sec<10?'0':'')+sec+'.'+(ms<10?'0':'')+ms}}
|
| 214 |
function upStat(msg){{var e=document.getElementById('statusBar');if(e)e.textContent=msg+' | ๋ฏธ๋์ด: '+S.mediaLibrary.length+'๊ฐ | ํด๋ฆฝ: '+S.timelineClips.length+'๊ฐ'}}
|
|
|
|
| 249 |
S.timelineClips.push(c);
|
| 250 |
renderTL();upDur();upStat('ํด๋ฆฝ ์ถ๊ฐ๋จ: '+c.name);
|
| 251 |
}}
|
| 252 |
+
function getTrEnd(tr){{var mx=0;S.timelineClips.forEach(function(c){{if(c.track===tr){{var e=c.start+(c.te-c.ts);if(e>mx)mx=e}}}});return Math.round(mx*1000)/1000}}
|
| 253 |
function renderTL(){{
|
| 254 |
var t0=document.getElementById('track0'),t1=document.getElementById('track1');
|
| 255 |
if(t0)t0.innerHTML='';if(t1)t1.innerHTML='';
|
|
|
|
| 263 |
d.oncontextmenu=function(e){{e.preventDefault();selClip(c.id);showCtx(e.clientX,e.clientY)}};
|
| 264 |
d.ondragstart=function(e){{e.dataTransfer.setData('cid',c.id);e.dataTransfer.setData('ox',e.offsetX.toString())}};
|
| 265 |
var th=c.thumb?'<img class="clip-thumbnail" src="'+c.thumb+'">':'';
|
| 266 |
+
d.innerHTML=th+'<div class="clip-info"><div class="clip-name">'+c.name+'</div><div class="clip-duration">'+fmt(cd)+'</div></div><div class="clip-handles clip-handle-left" data-cid="'+c.id+'" data-side="left"></div><div class="clip-handles clip-handle-right" data-cid="'+c.id+'" data-side="right"></div>';
|
| 267 |
+
var hl=d.querySelector('.clip-handle-left');
|
| 268 |
+
var hr=d.querySelector('.clip-handle-right');
|
| 269 |
+
hl.onmousedown=function(e){{e.stopPropagation();startTrim(e,c.id,'left')}};
|
| 270 |
+
hr.onmousedown=function(e){{e.stopPropagation();startTrim(e,c.id,'right')}};
|
| 271 |
tr.appendChild(d);
|
| 272 |
}});
|
| 273 |
renderRuler();setupDrop();
|
| 274 |
}}
|
| 275 |
+
function startTrim(e,cid,side){{
|
| 276 |
+
e.preventDefault();
|
| 277 |
+
var c=S.timelineClips.find(function(x){{return x.id===cid}});if(!c)return;
|
| 278 |
+
save();
|
| 279 |
+
S.trimData={{cid:cid,side:side,startX:e.clientX,origTs:c.ts,origTe:c.te,origStart:c.start}};
|
| 280 |
+
document.addEventListener('mousemove',doTrim);
|
| 281 |
+
document.addEventListener('mouseup',endTrim);
|
| 282 |
+
}}
|
| 283 |
+
function doTrim(e){{
|
| 284 |
+
if(!S.trimData)return;
|
| 285 |
+
var c=S.timelineClips.find(function(x){{return x.id===S.trimData.cid}});if(!c)return;
|
| 286 |
+
var dx=e.clientX-S.trimData.startX;
|
| 287 |
+
var dt=dx/(S.pps*S.zoom);
|
| 288 |
+
if(S.trimData.side==='left'){{
|
| 289 |
+
var newTs=Math.max(0,Math.min(c.te-0.1,S.trimData.origTs+dt));
|
| 290 |
+
var delta=newTs-S.trimData.origTs;
|
| 291 |
+
c.ts=newTs;
|
| 292 |
+
c.start=S.trimData.origStart+delta;
|
| 293 |
+
}}else{{
|
| 294 |
+
var newTe=Math.max(c.ts+0.1,Math.min(c.dur,S.trimData.origTe+dt));
|
| 295 |
+
c.te=newTe;
|
| 296 |
+
}}
|
| 297 |
+
renderTL();upDur();
|
| 298 |
+
}}
|
| 299 |
+
function endTrim(){{
|
| 300 |
+
S.trimData=null;
|
| 301 |
+
document.removeEventListener('mousemove',doTrim);
|
| 302 |
+
document.removeEventListener('mouseup',endTrim);
|
| 303 |
+
}}
|
| 304 |
function renderRuler(){{
|
| 305 |
var r=document.getElementById('timelineRuler');if(!r)return;
|
| 306 |
var w=Math.max(S.totalDuration*S.pps*S.zoom+300,1000);r.style.width=w+'px';
|
|
|
|
| 339 |
}}
|
| 340 |
function upProp(p,v){{save();var c=S.timelineClips.find(function(x){{return x.id===S.selectedClipId}});if(c){{c[p]=v;renderTL();upDur();renderProps()}}}}
|
| 341 |
function editorSplit(){{
|
| 342 |
+
if(!S.selectedClipId){{alert('ํด๋ฆฝ์ ์ ํํด์ฃผ์ธ์.');return}}
|
| 343 |
var c=S.timelineClips.find(function(x){{return x.id===S.selectedClipId}});if(!c)return;
|
| 344 |
+
var clipEnd=c.start+(c.te-c.ts);
|
| 345 |
+
if(S.currentTime<=c.start||S.currentTime>=clipEnd){{alert('ํ๋ ์ดํค๋๊ฐ ์ ํํ ํด๋ฆฝ ๋ฒ์ ์์ ์์ด์ผ ํฉ๋๋ค.');return}}
|
| 346 |
+
save();
|
| 347 |
+
var splitAt=S.currentTime-c.start;
|
| 348 |
+
var c2=JSON.parse(JSON.stringify(c));
|
| 349 |
+
c2.id=gid();
|
| 350 |
+
c2.start=S.currentTime;
|
| 351 |
+
c2.ts=c.ts+splitAt;
|
| 352 |
+
c.te=c.ts+splitAt;
|
| 353 |
+
S.timelineClips.push(c2);
|
| 354 |
+
renderTL();upDur();hideCtx();upStat('ํด๋ฆฝ์ด ํ์ฌ ์์น์์ ๋ถํ ๋จ');
|
| 355 |
}}
|
| 356 |
function editorDuplicate(){{
|
| 357 |
if(!S.selectedClipId)return;
|
|
|
|
| 458 |
if(S.timelineClips.length===0){{alert('ํ์๋ผ์ธ์ ํด๋ฆฝ์ ์ถ๊ฐํด์ฃผ์ธ์.');return}}
|
| 459 |
document.getElementById('exportModal').style.display='flex';
|
| 460 |
document.getElementById('exportProgress').style.width='0%';
|
| 461 |
+
document.getElementById('exportStatus').textContent='์์ ๋ ๋๋ง ์ค๋น ์ค...';
|
| 462 |
+
document.getElementById('cancelExportBtn').textContent='์ทจ์';
|
| 463 |
+
S.exportCancelled=false;
|
| 464 |
+
setTimeout(function(){{startRender()}},100);
|
| 465 |
+
}}
|
| 466 |
+
function startRender(){{
|
| 467 |
+
var canvas=document.createElement('canvas');
|
| 468 |
+
canvas.width=1280;canvas.height=720;
|
| 469 |
+
var ctx=canvas.getContext('2d');
|
| 470 |
+
var stream=canvas.captureStream(30);
|
| 471 |
+
var audioCtx=new(window.AudioContext||window.webkitAudioContext)();
|
| 472 |
+
var dest=audioCtx.createMediaStreamDestination();
|
| 473 |
+
stream.addTrack(dest.stream.getAudioTracks()[0]||stream.getAudioTracks()[0]);
|
| 474 |
+
var chunks=[];
|
| 475 |
+
var recorder=new MediaRecorder(stream,{{mimeType:'video/webm;codecs=vp9',videoBitsPerSecond:5000000}});
|
| 476 |
+
recorder.ondataavailable=function(e){{if(e.data.size>0)chunks.push(e.data)}};
|
| 477 |
+
recorder.onstop=function(){{
|
| 478 |
+
if(S.exportCancelled)return;
|
| 479 |
+
var blob=new Blob(chunks,{{type:'video/webm'}});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
var url=URL.createObjectURL(blob);
|
| 481 |
var a=document.createElement('a');
|
| 482 |
+
a.href=url;a.download='edited_video_'+Date.now()+'.webm';
|
| 483 |
+
document.body.appendChild(a);a.click();document.body.removeChild(a);
|
|
|
|
|
|
|
|
|
|
| 484 |
URL.revokeObjectURL(url);
|
| 485 |
+
document.getElementById('exportStatus').textContent='โ
๋ค์ด๋ก๋ ์๋ฃ!';
|
| 486 |
+
document.getElementById('cancelExportBtn').textContent='๋ซ๊ธฐ';
|
| 487 |
+
}};
|
| 488 |
+
recorder.start();
|
| 489 |
+
var renderTime=0;
|
| 490 |
+
var duration=S.totalDuration;
|
| 491 |
+
var fps=30;
|
| 492 |
+
var frameTime=1/fps;
|
| 493 |
+
var audioSources={{}};
|
| 494 |
+
S.mediaLibrary.forEach(function(m){{
|
| 495 |
+
if(m.type==='video'||m.type==='audio'){{
|
| 496 |
+
var el=document.createElement(m.type);
|
| 497 |
+
el.src=m.url;el.crossOrigin='anonymous';el.preload='auto';el.muted=true;
|
| 498 |
+
audioSources[m.id]=el;
|
| 499 |
+
}}
|
| 500 |
+
}});
|
| 501 |
+
function renderFrame(){{
|
| 502 |
+
if(S.exportCancelled){{recorder.stop();return}}
|
| 503 |
+
if(renderTime>=duration){{recorder.stop();return}}
|
| 504 |
+
var prog=Math.min(100,Math.round((renderTime/duration)*100));
|
| 505 |
+
document.getElementById('exportProgress').style.width=prog+'%';
|
| 506 |
+
document.getElementById('exportStatus').textContent='๋ ๋๋ง ์ค... '+prog+'% ('+fmt(renderTime)+' / '+fmt(duration)+')';
|
| 507 |
+
ctx.fillStyle='#000';ctx.fillRect(0,0,1280,720);
|
| 508 |
+
var curClips=S.timelineClips.filter(function(c){{var ce=c.start+(c.te-c.ts);return renderTime>=c.start&&renderTime<ce}});
|
| 509 |
+
var vc=curClips.find(function(c){{return c.type==='video'||c.type==='image'}});
|
| 510 |
+
if(vc){{
|
| 511 |
+
var clipTime=renderTime-vc.start+vc.ts;
|
| 512 |
+
var media=S.mediaLibrary.find(function(m){{return m.id===vc.mid}});
|
| 513 |
+
if(media){{
|
| 514 |
+
if(vc.type==='image'){{
|
| 515 |
+
var img=new Image();img.src=media.url;
|
| 516 |
+
try{{drawFit(ctx,img,1280,720)}}catch(e){{}}
|
| 517 |
+
}}else if(vc.type==='video'){{
|
| 518 |
+
var vid=audioSources[media.id];
|
| 519 |
+
if(vid){{vid.currentTime=clipTime;try{{drawFit(ctx,vid,1280,720)}}catch(e){{}}}}
|
| 520 |
+
}}
|
| 521 |
+
}}
|
| 522 |
}}
|
| 523 |
+
renderTime+=frameTime;
|
| 524 |
+
setTimeout(renderFrame,1);
|
| 525 |
}}
|
| 526 |
+
setTimeout(renderFrame,500);
|
| 527 |
}}
|
| 528 |
+
function drawFit(ctx,src,w,h){{
|
| 529 |
+
var sw=src.videoWidth||src.width||1280;
|
| 530 |
+
var sh=src.videoHeight||src.height||720;
|
| 531 |
+
var scale=Math.min(w/sw,h/sh);
|
| 532 |
+
var dw=sw*scale,dh=sh*scale;
|
| 533 |
+
var dx=(w-dw)/2,dy=(h-dh)/2;
|
| 534 |
+
ctx.drawImage(src,dx,dy,dw,dh);
|
| 535 |
}}
|
| 536 |
+
function editorCancelExport(){{S.exportCancelled=true;document.getElementById('exportModal').style.display='none';document.getElementById('cancelExportBtn').textContent='์ทจ์'}}
|
| 537 |
document.addEventListener('keydown',function(e){{
|
| 538 |
if(e.target.tagName==='INPUT')return;
|
| 539 |
if(e.code==='Space'){{e.preventDefault();editorTogglePlay()}}
|