Update app.py
Browse files
app.py
CHANGED
|
@@ -629,32 +629,48 @@ var canvas=document.createElement('canvas');
|
|
| 629 |
canvas.width=1280;canvas.height=720;
|
| 630 |
var ctx=canvas.getContext('2d');
|
| 631 |
var stream=canvas.captureStream(30);
|
| 632 |
-
|
| 633 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
var rec=new MediaRecorder(stream,opts);
|
| 635 |
var chunks=[];
|
| 636 |
rec.ondataavailable=function(e){{if(e.data.size>0)chunks.push(e.data)}};
|
|
|
|
| 637 |
document.getElementById('exportMsg').textContent='๋
นํ ์ค...';
|
| 638 |
rec.start(100);
|
|
|
|
| 639 |
var dur=S.dur;
|
| 640 |
-
var
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
document.getElementById('exportBar').style.width=(
|
| 650 |
-
document.getElementById('exportMsg').textContent='๋
นํ ์ค... '+Math.round(
|
|
|
|
| 651 |
ctx.fillStyle='#000';
|
| 652 |
ctx.fillRect(0,0,1280,720);
|
|
|
|
| 653 |
var vc=getClipAt(t,'visual');
|
| 654 |
if(vc){{
|
| 655 |
var el=S.els[vc.mid];
|
| 656 |
if(el){{
|
| 657 |
-
if(vc.type==='video')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 658 |
try{{
|
| 659 |
var sw=el.videoWidth||el.naturalWidth||el.width||1280;
|
| 660 |
var sh=el.videoHeight||el.naturalHeight||el.height||720;
|
|
@@ -664,16 +680,25 @@ ctx.drawImage(el,(1280-dw)/2,(720-dh)/2,dw,dh);
|
|
| 664 |
}}catch(e){{}}
|
| 665 |
}}
|
| 666 |
}}
|
| 667 |
-
|
|
|
|
|
|
|
| 668 |
}}
|
| 669 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
}});
|
|
|
|
| 671 |
if(S.cancelled)return;
|
|
|
|
| 672 |
var webmBlob=new Blob(chunks,{{type:'video/webm'}});
|
| 673 |
if(webmBlob.size<1000){{document.getElementById('exportMsg').textContent='๋
นํ ์คํจ';return}}
|
|
|
|
| 674 |
document.getElementById('exportBar').style.width='100%';
|
| 675 |
-
document.getElementById('exportMsg').textContent='์๋ฃ! ('+Math.round(webmBlob.size/1024)+'
|
| 676 |
-
|
| 677 |
var downloadDiv=document.createElement('div');
|
| 678 |
downloadDiv.style.marginTop='10px';
|
| 679 |
var webmLink=document.createElement('a');
|
|
@@ -683,18 +708,20 @@ webmLink.className='btn btn-success';
|
|
| 683 |
webmLink.textContent='๐ฅ WebM ๋ค์ด๋ก๋';
|
| 684 |
webmLink.style.marginRight='5px';
|
| 685 |
downloadDiv.appendChild(webmLink);
|
| 686 |
-
|
| 687 |
var copyBtn=document.createElement('button');
|
| 688 |
copyBtn.className='btn btn-secondary';
|
| 689 |
copyBtn.textContent='๐ MP4๋ณํ์ฉ ๋ณต์ฌ';
|
| 690 |
copyBtn.onclick=async function(){{
|
|
|
|
| 691 |
var reader=new FileReader();
|
| 692 |
reader.onload=function(){{
|
| 693 |
var base64=reader.result.split(',')[1];
|
| 694 |
navigator.clipboard.writeText(base64).then(function(){{
|
| 695 |
-
|
|
|
|
| 696 |
}}).catch(function(){{
|
| 697 |
-
prompt('์๋ ๋ฐ์ดํฐ๋ฅผ ๋ณต์ฌํ์ธ์
|
| 698 |
}});
|
| 699 |
}};
|
| 700 |
reader.readAsDataURL(webmBlob);
|
|
@@ -703,6 +730,24 @@ downloadDiv.appendChild(copyBtn);
|
|
| 703 |
document.querySelector('.modal-box').appendChild(downloadDiv);
|
| 704 |
}}
|
| 705 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
function cancelExport(){{S.cancelled=true;document.getElementById('exportModal').style.display='none'}}
|
| 707 |
|
| 708 |
document.addEventListener('keydown',function(e){{
|
|
|
|
| 629 |
canvas.width=1280;canvas.height=720;
|
| 630 |
var ctx=canvas.getContext('2d');
|
| 631 |
var stream=canvas.captureStream(30);
|
| 632 |
+
|
| 633 |
+
// ๊ณ ํ์ง ์ค์
|
| 634 |
+
var opts={{mimeType:'video/webm;codecs=vp9',videoBitsPerSecond:8000000}};
|
| 635 |
+
if(!MediaRecorder.isTypeSupported(opts.mimeType)){{
|
| 636 |
+
opts={{mimeType:'video/webm;codecs=vp8',videoBitsPerSecond:8000000}};
|
| 637 |
+
}}
|
| 638 |
+
if(!MediaRecorder.isTypeSupported(opts.mimeType)){{
|
| 639 |
+
opts={{mimeType:'video/webm',videoBitsPerSecond:5000000}};
|
| 640 |
+
}}
|
| 641 |
+
|
| 642 |
var rec=new MediaRecorder(stream,opts);
|
| 643 |
var chunks=[];
|
| 644 |
rec.ondataavailable=function(e){{if(e.data.size>0)chunks.push(e.data)}};
|
| 645 |
+
|
| 646 |
document.getElementById('exportMsg').textContent='๋
นํ ์ค...';
|
| 647 |
rec.start(100);
|
| 648 |
+
|
| 649 |
var dur=S.dur;
|
| 650 |
+
var fps=30;
|
| 651 |
+
var totalFrames=Math.ceil(dur*fps);
|
| 652 |
+
var frameTime=1/fps;
|
| 653 |
+
|
| 654 |
+
// ํ๋ ์ ๋จ์๋ก ์ ํํ๊ฒ ๋ ๋๋ง
|
| 655 |
+
for(var frame=0;frame<totalFrames;frame++){{
|
| 656 |
+
if(S.cancelled)break;
|
| 657 |
+
|
| 658 |
+
var t=frame*frameTime;
|
| 659 |
+
document.getElementById('exportBar').style.width=(frame/totalFrames*100)+'%';
|
| 660 |
+
document.getElementById('exportMsg').textContent='๋
นํ ์ค... '+Math.round(frame/totalFrames*100)+'% ('+Math.floor(t)+'/'+Math.floor(dur)+'์ด)';
|
| 661 |
+
|
| 662 |
ctx.fillStyle='#000';
|
| 663 |
ctx.fillRect(0,0,1280,720);
|
| 664 |
+
|
| 665 |
var vc=getClipAt(t,'visual');
|
| 666 |
if(vc){{
|
| 667 |
var el=S.els[vc.mid];
|
| 668 |
if(el){{
|
| 669 |
+
if(vc.type==='video'){{
|
| 670 |
+
var clipT=t-vc.start+vc.ts;
|
| 671 |
+
// seekํ๊ณ ์๋ฃ๋ ๋๊น์ง ๊ธฐ๋ค๋ฆผ
|
| 672 |
+
await seekVideo(el,clipT);
|
| 673 |
+
}}
|
| 674 |
try{{
|
| 675 |
var sw=el.videoWidth||el.naturalWidth||el.width||1280;
|
| 676 |
var sh=el.videoHeight||el.naturalHeight||el.height||720;
|
|
|
|
| 680 |
}}catch(e){{}}
|
| 681 |
}}
|
| 682 |
}}
|
| 683 |
+
|
| 684 |
+
// ํ๋ ์ ๊ฐ๊ฒฉ๋งํผ ๋๊ธฐ (MediaRecorder๊ฐ ํ๋ ์ ์บก์ฒํ ์๊ฐ)
|
| 685 |
+
await new Promise(function(resolve){{setTimeout(resolve,33)}});
|
| 686 |
}}
|
| 687 |
+
|
| 688 |
+
// ๋
นํ ์ข
๋ฃ
|
| 689 |
+
await new Promise(function(resolve){{
|
| 690 |
+
rec.onstop=resolve;
|
| 691 |
+
rec.stop();
|
| 692 |
}});
|
| 693 |
+
|
| 694 |
if(S.cancelled)return;
|
| 695 |
+
|
| 696 |
var webmBlob=new Blob(chunks,{{type:'video/webm'}});
|
| 697 |
if(webmBlob.size<1000){{document.getElementById('exportMsg').textContent='๋
นํ ์คํจ';return}}
|
| 698 |
+
|
| 699 |
document.getElementById('exportBar').style.width='100%';
|
| 700 |
+
document.getElementById('exportMsg').textContent='์๋ฃ! ('+Math.round(webmBlob.size/1024/1024*10)/10+'MB) - ์๋์์ ๋ค์ด๋ก๋';
|
| 701 |
+
|
| 702 |
var downloadDiv=document.createElement('div');
|
| 703 |
downloadDiv.style.marginTop='10px';
|
| 704 |
var webmLink=document.createElement('a');
|
|
|
|
| 708 |
webmLink.textContent='๐ฅ WebM ๋ค์ด๋ก๋';
|
| 709 |
webmLink.style.marginRight='5px';
|
| 710 |
downloadDiv.appendChild(webmLink);
|
| 711 |
+
|
| 712 |
var copyBtn=document.createElement('button');
|
| 713 |
copyBtn.className='btn btn-secondary';
|
| 714 |
copyBtn.textContent='๐ MP4๋ณํ์ฉ ๋ณต์ฌ';
|
| 715 |
copyBtn.onclick=async function(){{
|
| 716 |
+
document.getElementById('exportMsg').textContent='๋ฐ์ดํฐ ์ค๋น ์ค...';
|
| 717 |
var reader=new FileReader();
|
| 718 |
reader.onload=function(){{
|
| 719 |
var base64=reader.result.split(',')[1];
|
| 720 |
navigator.clipboard.writeText(base64).then(function(){{
|
| 721 |
+
document.getElementById('exportMsg').textContent='๋ณต์ฌ ์๋ฃ! ์ ์
๋ ฅ๋์ ๋ถ์ฌ๋ฃ๊ธฐ';
|
| 722 |
+
alert('๋ณต์ฌ ์๋ฃ!\\n\\nGradio์ "WebM ๋ฐ์ดํฐ" ์
๋ ฅ๋์ ๋ถ์ฌ๋ฃ๊ธฐ(Ctrl+V) ํ\\n"MP4 ๋ณํ" ๋ฒํผ์ ํด๋ฆญํ์ธ์.');
|
| 723 |
}}).catch(function(){{
|
| 724 |
+
prompt('์๋ ๋ฐ์ดํฐ๋ฅผ ๋ณต์ฌํ์ธ์:', base64.substring(0,100)+'...');
|
| 725 |
}});
|
| 726 |
}};
|
| 727 |
reader.readAsDataURL(webmBlob);
|
|
|
|
| 730 |
document.querySelector('.modal-box').appendChild(downloadDiv);
|
| 731 |
}}
|
| 732 |
|
| 733 |
+
// ๋น๋์ค seek ์๋ฃ ๋๊ธฐ ํจ์
|
| 734 |
+
function seekVideo(video,time){{
|
| 735 |
+
return new Promise(function(resolve){{
|
| 736 |
+
if(Math.abs(video.currentTime-time)<0.05){{
|
| 737 |
+
resolve();
|
| 738 |
+
return;
|
| 739 |
+
}}
|
| 740 |
+
var onSeeked=function(){{
|
| 741 |
+
video.removeEventListener('seeked',onSeeked);
|
| 742 |
+
resolve();
|
| 743 |
+
}};
|
| 744 |
+
video.addEventListener('seeked',onSeeked);
|
| 745 |
+
video.currentTime=time;
|
| 746 |
+
// ํ์์์ (ํน์ seeked ์ด๋ฒคํธ๊ฐ ์ ์ค๋ฉด)
|
| 747 |
+
setTimeout(resolve,200);
|
| 748 |
+
}});
|
| 749 |
+
}}
|
| 750 |
+
|
| 751 |
function cancelExport(){{S.cancelled=true;document.getElementById('exportModal').style.display='none'}}
|
| 752 |
|
| 753 |
document.addEventListener('keydown',function(e){{
|