File size: 1,619 Bytes
cdcf568
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
48
49
50
51
52
53
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))