Update app.py
Browse files
app.py
CHANGED
@@ -202,17 +202,50 @@ 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 |
if not video_list:
|
206 |
return None
|
207 |
-
|
208 |
if len(video_list) == 1:
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
218 |
|
@@ -223,7 +256,6 @@ def merge_videos(video_list, output_path="temp/output.mp4"):
|
|
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)
|
|
|
202 |
return None
|
203 |
|
204 |
def merge_videos(video_list, output_path="temp/output.mp4"):
|
205 |
+
# Create temp directory
|
206 |
+
os.makedirs("temp", exist_ok=True)
|
207 |
+
|
208 |
if not video_list:
|
209 |
return None
|
210 |
+
|
211 |
if len(video_list) == 1:
|
212 |
+
# Use a try-except block to handle potential errors
|
213 |
+
try:
|
214 |
+
import shutil
|
215 |
+
shutil.copy(video_list[0], output_path)
|
216 |
+
return output_path
|
217 |
+
except Exception as e:
|
218 |
+
print(f"Error copying single video: {e}")
|
219 |
+
return None
|
220 |
+
|
221 |
+
# Create a new list with verified paths
|
222 |
+
verified_paths = []
|
223 |
+
for path in video_list:
|
224 |
+
if os.path.exists(path):
|
225 |
+
verified_paths.append(path)
|
226 |
+
else:
|
227 |
+
print(f"Warning: Video path does not exist: {path}")
|
228 |
+
|
229 |
+
if not verified_paths:
|
230 |
+
print("No valid video paths found")
|
231 |
+
return None
|
232 |
+
|
233 |
+
# Create the video list file
|
234 |
+
list_path = "temp/video_list.txt"
|
235 |
+
with open(list_path, "w") as f:
|
236 |
+
for path in verified_paths:
|
237 |
+
# Use absolute paths to avoid any directory confusion
|
238 |
+
abs_path = os.path.abspath(path)
|
239 |
+
f.write(f"file '{abs_path}'\n")
|
240 |
+
|
241 |
+
# Run ffmpeg with absolute paths
|
242 |
+
abs_output = os.path.abspath(output_path)
|
243 |
+
abs_list = os.path.abspath(list_path)
|
244 |
+
|
245 |
+
command = f"ffmpeg -f concat -safe 0 -i '{abs_list}' -c copy '{abs_output}' -y"
|
246 |
+
|
247 |
+
# Print the command for debugging
|
248 |
+
print(f"Running command: {command}")
|
249 |
|
250 |
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
251 |
|
|
|
256 |
return output_path
|
257 |
|
258 |
|
|
|
259 |
def save_video(video_path, output_path="temp/display_output.mp4"):
|
260 |
|
261 |
os.makedirs("temp", exist_ok=True)
|