afzalsomro15684 commited on
Commit
777d015
·
verified ·
1 Parent(s): 66a9dec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -23
app.py CHANGED
@@ -1,11 +1,12 @@
1
  import streamlit as st
2
- from moviepy.editor import VideoFileClip, concatenate_videoclips, TextClip, CompositeVideoClip
3
- from moviepy.video.fx.all import crop
4
  import os
5
 
6
  # Streamlit app
7
- st.title("🎥 Simple Video Editor")
8
- st.write("Edit your videos online and make them copyright-free!")
 
9
 
10
  # Upload video
11
  uploaded_file = st.file_uploader("Upload a video:", type=["mp4", "avi", "mov"])
@@ -21,45 +22,80 @@ if uploaded_file is not None:
21
  # Sidebar for editing options
22
  st.sidebar.header("Editing Options")
23
  task = st.sidebar.selectbox("Select a task:", [
24
- "Trim Video", "Crop Video", "Add Text", "Export Video"
25
  ])
26
 
27
  if task == "Trim Video":
28
- st.header("Trim Video")
 
29
  start_time = st.number_input("Start Time (seconds):", min_value=0, max_value=int(video.duration))
30
  end_time = st.number_input("End Time (seconds):", min_value=0, max_value=int(video.duration))
31
- if st.button("Trim"):
32
- trimmed_video = video.subclip(start_time, end_time)
33
- trimmed_video.write_videofile("trimmed_video.mp4")
34
- st.video("trimmed_video.mp4")
 
 
35
 
36
  elif task == "Crop Video":
37
- st.header("Crop Video")
 
38
  x1 = st.number_input("X1:", min_value=0, max_value=video.size[0])
39
  y1 = st.number_input("Y1:", min_value=0, max_value=video.size[1])
40
  x2 = st.number_input("X2:", min_value=0, max_value=video.size[0])
41
  y2 = st.number_input("Y2:", min_value=0, max_value=video.size[1])
42
- if st.button("Crop"):
43
- cropped_video = crop(video, x1=x1, y1=y1, x2=x2, y2=y2)
44
- cropped_video.write_videofile("cropped_video.mp4")
45
- st.video("cropped_video.mp4")
 
 
46
 
47
  elif task == "Add Text":
48
- st.header("Add Text")
 
49
  text = st.text_input("Enter text:")
50
  fontsize = st.number_input("Font Size:", min_value=10, max_value=100, value=50)
51
  color = st.color_picker("Text Color:", "#FFFFFF")
52
  position_x = st.number_input("Position X:", min_value=0, max_value=video.size[0])
53
  position_y = st.number_input("Position Y:", min_value=0, max_value=video.size[1])
54
  if st.button("Add Text"):
55
- text_clip = TextClip(text, fontsize=fontsize, color=color)
56
- text_clip = text_clip.set_position((position_x, position_y)).set_duration(video.duration)
57
- final_video = CompositeVideoClip([video, text_clip])
58
- final_video.write_videofile("text_video.mp4")
59
- st.video("text_video.mp4")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  elif task == "Export Video":
62
- st.header("Export Video")
63
  st.write("Your video is ready to download!")
64
  st.video("input_video.mp4")
65
  with open("input_video.mp4", "rb") as f:
@@ -73,4 +109,10 @@ if os.path.exists("trimmed_video.mp4"):
73
  if os.path.exists("cropped_video.mp4"):
74
  os.remove("cropped_video.mp4")
75
  if os.path.exists("text_video.mp4"):
76
- os.remove("text_video.mp4")
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from moviepy.editor import VideoFileClip, concatenate_videoclips, TextClip, CompositeVideoClip, AudioFileClip
3
+ from moviepy.video.fx.all import crop, resize, mirror_x
4
  import os
5
 
6
  # Streamlit app
7
+ st.set_page_config(page_title="🎥 Pro Video Editor", page_icon="🎬", layout="wide")
8
+ st.title("🎥 Pro Video Editor")
9
+ st.write("Edit your videos like a pro with this easy-to-use tool!")
10
 
11
  # Upload video
12
  uploaded_file = st.file_uploader("Upload a video:", type=["mp4", "avi", "mov"])
 
22
  # Sidebar for editing options
23
  st.sidebar.header("Editing Options")
24
  task = st.sidebar.selectbox("Select a task:", [
25
+ "Trim Video", "Crop Video", "Add Text", "Add Music", "Resize Video", "Export Video"
26
  ])
27
 
28
  if task == "Trim Video":
29
+ st.header("✂️ Trim Video")
30
+ st.write("Select the start and end time to trim your video.")
31
  start_time = st.number_input("Start Time (seconds):", min_value=0, max_value=int(video.duration))
32
  end_time = st.number_input("End Time (seconds):", min_value=0, max_value=int(video.duration))
33
+ if st.button("Trim Video"):
34
+ with st.spinner("Trimming video..."):
35
+ trimmed_video = video.subclip(start_time, end_time)
36
+ trimmed_video.write_videofile("trimmed_video.mp4")
37
+ st.success("Video trimmed successfully!")
38
+ st.video("trimmed_video.mp4")
39
 
40
  elif task == "Crop Video":
41
+ st.header("🌾 Crop Video")
42
+ st.write("Crop your video by selecting the area.")
43
  x1 = st.number_input("X1:", min_value=0, max_value=video.size[0])
44
  y1 = st.number_input("Y1:", min_value=0, max_value=video.size[1])
45
  x2 = st.number_input("X2:", min_value=0, max_value=video.size[0])
46
  y2 = st.number_input("Y2:", min_value=0, max_value=video.size[1])
47
+ if st.button("Crop Video"):
48
+ with st.spinner("Cropping video..."):
49
+ cropped_video = crop(video, x1=x1, y1=y1, x2=x2, y2=y2)
50
+ cropped_video.write_videofile("cropped_video.mp4")
51
+ st.success("Video cropped successfully!")
52
+ st.video("cropped_video.mp4")
53
 
54
  elif task == "Add Text":
55
+ st.header("✍️ Add Text")
56
+ st.write("Add text to your video with custom font size, color, and position.")
57
  text = st.text_input("Enter text:")
58
  fontsize = st.number_input("Font Size:", min_value=10, max_value=100, value=50)
59
  color = st.color_picker("Text Color:", "#FFFFFF")
60
  position_x = st.number_input("Position X:", min_value=0, max_value=video.size[0])
61
  position_y = st.number_input("Position Y:", min_value=0, max_value=video.size[1])
62
  if st.button("Add Text"):
63
+ with st.spinner("Adding text..."):
64
+ text_clip = TextClip(text, fontsize=fontsize, color=color)
65
+ text_clip = text_clip.set_position((position_x, position_y)).set_duration(video.duration)
66
+ final_video = CompositeVideoClip([video, text_clip])
67
+ final_video.write_videofile("text_video.mp4")
68
+ st.success("Text added successfully!")
69
+ st.video("text_video.mp4")
70
+
71
+ elif task == "Add Music":
72
+ st.header("🎵 Add Music")
73
+ st.write("Add background music to your video.")
74
+ music_file = st.file_uploader("Upload a music file:", type=["mp3", "wav"])
75
+ if music_file and st.button("Add Music"):
76
+ with st.spinner("Adding music..."):
77
+ with open("background_music.mp3", "wb") as f:
78
+ f.write(music_file.getbuffer())
79
+ audio_clip = AudioFileClip("background_music.mp3")
80
+ final_video = video.set_audio(audio_clip)
81
+ final_video.write_videofile("music_video.mp4")
82
+ st.success("Music added successfully!")
83
+ st.video("music_video.mp4")
84
+
85
+ elif task == "Resize Video":
86
+ st.header("📏 Resize Video")
87
+ st.write("Resize your video to a specific width and height.")
88
+ width = st.number_input("Width:", min_value=100, max_value=1920, value=video.size[0])
89
+ height = st.number_input("Height:", min_value=100, max_value=1080, value=video.size[1])
90
+ if st.button("Resize Video"):
91
+ with st.spinner("Resizing video..."):
92
+ resized_video = resize(video, width=width, height=height)
93
+ resized_video.write_videofile("resized_video.mp4")
94
+ st.success("Video resized successfully!")
95
+ st.video("resized_video.mp4")
96
 
97
  elif task == "Export Video":
98
+ st.header("📤 Export Video")
99
  st.write("Your video is ready to download!")
100
  st.video("input_video.mp4")
101
  with open("input_video.mp4", "rb") as f:
 
109
  if os.path.exists("cropped_video.mp4"):
110
  os.remove("cropped_video.mp4")
111
  if os.path.exists("text_video.mp4"):
112
+ os.remove("text_video.mp4")
113
+ if os.path.exists("music_video.mp4"):
114
+ os.remove("music_video.mp4")
115
+ if os.path.exists("resized_video.mp4"):
116
+ os.remove("resized_video.mp4")
117
+ if os.path.exists("background_music.mp3"):
118
+ os.remove("background_music.mp3")