File size: 4,161 Bytes
9aad68e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from moviepy.editor import VideoFileClip, concatenate_videoclips, TextClip, CompositeVideoClip
from moviepy.video.fx.all import crop, resize, mirror_x
import os

# Streamlit app
st.title("🎥 Professional Video Editing Tool")
st.write("Make your videos copyright-free and edit them like a pro!")

# 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", "Remove Watermark", "Export Video"
    ])

    if task == "Trim Video":
        st.header("Trim 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"):
            trimmed_video = video.subclip(start_time, end_time)
            trimmed_video.write_videofile("trimmed_video.mp4")
            st.video("trimmed_video.mp4")

    elif task == "Crop Video":
        st.header("Crop Video")
        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"):
            cropped_video = crop(video, x1=x1, y1=y1, x2=x2, y2=y2)
            cropped_video.write_videofile("cropped_video.mp4")
            st.video("cropped_video.mp4")

    elif task == "Add Text":
        st.header("Add Text")
        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"):
            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.video("text_video.mp4")

    elif task == "Add Music":
        st.header("Add Music")
        music_file = st.file_uploader("Upload a music file:", type=["mp3", "wav"])
        if music_file and st.button("Add 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.video("music_video.mp4")

    elif task == "Remove Watermark":
        st.header("Remove Watermark")
        st.write("This feature is under development. Please check back later!")
        # Add watermark removal code here

    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("background_music.mp3"):
    os.remove("background_music.mp3")