Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -56,28 +56,33 @@ def convert_video(video_file: File, quality, aspect_ratio, video_url):
|
|
56 |
# Set the output path to the temp directory
|
57 |
output_path = os.path.join(temp_dir, output_path)
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
from gradio import outputs
|
83 |
|
|
|
56 |
# Set the output path to the temp directory
|
57 |
output_path = os.path.join(temp_dir, output_path)
|
58 |
|
59 |
+
if os.path.exists(output_path):
|
60 |
+
# The file already exists, so we can just display it in the output viewer
|
61 |
+
gr.outputs.Video(output_path)
|
62 |
+
else:
|
63 |
+
# The file does not exist, so we need to convert it
|
64 |
+
ffmpeg_command = f"ffmpeg -i {video_file} -c:v libx264 -crf {quality} -f mp4 -aspect {aspect_ratio} {output_path}"
|
65 |
+
|
66 |
+
try:
|
67 |
+
subprocess.run(ffmpeg_command, shell=True, timeout=10)
|
68 |
+
except subprocess.TimeoutExpired:
|
69 |
+
print("ffmpeg timed out")
|
70 |
+
return None
|
71 |
+
except FileNotFoundError:
|
72 |
+
print("ffmpeg is not installed.")
|
73 |
+
return None
|
74 |
+
|
75 |
+
for i in range(10):
|
76 |
+
if os.path.exists(output_path):
|
77 |
+
break
|
78 |
+
else:
|
79 |
+
time.sleep(1)
|
80 |
+
|
81 |
+
# The file has now been converted, so we can display it in the output viewer
|
82 |
+
gr.outputs.Video(output_path)
|
83 |
+
|
84 |
+
# Add a button to download the file
|
85 |
+
gr.outputs.Button(label="Download", click=lambda: gr.download(output_path))
|
86 |
|
87 |
from gradio import outputs
|
88 |
|