Update app.py
Browse files
app.py
CHANGED
@@ -37,7 +37,6 @@ def generate_thumbnail(video_clip, time_point):
|
|
37 |
return thumbnail_img
|
38 |
except Exception as e:
|
39 |
add_log(f"[ERROR] ์ธ๋ค์ผ ์์ฑ ์คํจ: {e}")
|
40 |
-
# time_point๊ฐ ๋ฒ์๋ฅผ ๋ฒ์ด๋๋ฉด ์ฒซ ํ๋ ์์ ๋ฐํ
|
41 |
frame = video_clip.get_frame(0)
|
42 |
thumbnail_img = Image.fromarray(frame)
|
43 |
return thumbnail_img
|
@@ -93,20 +92,19 @@ def process_video(video,
|
|
93 |
add_log(f"[LOG 7] ํด์๋ {resolution_factor*100:.1f}%๋ก ์กฐ์ ์ค...")
|
94 |
clip = clip.resize(resolution_factor)
|
95 |
|
96 |
-
# ์ฌ์์๋ ์กฐ์ : speedx๋ฅผ ์ ์ฉํ๋ฉด clip.duration
|
97 |
if abs(speed_factor - 1.0) > 1e-3:
|
98 |
add_log(f"[LOG 8] ์ฌ์์๋ {speed_factor}๋ฐฐ๋ก ์กฐ์ ์ค...")
|
99 |
clip = clip.fx(mp.vfx.speedx, speed_factor)
|
100 |
|
101 |
-
# FPS ์กฐ์ :
|
102 |
original_fps = clip.fps
|
103 |
target_fps = original_fps * speed_factor * frame_rate_factor
|
104 |
add_log(f"[LOG 9] ์ต์ข
์ถ๋ ฅ FPS: {target_fps:.2f} (์๋ณธ FPS: {original_fps})")
|
105 |
clip = clip.set_fps(target_fps)
|
106 |
|
107 |
-
# ๋ฐ๋ณต ํ์: 0์ด๋ฉด ๋ฌดํ๋ฐ๋ณต, 1~10๋ฉด ํด๋น ํ์๋งํผ ๋ฐ๋ณต (
|
108 |
add_log(f"[LOG 10] GIF ๋ฐ๋ณต ํ์ ์ค์ : {repeat_count} (0์ด๋ฉด ๋ฌดํ๋ฐ๋ณต)")
|
109 |
-
# ๋ฐ๋ณต ๊ธฐ๋ฅ์ GIF์ ๋ฉํ๋ฐ์ดํฐ(loop)๋ก ์ค์ ํ๋ฏ๋ก ํด๋ฆฝ์ ๋ฐ๋ณต ์ฐ๊ฒฐํ์ง ์์ต๋๋ค.
|
110 |
final_clip = clip
|
111 |
|
112 |
add_log("[LOG 11] GIF ์์ฑ ์ค...")
|
@@ -120,7 +118,7 @@ def process_video(video,
|
|
120 |
add_log(f"[ERROR] GIF ์์ฑ ์คํจ: {e}")
|
121 |
return None, None, "\n".join(global_logs)
|
122 |
|
123 |
-
# ๋ฏธ๋ฆฌ๋ณด๊ธฐ: ์์ฑ๋ GIF ํ์ผ ๊ฒฝ๋ก๋ฅผ ๊ทธ๋๋ก ๋ฐํํ๋ฉด gr.
|
124 |
return output_filename, output_filename, "\n".join(global_logs)
|
125 |
|
126 |
def update_thumbnails(video, start_time_str, end_time_str):
|
@@ -168,14 +166,14 @@ with gr.Blocks() as demo:
|
|
168 |
start_thumb_output = gr.Image(label="์์ ์ธ๋ค์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
169 |
end_thumb_output = gr.Image(label="์ข
๋ฃ ์ธ๋ค์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
170 |
# ํด์๋, ํ๋ ์ ๋ ์ดํธ, ์ฌ์ ์๋, ๋ฐ๋ณต ํ์ ์กฐ์
|
171 |
-
# โ ํ์ผ ์ฉ๋ ์ ๊ฐ์ ์ํด ๊ธฐ๋ณธ ํด์๋์ ํ๋ ์ ๋ ์ดํธ ๋ฐฐ์จ์ 0.5๋ก ์ค์
|
172 |
resolution_slider = gr.Slider(label="ํด์๋ ๋น์จ ์กฐ์ (0.1 ~ 1.0)", minimum=0.1, maximum=1.0, step=0.1, value=0.5)
|
173 |
fps_slider = gr.Slider(label="ํ๋ ์ ๋ ์ดํธ ๋ฐฐ์จ ์กฐ์ (0.1 ~ 2.0)", minimum=0.1, maximum=2.0, step=0.1, value=0.5)
|
174 |
speed_slider = gr.Slider(label="์ฌ์ ์๋ ์กฐ์ (0.5 ~ 2.0)", minimum=0.5, maximum=2.0, step=0.1, value=1.0)
|
175 |
repeat_slider = gr.Slider(label="GIF ๋ฐ๋ณต ํ์ (0: ๋ฌดํ๋ฐ๋ณต, 1~10: ๋ฐ๋ณต ํ์)", minimum=0, maximum=10, step=1, value=0)
|
176 |
# GIF ์์ฑ ๋ฒํผ ๋ฐ ๊ฒฐ๊ณผ ์ถ๋ ฅ
|
177 |
generate_button = gr.Button("GIF ์์ฑํ๊ธฐ")
|
178 |
-
|
|
|
179 |
download_output = gr.File(label="GIF ๋ค์ด๋ก๋ ๋งํฌ")
|
180 |
logs_output = gr.Textbox(label="๋ก๊ทธ ์ถ๋ ฅ", lines=10)
|
181 |
|
|
|
37 |
return thumbnail_img
|
38 |
except Exception as e:
|
39 |
add_log(f"[ERROR] ์ธ๋ค์ผ ์์ฑ ์คํจ: {e}")
|
|
|
40 |
frame = video_clip.get_frame(0)
|
41 |
thumbnail_img = Image.fromarray(frame)
|
42 |
return thumbnail_img
|
|
|
92 |
add_log(f"[LOG 7] ํด์๋ {resolution_factor*100:.1f}%๋ก ์กฐ์ ์ค...")
|
93 |
clip = clip.resize(resolution_factor)
|
94 |
|
95 |
+
# ์ฌ์์๋ ์กฐ์ : speedx๋ฅผ ์ ์ฉํ๋ฉด clip.duration์ด ์ค์ด๋ค์ง๋ง fps๋ ๊ทธ๋๋ก ์ ์ง๋จ.
|
96 |
if abs(speed_factor - 1.0) > 1e-3:
|
97 |
add_log(f"[LOG 8] ์ฌ์์๋ {speed_factor}๋ฐฐ๋ก ์กฐ์ ์ค...")
|
98 |
clip = clip.fx(mp.vfx.speedx, speed_factor)
|
99 |
|
100 |
+
# FPS ์กฐ์ : ์ต์ข
์ถ๋ ฅ FPS์ speed_factor์ frame_rate_factor๋ฅผ ๋ฐ์
|
101 |
original_fps = clip.fps
|
102 |
target_fps = original_fps * speed_factor * frame_rate_factor
|
103 |
add_log(f"[LOG 9] ์ต์ข
์ถ๋ ฅ FPS: {target_fps:.2f} (์๋ณธ FPS: {original_fps})")
|
104 |
clip = clip.set_fps(target_fps)
|
105 |
|
106 |
+
# ๋ฐ๋ณต ํ์: 0์ด๋ฉด ๋ฌดํ๋ฐ๋ณต, 1~10๋ฉด ํด๋น ํ์๋งํผ ๋ฐ๋ณต (GIF์ loop ๋ฉํ๋ฐ์ดํฐ ์ฌ์ฉ)
|
107 |
add_log(f"[LOG 10] GIF ๋ฐ๋ณต ํ์ ์ค์ : {repeat_count} (0์ด๋ฉด ๋ฌดํ๋ฐ๋ณต)")
|
|
|
108 |
final_clip = clip
|
109 |
|
110 |
add_log("[LOG 11] GIF ์์ฑ ์ค...")
|
|
|
118 |
add_log(f"[ERROR] GIF ์์ฑ ์คํจ: {e}")
|
119 |
return None, None, "\n".join(global_logs)
|
120 |
|
121 |
+
# ๋ฏธ๋ฆฌ๋ณด๊ธฐ: ์์ฑ๋ GIF ํ์ผ ๊ฒฝ๋ก๋ฅผ ๊ทธ๋๋ก ๋ฐํํ๋ฉด gr.Image์์ ์ ๋๋ฉ์ด์
๋ฏธ๋ฆฌ๋ณด๊ธฐ๊ฐ ๊ฐ๋ฅํฉ๋๋ค.
|
122 |
return output_filename, output_filename, "\n".join(global_logs)
|
123 |
|
124 |
def update_thumbnails(video, start_time_str, end_time_str):
|
|
|
166 |
start_thumb_output = gr.Image(label="์์ ์ธ๋ค์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
167 |
end_thumb_output = gr.Image(label="์ข
๋ฃ ์ธ๋ค์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
168 |
# ํด์๋, ํ๋ ์ ๋ ์ดํธ, ์ฌ์ ์๋, ๋ฐ๋ณต ํ์ ์กฐ์
|
|
|
169 |
resolution_slider = gr.Slider(label="ํด์๋ ๋น์จ ์กฐ์ (0.1 ~ 1.0)", minimum=0.1, maximum=1.0, step=0.1, value=0.5)
|
170 |
fps_slider = gr.Slider(label="ํ๋ ์ ๋ ์ดํธ ๋ฐฐ์จ ์กฐ์ (0.1 ~ 2.0)", minimum=0.1, maximum=2.0, step=0.1, value=0.5)
|
171 |
speed_slider = gr.Slider(label="์ฌ์ ์๋ ์กฐ์ (0.5 ~ 2.0)", minimum=0.5, maximum=2.0, step=0.1, value=1.0)
|
172 |
repeat_slider = gr.Slider(label="GIF ๋ฐ๋ณต ํ์ (0: ๋ฌดํ๋ฐ๋ณต, 1~10: ๋ฐ๋ณต ํ์)", minimum=0, maximum=10, step=1, value=0)
|
173 |
# GIF ์์ฑ ๋ฒํผ ๋ฐ ๊ฒฐ๊ณผ ์ถ๋ ฅ
|
174 |
generate_button = gr.Button("GIF ์์ฑํ๊ธฐ")
|
175 |
+
# ๋ฏธ๋ฆฌ๋ณด๊ธฐ: gr.Image๋ฅผ ์ฌ์ฉํ์ฌ ์ ๋๋ฉ์ด์
GIF ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
176 |
+
gif_preview_output = gr.Image(label="์์ฑ๋ GIF ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
177 |
download_output = gr.File(label="GIF ๋ค์ด๋ก๋ ๋งํฌ")
|
178 |
logs_output = gr.Textbox(label="๋ก๊ทธ ์ถ๋ ฅ", lines=10)
|
179 |
|