awacke1 commited on
Commit
b0716df
·
verified ·
1 Parent(s): 3596178

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import moviepy.editor as mp
3
+ import tempfile
4
+ import os
5
+
6
+ def main():
7
+ st.title("Simple Video Editor")
8
+
9
+ # File uploaders
10
+ video_file = st.file_uploader("Upload a video file (MP4)", type=["mp4"])
11
+ audio_file = st.file_uploader("Upload an audio file (MP3 or WAV)", type=["mp3", "wav"])
12
+
13
+ if video_file and audio_file:
14
+ # Save uploaded files to temporary locations
15
+ temp_video = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
16
+ temp_video.write(video_file.read())
17
+ temp_video_path = temp_video.name
18
+
19
+ temp_audio = tempfile.NamedTemporaryFile(delete=False, suffix=f".{audio_file.name.split('.')[-1]}")
20
+ temp_audio.write(audio_file.read())
21
+ temp_audio_path = temp_audio.name
22
+
23
+ # Load video and audio
24
+ video = mp.VideoFileClip(temp_video_path)
25
+ audio = mp.AudioFileClip(temp_audio_path)
26
+
27
+ # Display video info
28
+ st.write(f"Video duration: {video.duration:.2f} seconds")
29
+ st.write(f"Audio duration: {audio.duration:.2f} seconds")
30
+
31
+ # Trim video
32
+ st.subheader("Trim Video")
33
+ video_start = st.slider("Video start time (seconds)", 0.0, video.duration, 0.0)
34
+ video_end = st.slider("Video end time (seconds)", 0.0, video.duration, video.duration)
35
+ trimmed_video = video.subclip(video_start, video_end)
36
+
37
+ # Trim audio
38
+ st.subheader("Trim Audio")
39
+ audio_start = st.slider("Audio start time (seconds)", 0.0, audio.duration, 0.0)
40
+ audio_end = st.slider("Audio end time (seconds)", 0.0, audio.duration, audio.duration)
41
+ trimmed_audio = audio.subclip(audio_start, audio_end)
42
+
43
+ # Combine video and audio
44
+ if st.button("Combine Video and Audio"):
45
+ final_clip = trimmed_video.set_audio(trimmed_audio)
46
+
47
+ # Save the final video
48
+ output_path = "output_video.mp4"
49
+ final_clip.write_videofile(output_path, codec="libx264", audio_codec="aac")
50
+
51
+ # Provide download link
52
+ st.success("Video processing complete!")
53
+ with open(output_path, "rb") as file:
54
+ btn = st.download_button(
55
+ label="Download processed video",
56
+ data=file,
57
+ file_name="processed_video.mp4",
58
+ mime="video/mp4"
59
+ )
60
+
61
+ # Clean up temporary files
62
+ video.close()
63
+ audio.close()
64
+ os.unlink(temp_video_path)
65
+ os.unlink(temp_audio_path)
66
+
67
+ if __name__ == "__main__":
68
+ main()