Update app.py
Browse files
app.py
CHANGED
|
@@ -38,13 +38,14 @@ from torchvision import transforms
|
|
| 38 |
|
| 39 |
|
| 40 |
# ββ moviepy import ββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 41 |
try:
|
| 42 |
-
# editor μλΈλͺ¨λμ΄ μμΌλ©΄ μ°μ μ¬μ©
|
| 43 |
from moviepy.editor import VideoFileClip, concatenate_videoclips
|
| 44 |
except ImportError:
|
| 45 |
from moviepy import VideoFileClip, concatenate_videoclips
|
| 46 |
|
| 47 |
-
# resize
|
|
|
|
| 48 |
try:
|
| 49 |
from moviepy.video.fx.resize import resize
|
| 50 |
except ImportError:
|
|
@@ -54,10 +55,45 @@ except ImportError:
|
|
| 54 |
try:
|
| 55 |
from moviepy.video.fx import resize
|
| 56 |
except ImportError:
|
| 57 |
-
# resize
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
from moviepy import (
|
| 63 |
ImageSequenceClip,
|
|
@@ -67,12 +103,14 @@ from moviepy import (
|
|
| 67 |
)
|
| 68 |
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
|
| 69 |
from moviepy.video.VideoClip import ColorClip
|
| 70 |
-
|
| 71 |
import time
|
| 72 |
from concurrent.futures import ThreadPoolExecutor
|
| 73 |
|
| 74 |
|
| 75 |
|
|
|
|
|
|
|
| 76 |
# ββ moviepy import ββββββββββββββββββββββββββββββββββββββββββ
|
| 77 |
# editor μλΈλͺ¨λμ΄ μλ κ²½μ° μ°μ μ¬μ©, μμΌλ©΄ μ΅μμ moviepy μ¬μ©
|
| 78 |
try:
|
|
@@ -621,17 +659,24 @@ def process_video_bg(vid, bg_type="μμ", bg_image=None, bg_video=None, color=
|
|
| 621 |
|
| 622 |
processed_frames = []
|
| 623 |
yield gr.update(visible=True), gr.update(visible=False), f"μ²λ¦¬ μμ... κ²½κ³Ό μκ°: 0μ΄"
|
| 624 |
-
|
| 625 |
if bg_type == "λΉλμ€":
|
| 626 |
background_video = VideoFileClip(bg_video)
|
| 627 |
if background_video.duration < video.duration:
|
| 628 |
if video_handling == "slow_down":
|
| 629 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 630 |
else: # video_handling == "loop"
|
| 631 |
background_video = concatenate_videoclips([background_video] * int(video.duration / background_video.duration + 1))
|
| 632 |
background_frames = list(background_video.iter_frames(fps=fps))
|
| 633 |
else:
|
| 634 |
background_frames = None
|
|
|
|
|
|
|
| 635 |
|
| 636 |
bg_frame_index = 0
|
| 637 |
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
# ββ moviepy import ββββββββββββββββββββββββββββββββββββββββββ
|
| 41 |
+
|
| 42 |
try:
|
|
|
|
| 43 |
from moviepy.editor import VideoFileClip, concatenate_videoclips
|
| 44 |
except ImportError:
|
| 45 |
from moviepy import VideoFileClip, concatenate_videoclips
|
| 46 |
|
| 47 |
+
# resize ν¨μ import μλ
|
| 48 |
+
resize = None
|
| 49 |
try:
|
| 50 |
from moviepy.video.fx.resize import resize
|
| 51 |
except ImportError:
|
|
|
|
| 55 |
try:
|
| 56 |
from moviepy.video.fx import resize
|
| 57 |
except ImportError:
|
| 58 |
+
pass # resizeλ₯Ό μ°Ύμ μ μμ
|
| 59 |
+
|
| 60 |
+
# resizeκ° μμΌλ©΄ λ체 ν¨μ μμ±
|
| 61 |
+
if resize is None:
|
| 62 |
+
def resize(clip, newsize=None, height=None, width=None):
|
| 63 |
+
"""Fallback resize function when moviepy resize is not available"""
|
| 64 |
+
if hasattr(clip, 'resize'):
|
| 65 |
+
if newsize:
|
| 66 |
+
return clip.resize(newsize)
|
| 67 |
+
elif height:
|
| 68 |
+
return clip.resize(height=height)
|
| 69 |
+
elif width:
|
| 70 |
+
return clip.resize(width=width)
|
| 71 |
+
return clip
|
| 72 |
+
|
| 73 |
+
# speedx ν¨μ import μλ
|
| 74 |
+
speedx = None
|
| 75 |
+
try:
|
| 76 |
+
from moviepy.video.fx.speedx import speedx
|
| 77 |
+
except ImportError:
|
| 78 |
+
try:
|
| 79 |
+
from moviepy.video.fx.all import speedx
|
| 80 |
+
except ImportError:
|
| 81 |
+
try:
|
| 82 |
+
from moviepy.video.fx import speedx
|
| 83 |
+
except ImportError:
|
| 84 |
+
pass # speedxλ₯Ό μ°Ύμ μ μμ
|
| 85 |
+
|
| 86 |
+
# speedxκ° μμΌλ©΄ λ체 ν¨μ μμ±
|
| 87 |
+
if speedx is None:
|
| 88 |
+
def speedx(clip, factor=1.0, final_duration=None):
|
| 89 |
+
"""Fallback speedx function"""
|
| 90 |
+
if hasattr(clip, 'fx') and hasattr(clip.fx, 'speedx'):
|
| 91 |
+
return clip.fx.speedx(factor, final_duration)
|
| 92 |
+
elif hasattr(clip, 'fl_time'):
|
| 93 |
+
return clip.fl_time(lambda t: t * factor)
|
| 94 |
+
else:
|
| 95 |
+
# μ΅νμ μλ¨: ν΄λ¦½ κ·Έλλ‘ λ°ν
|
| 96 |
+
return clip
|
| 97 |
|
| 98 |
from moviepy import (
|
| 99 |
ImageSequenceClip,
|
|
|
|
| 103 |
)
|
| 104 |
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
|
| 105 |
from moviepy.video.VideoClip import ColorClip
|
| 106 |
+
|
| 107 |
import time
|
| 108 |
from concurrent.futures import ThreadPoolExecutor
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
+
|
| 113 |
+
|
| 114 |
# ββ moviepy import ββββββββββββββββββββββββββββββββββββββββββ
|
| 115 |
# editor μλΈλͺ¨λμ΄ μλ κ²½μ° μ°μ μ¬μ©, μμΌλ©΄ μ΅μμ moviepy μ¬μ©
|
| 116 |
try:
|
|
|
|
| 659 |
|
| 660 |
processed_frames = []
|
| 661 |
yield gr.update(visible=True), gr.update(visible=False), f"μ²λ¦¬ μμ... κ²½κ³Ό μκ°: 0μ΄"
|
| 662 |
+
|
| 663 |
if bg_type == "λΉλμ€":
|
| 664 |
background_video = VideoFileClip(bg_video)
|
| 665 |
if background_video.duration < video.duration:
|
| 666 |
if video_handling == "slow_down":
|
| 667 |
+
# vfx.speedx λμ speedx ν¨μ μ§μ μ¬μ©
|
| 668 |
+
if speedx is not None:
|
| 669 |
+
background_video = speedx(background_video, factor=video.duration / background_video.duration)
|
| 670 |
+
else:
|
| 671 |
+
# speedxκ° μμΌλ©΄ λ°λ³΅μΌλ‘ λ체
|
| 672 |
+
background_video = concatenate_videoclips([background_video] * int(video.duration / background_video.duration + 1))
|
| 673 |
else: # video_handling == "loop"
|
| 674 |
background_video = concatenate_videoclips([background_video] * int(video.duration / background_video.duration + 1))
|
| 675 |
background_frames = list(background_video.iter_frames(fps=fps))
|
| 676 |
else:
|
| 677 |
background_frames = None
|
| 678 |
+
|
| 679 |
+
|
| 680 |
|
| 681 |
bg_frame_index = 0
|
| 682 |
|