Smriti77 commited on
Commit
51c5681
·
verified ·
1 Parent(s): 83e4f6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -202,26 +202,18 @@ def retrieve_video(text, debug=False, similarity_threshold=0.7):
202
  return None
203
 
204
  def merge_videos(video_list, output_path="temp/output.mp4"):
205
-
206
- os.makedirs("temp", exist_ok=True)
207
-
208
  if not video_list:
209
  return None
210
-
211
  if len(video_list) == 1:
212
- os.system(f"cp '{video_list[0]}' '{output_path}'")
213
- return output_path
214
-
215
- for path in video_list:
216
- if not os.path.exists(path):
217
- print(f"Warning: Video path does not exist: {path}")
218
- return None
219
-
220
- with open("temp/video_list.txt", "w") as f:
221
- for path in video_list:
222
- f.write(f"file '{path}'\n")
223
 
224
- command = f"ffmpeg -f concat -safe 0 -i temp/video_list.txt -c copy {output_path} -y"
225
  process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
226
 
227
  if process.returncode != 0:
@@ -231,6 +223,7 @@ def merge_videos(video_list, output_path="temp/output.mp4"):
231
  return output_path
232
 
233
 
 
234
  def save_video(video_path, output_path="temp/display_output.mp4"):
235
 
236
  os.makedirs("temp", exist_ok=True)
 
202
  return None
203
 
204
  def merge_videos(video_list, output_path="temp/output.mp4"):
 
 
 
205
  if not video_list:
206
  return None
207
+
208
  if len(video_list) == 1:
209
+ return video_list[0] # No need to merge if only one video
210
+
211
+ input_files = ' '.join([f"-i {path}" for path in video_list])
212
+ filter_complex = "".join([f"[{i}:v:0] [{i}:a:0] " for i in range(len(video_list))])
213
+ filter_complex += f"concat=n={len(video_list)}:v=1:a=1 [v] [a]"
214
+
215
+ command = f"ffmpeg {input_files} -filter_complex \"{filter_complex}\" -map \"[v]\" -map \"[a]\" {output_path} -y"
 
 
 
 
216
 
 
217
  process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
218
 
219
  if process.returncode != 0:
 
223
  return output_path
224
 
225
 
226
+
227
  def save_video(video_path, output_path="temp/display_output.mp4"):
228
 
229
  os.makedirs("temp", exist_ok=True)