Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,15 +72,30 @@ def convert_video(video_file: File, quality, aspect_ratio):
|
|
| 72 |
print("File does not exist.")
|
| 73 |
|
| 74 |
# Create a temporary file to store the download link
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
|
| 79 |
# Add a button to download the file
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
from gradio import outputs
|
| 85 |
|
| 86 |
-
gr.Interface(convert_video, inputs=[video_file, quality], outputs=[outputs.Video()]).launch(share=False)
|
|
|
|
| 72 |
print("File does not exist.")
|
| 73 |
|
| 74 |
# Create a temporary file to store the download link
|
| 75 |
+
with tempfile.NamedTemporaryFile(delete=False) as f:
|
| 76 |
+
f.write(output_path.encode())
|
| 77 |
+
download_link = f.name
|
| 78 |
|
| 79 |
# Add a button to download the file
|
| 80 |
+
gr.components.HTML("""
|
| 81 |
+
<a href="{}" download="downloaded_file.mp4">Download</a>
|
| 82 |
+
""".format(download_link))
|
| 83 |
+
|
| 84 |
+
# Convert the video file to M3U8 format
|
| 85 |
+
m3u8_file = Path(video_file.stem + ".m3u8")
|
| 86 |
+
ffmpeg_command = f"ffmpeg -i {video_file} -c:v libx264 -crf {quality} -f hls -segment_time 10 {m3u8_file}"
|
| 87 |
+
|
| 88 |
+
try:
|
| 89 |
+
subprocess.run(ffmpeg_command, shell=True, timeout=10)
|
| 90 |
+
except subprocess.TimeoutExpired:
|
| 91 |
+
print("ffmpeg timed out")
|
| 92 |
+
return None
|
| 93 |
+
except FileNotFoundError:
|
| 94 |
+
print("ffmpeg is not installed.")
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
return m3u8_file
|
| 98 |
|
| 99 |
from gradio import outputs
|
| 100 |
|
| 101 |
+
gr.Interface(convert_video, inputs=[video_file, quality], outputs=[outputs.Video(), outputs.File()]).launch(share=False)
|