Update src/streamlit_app.py
Browse files- src/streamlit_app.py +33 -57
src/streamlit_app.py
CHANGED
|
@@ -1,71 +1,47 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
import m3u8
|
| 4 |
import os
|
| 5 |
import time
|
| 6 |
-
from moviepy.editor import concatenate_videoclips, VideoFileClip
|
| 7 |
|
| 8 |
-
st.title("HLS to MP4 Downloader")
|
| 9 |
|
| 10 |
url = st.text_input("Enter HLS stream URL (.m3u8):")
|
|
|
|
| 11 |
|
| 12 |
-
if st.button("Download
|
| 13 |
if not url:
|
| 14 |
st.error("Please enter a valid URL.")
|
| 15 |
else:
|
| 16 |
try:
|
| 17 |
start_time = time.time()
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
final_clip.write_videofile(output_file, codec="libx264", audio_codec="aac")
|
| 48 |
-
final_clip.close()
|
| 49 |
-
|
| 50 |
-
# Clean up TS files
|
| 51 |
-
for f in ts_files:
|
| 52 |
-
os.remove(f)
|
| 53 |
-
|
| 54 |
-
end_time = time.time()
|
| 55 |
-
duration = end_time - start_time
|
| 56 |
-
file_size_mb = os.path.getsize(output_file) / (1024 * 1024)
|
| 57 |
-
|
| 58 |
-
metadata = {
|
| 59 |
-
"File Name": output_file,
|
| 60 |
-
"File Path": os.path.abspath(output_file),
|
| 61 |
-
"File Size (MB)": round(file_size_mb, 2),
|
| 62 |
-
"Download Time (s)": round(duration, 2),
|
| 63 |
-
"URL": url,
|
| 64 |
-
"Total Segments": len(segments)
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
st.success(f"Downloaded and merged to '{output_file}' successfully!")
|
| 68 |
-
st.json(metadata)
|
| 69 |
-
|
| 70 |
except Exception as e:
|
| 71 |
st.error(f"Error: {e}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import subprocess
|
|
|
|
| 3 |
import os
|
| 4 |
import time
|
|
|
|
| 5 |
|
| 6 |
+
st.title("HLS to MP4 Downloader (FFmpeg)")
|
| 7 |
|
| 8 |
url = st.text_input("Enter HLS stream URL (.m3u8):")
|
| 9 |
+
output_file = st.text_input("Output MP4 filename:", "output.mp4")
|
| 10 |
|
| 11 |
+
if st.button("Download"):
|
| 12 |
if not url:
|
| 13 |
st.error("Please enter a valid URL.")
|
| 14 |
else:
|
| 15 |
try:
|
| 16 |
start_time = time.time()
|
| 17 |
+
|
| 18 |
+
# Run FFmpeg command
|
| 19 |
+
command = [
|
| 20 |
+
"ffmpeg",
|
| 21 |
+
"-y", # Overwrite output if exists
|
| 22 |
+
"-i", url, # Input HLS URL
|
| 23 |
+
"-c", "copy", # Copy codecs without re-encoding
|
| 24 |
+
output_file
|
| 25 |
+
]
|
| 26 |
+
st.info("Downloading stream using FFmpeg...")
|
| 27 |
+
subprocess.run(command, check=True)
|
| 28 |
+
|
| 29 |
+
end_time = time.time()
|
| 30 |
+
duration = end_time - start_time
|
| 31 |
+
file_size_mb = os.path.getsize(output_file) / (1024 * 1024)
|
| 32 |
+
|
| 33 |
+
metadata = {
|
| 34 |
+
"File Name": output_file,
|
| 35 |
+
"File Path": os.path.abspath(output_file),
|
| 36 |
+
"File Size (MB)": round(file_size_mb, 2),
|
| 37 |
+
"Download Time (s)": round(duration, 2),
|
| 38 |
+
"URL": url
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
st.success(f"Downloaded successfully to '{output_file}'!")
|
| 42 |
+
st.json(metadata)
|
| 43 |
+
|
| 44 |
+
except subprocess.CalledProcessError as e:
|
| 45 |
+
st.error(f"FFmpeg failed: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
except Exception as e:
|
| 47 |
st.error(f"Error: {e}")
|