File size: 5,589 Bytes
9aad68e
777d015
 
9aad68e
 
 
777d015
 
 
9aad68e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
777d015
9aad68e
 
 
777d015
 
9aad68e
 
777d015
 
 
 
 
 
9aad68e
 
777d015
 
9aad68e
 
 
 
777d015
 
 
 
 
 
9aad68e
 
777d015
 
9aad68e
 
 
 
 
 
777d015
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9aad68e
 
777d015
9aad68e
 
 
 
 
 
 
 
 
 
 
 
 
777d015
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import streamlit as st
from moviepy.editor import VideoFileClip, concatenate_videoclips, TextClip, CompositeVideoClip, AudioFileClip
from moviepy.video.fx.all import crop, resize, mirror_x
import os

# Streamlit app
st.set_page_config(page_title="🎥 Pro Video Editor", page_icon="🎬", layout="wide")
st.title("🎥 Pro Video Editor")
st.write("Edit your videos like a pro with this easy-to-use tool!")

# Upload video
uploaded_file = st.file_uploader("Upload a video:", type=["mp4", "avi", "mov"])

if uploaded_file is not None:
    # Save uploaded file
    with open("input_video.mp4", "wb") as f:
        f.write(uploaded_file.getbuffer())
    
    # Load video
    video = VideoFileClip("input_video.mp4")

    # Sidebar for editing options
    st.sidebar.header("Editing Options")
    task = st.sidebar.selectbox("Select a task:", [
        "Trim Video", "Crop Video", "Add Text", "Add Music", "Resize Video", "Export Video"
    ])

    if task == "Trim Video":
        st.header("✂️ Trim Video")
        st.write("Select the start and end time to trim your video.")
        start_time = st.number_input("Start Time (seconds):", min_value=0, max_value=int(video.duration))
        end_time = st.number_input("End Time (seconds):", min_value=0, max_value=int(video.duration))
        if st.button("Trim Video"):
            with st.spinner("Trimming video..."):
                trimmed_video = video.subclip(start_time, end_time)
                trimmed_video.write_videofile("trimmed_video.mp4")
                st.success("Video trimmed successfully!")
                st.video("trimmed_video.mp4")

    elif task == "Crop Video":
        st.header("🌾 Crop Video")
        st.write("Crop your video by selecting the area.")
        x1 = st.number_input("X1:", min_value=0, max_value=video.size[0])
        y1 = st.number_input("Y1:", min_value=0, max_value=video.size[1])
        x2 = st.number_input("X2:", min_value=0, max_value=video.size[0])
        y2 = st.number_input("Y2:", min_value=0, max_value=video.size[1])
        if st.button("Crop Video"):
            with st.spinner("Cropping video..."):
                cropped_video = crop(video, x1=x1, y1=y1, x2=x2, y2=y2)
                cropped_video.write_videofile("cropped_video.mp4")
                st.success("Video cropped successfully!")
                st.video("cropped_video.mp4")

    elif task == "Add Text":
        st.header("✍️ Add Text")
        st.write("Add text to your video with custom font size, color, and position.")
        text = st.text_input("Enter text:")
        fontsize = st.number_input("Font Size:", min_value=10, max_value=100, value=50)
        color = st.color_picker("Text Color:", "#FFFFFF")
        position_x = st.number_input("Position X:", min_value=0, max_value=video.size[0])
        position_y = st.number_input("Position Y:", min_value=0, max_value=video.size[1])
        if st.button("Add Text"):
            with st.spinner("Adding text..."):
                text_clip = TextClip(text, fontsize=fontsize, color=color)
                text_clip = text_clip.set_position((position_x, position_y)).set_duration(video.duration)
                final_video = CompositeVideoClip([video, text_clip])
                final_video.write_videofile("text_video.mp4")
                st.success("Text added successfully!")
                st.video("text_video.mp4")

    elif task == "Add Music":
        st.header("🎵 Add Music")
        st.write("Add background music to your video.")
        music_file = st.file_uploader("Upload a music file:", type=["mp3", "wav"])
        if music_file and st.button("Add Music"):
            with st.spinner("Adding music..."):
                with open("background_music.mp3", "wb") as f:
                    f.write(music_file.getbuffer())
                audio_clip = AudioFileClip("background_music.mp3")
                final_video = video.set_audio(audio_clip)
                final_video.write_videofile("music_video.mp4")
                st.success("Music added successfully!")
                st.video("music_video.mp4")

    elif task == "Resize Video":
        st.header("📏 Resize Video")
        st.write("Resize your video to a specific width and height.")
        width = st.number_input("Width:", min_value=100, max_value=1920, value=video.size[0])
        height = st.number_input("Height:", min_value=100, max_value=1080, value=video.size[1])
        if st.button("Resize Video"):
            with st.spinner("Resizing video..."):
                resized_video = resize(video, width=width, height=height)
                resized_video.write_videofile("resized_video.mp4")
                st.success("Video resized successfully!")
                st.video("resized_video.mp4")

    elif task == "Export Video":
        st.header("📤 Export Video")
        st.write("Your video is ready to download!")
        st.video("input_video.mp4")
        with open("input_video.mp4", "rb") as f:
            st.download_button("Download Video", f, file_name="edited_video.mp4")

# Clean up temporary files
if os.path.exists("input_video.mp4"):
    os.remove("input_video.mp4")
if os.path.exists("trimmed_video.mp4"):
    os.remove("trimmed_video.mp4")
if os.path.exists("cropped_video.mp4"):
    os.remove("cropped_video.mp4")
if os.path.exists("text_video.mp4"):
    os.remove("text_video.mp4")
if os.path.exists("music_video.mp4"):
    os.remove("music_video.mp4")
if os.path.exists("resized_video.mp4"):
    os.remove("resized_video.mp4")
if os.path.exists("background_music.mp3"):
    os.remove("background_music.mp3")