video_converter / app.py
Akshayram1's picture
Update app.py
cdcf568 verified
import streamlit as st
import ffmpeg
import os
import time
st.title("πŸŽ₯ WebM to MP4 Converter with Progress")
uploaded_file = st.file_uploader("Upload a WebM file", type=["webm"])
if uploaded_file:
input_path = "temp_input.webm"
output_path = "converted_output.mp4"
with open(input_path, "wb") as f:
f.write(uploaded_file.read())
st.write("File uploaded successfully! Click the button below to convert.")
if st.button("Convert to MP4"):
progress_bar = st.progress(0)
status_text = st.empty()
try:
# Simulating progress
for percent in range(0, 101, 10):
time.sleep(0.3) # Simulate processing time
progress_bar.progress(percent)
status_text.text(f"Converting... {percent}%")
# Actual conversion
(
ffmpeg
.input(input_path)
.output(output_path, vcodec="libx264", acodec="aac")
.run(overwrite_output=True)
)
progress_bar.progress(100)
status_text.text("Conversion complete!")
st.success("Conversion successful! Download your MP4 file below.")
st.video(output_path)
with open(output_path, "rb") as f:
st.download_button("Download MP4", f, file_name="converted.mp4", mime="video/mp4")
os.remove(input_path)
os.remove(output_path)
except ffmpeg.Error as e:
st.error("Error during conversion!")
st.text(str(e))