Kims12 commited on
Commit
4abd773
ยท
verified ยท
1 Parent(s): 3005b66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
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๊ฐ€ ์ค„์–ด๋“ค์ง€๋งŒ fps๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€๋จ.
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 ์กฐ์ ˆ: ์†๋„ ์กฐ์ ˆ ๋ณด์ •์„ ์œ„ํ•ด speed_factor๋ฅผ ๋ฐ˜์˜
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๋ฉด ํ•ด๋‹น ํšŸ์ˆ˜๋งŒํผ ๋ฐ˜๋ณต (๊ธฐ๋ณธ๊ฐ’์€ 0)
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.Gif ์ปดํฌ๋„ŒํŠธ์—์„œ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
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
- gif_preview_output = gr.Gif(label="์™„์„ฑ๋œ GIF ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
 
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