Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import ffmpeg
|
| 3 |
+
import os
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
st.title("🎥 WebM to MP4 Converter with Progress")
|
| 7 |
+
|
| 8 |
+
uploaded_file = st.file_uploader("Upload a WebM file", type=["webm"])
|
| 9 |
+
|
| 10 |
+
if uploaded_file:
|
| 11 |
+
input_path = "temp_input.webm"
|
| 12 |
+
output_path = "converted_output.mp4"
|
| 13 |
+
|
| 14 |
+
with open(input_path, "wb") as f:
|
| 15 |
+
f.write(uploaded_file.read())
|
| 16 |
+
|
| 17 |
+
st.write("File uploaded successfully! Click the button below to convert.")
|
| 18 |
+
|
| 19 |
+
if st.button("Convert to MP4"):
|
| 20 |
+
progress_bar = st.progress(0)
|
| 21 |
+
status_text = st.empty()
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
# Simulating progress
|
| 25 |
+
for percent in range(0, 101, 10):
|
| 26 |
+
time.sleep(0.3) # Simulate processing time
|
| 27 |
+
progress_bar.progress(percent)
|
| 28 |
+
status_text.text(f"Converting... {percent}%")
|
| 29 |
+
|
| 30 |
+
# Actual conversion
|
| 31 |
+
(
|
| 32 |
+
ffmpeg
|
| 33 |
+
.input(input_path)
|
| 34 |
+
.output(output_path, vcodec="libx264", acodec="aac")
|
| 35 |
+
.run(overwrite_output=True)
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
progress_bar.progress(100)
|
| 39 |
+
status_text.text("Conversion complete!")
|
| 40 |
+
|
| 41 |
+
st.success("Conversion successful! Download your MP4 file below.")
|
| 42 |
+
st.video(output_path)
|
| 43 |
+
|
| 44 |
+
with open(output_path, "rb") as f:
|
| 45 |
+
st.download_button("Download MP4", f, file_name="converted.mp4", mime="video/mp4")
|
| 46 |
+
|
| 47 |
+
os.remove(input_path)
|
| 48 |
+
os.remove(output_path)
|
| 49 |
+
|
| 50 |
+
except ffmpeg.Error as e:
|
| 51 |
+
st.error("Error during conversion!")
|
| 52 |
+
st.text(str(e))
|