Luongsosad commited on
Commit
c2a1189
·
verified ·
1 Parent(s): f45f269

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -12,7 +12,7 @@ import cv2
12
  os.environ["PATH"] += os.pathsep + r"D:\Downloads\ffmpeg-7.1.1-essentials_build\ffmpeg-7.1.1-essentials_build\bin"
13
 
14
  # Timeout cho toàn bộ thao tác (giây)
15
- TIMEOUT = 300 # 5 phút
16
 
17
  def wrap_text(text, max_width=1060, font_size=20):
18
  words = text.split()
@@ -108,12 +108,17 @@ def generate_video(image_files, script_input, duration_input, audio_file, fps=60
108
  return None, "❌ Số lượng ảnh, scripts và durations phải bằng nhau!"
109
 
110
  images = []
111
- for idx, img_file in enumerate(image_files):
112
  try:
113
- kind = filetype.guess(img_file.name)
 
114
  if not kind or kind.mime not in ['image/png', 'image/jpeg']:
115
  continue
116
- img = cv2.cvtColor(cv2.imread(img_file.name), cv2.COLOR_BGR2RGB)
 
 
 
 
117
  images.append(img)
118
  except Exception as e:
119
  continue
 
12
  os.environ["PATH"] += os.pathsep + r"D:\Downloads\ffmpeg-7.1.1-essentials_build\ffmpeg-7.1.1-essentials_build\bin"
13
 
14
  # Timeout cho toàn bộ thao tác (giây)
15
+ TIMEOUT = 300 # giây
16
 
17
  def wrap_text(text, max_width=1060, font_size=20):
18
  words = text.split()
 
108
  return None, "❌ Số lượng ảnh, scripts và durations phải bằng nhau!"
109
 
110
  images = []
111
+ for img_file in image_files:
112
  try:
113
+ file_bytes = img_file.read()
114
+ kind = filetype.guess(file_bytes)
115
  if not kind or kind.mime not in ['image/png', 'image/jpeg']:
116
  continue
117
+
118
+ # Đọc ảnh bằng numpy
119
+ nparr = np.frombuffer(file_bytes, np.uint8)
120
+ img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
121
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
122
  images.append(img)
123
  except Exception as e:
124
  continue