ginipick commited on
Commit
ce62711
ยท
verified ยท
1 Parent(s): 5ce8bf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -5,16 +5,24 @@ import cv2
5
  import os
6
 
7
  def image_to_video(image):
8
- image_array = np.array(image.convert('RGB')) # RGB๋กœ ๋ณ€ํ™˜
 
 
 
 
 
 
9
 
10
- # MP4 ๋Œ€์‹  AVI ํŒŒ์ผ๋กœ ์ €์žฅ์„ ์‹œ๋„ํ•ด ๋ณด์„ธ์š”.
11
- output_path = '/mnt/data/output_video.avi'
12
  height, width, _ = image_array.shape
13
  size = (width, height)
14
- fourcc = cv2.VideoWriter_fourcc(*'mp4v') # 'mp4v' ์ฝ”๋ฑ ๋ช…์‹œ์  ์‚ฌ์šฉ
15
 
16
  video = cv2.VideoWriter(output_path, fourcc, 30, size) # ํ”„๋ ˆ์ž„ ์†๋„๋ฅผ 30์œผ๋กœ ์„ค์ •
17
 
 
 
 
 
18
  for _ in range(150): # ์ด 150 ํ”„๋ ˆ์ž„ ์ƒ์„ฑ
19
  video.write(image_array)
20
 
 
5
  import os
6
 
7
  def image_to_video(image):
8
+ image_array = np.array(image.convert('RGB')) # ์ด๋ฏธ์ง€๋ฅผ RGB๋กœ ๋ณ€ํ™˜
9
+
10
+ # ํŒŒ์ผ ๊ฒฝ๋กœ ์ง€์ •
11
+ output_path = 'output_video.mp4' # ๊ฒฝ๋กœ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ„์†Œํ™”๋œ ๊ฒฝ๋กœ ์‚ฌ์šฉ
12
+ if not os.path.exists('output'): # 'output' ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์—†์œผ๋ฉด ์ƒ์„ฑ
13
+ os.makedirs('output')
14
+ output_path = os.path.join('output', output_path) # ํŒŒ์ผ ๊ฒฝ๋กœ ์™„์„ฑ
15
 
 
 
16
  height, width, _ = image_array.shape
17
  size = (width, height)
18
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v') # 'mp4v' ์ฝ”๋ฑ ์‚ฌ์šฉ
19
 
20
  video = cv2.VideoWriter(output_path, fourcc, 30, size) # ํ”„๋ ˆ์ž„ ์†๋„๋ฅผ 30์œผ๋กœ ์„ค์ •
21
 
22
+ if not video.isOpened():
23
+ print("๋น„๋””์˜ค ์ž‘์„ฑ์ž๊ฐ€ ํŒŒ์ผ์„ ์—ด์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.")
24
+ return None
25
+
26
  for _ in range(150): # ์ด 150 ํ”„๋ ˆ์ž„ ์ƒ์„ฑ
27
  video.write(image_array)
28