awacke1 commited on
Commit
00b7f6e
Β·
1 Parent(s): 1dc1e50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -39
app.py CHANGED
@@ -1,41 +1,18 @@
1
  # Import required libraries
2
  import streamlit as st
3
- import cv2
4
  import tempfile
5
  import base64
6
 
7
  # Streamlit app title
8
  st.title("Video Concatenator App πŸŽ₯")
9
 
10
- # Function to read video and return frames and properties
11
- def read_video(video_path):
12
- cap = cv2.VideoCapture(video_path)
13
- frames = []
14
- while True:
15
- ret, frame = cap.read()
16
- if not ret:
17
- break
18
- frames.append(frame)
19
- fps = int(cap.get(cv2.CAP_PROP_FPS))
20
- size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
21
- cap.release()
22
- return frames, fps, size
23
-
24
  # Function to convert video file to base64
25
  def get_video_base64(video_path):
26
  with open(video_path, "rb") as file:
27
  video_base64 = base64.b64encode(file.read()).decode()
28
  return video_base64
29
 
30
- # Function to save frames to video
31
- def save_frames_to_video(frames, output_video_path, fps, size):
32
- fourcc = cv2.VideoWriter_fourcc(*'mp4v')
33
- out = cv2.VideoWriter(output_video_path, fourcc, fps, size)
34
-
35
- for frame in frames:
36
- out.write(frame)
37
- out.release()
38
-
39
  # Textbox for user to specify output video name
40
  output_video_name = st.text_input("Enter the name for the output video:", "Output_Video.mp4")
41
 
@@ -43,30 +20,26 @@ output_video_name = st.text_input("Enter the name for the output video:", "Outpu
43
  uploaded_files = st.file_uploader("Upload Video Files πŸ“€", type=["mp4"], accept_multiple_files=True)
44
 
45
  if uploaded_files:
 
46
  video_paths = []
47
  for file in uploaded_files:
48
- tfile = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
49
  tfile.write(file.read())
50
  video_paths.append(tfile.name)
51
-
52
- st.write("Uploaded video files: πŸ“‚", video_paths)
53
 
54
- # Read videos and get frames
55
- all_frames = []
56
- fps = 0
57
- size = (0, 0)
58
- for path in video_paths:
59
- frames, fps, size = read_video(path)
60
- all_frames.extend(frames)
61
 
62
- # Placeholder for future functionality
63
- st.write("Additional processing can be performed here. ⏳")
64
 
65
- # Save frames to video
66
- save_frames_to_video(all_frames, output_video_name, fps, size)
 
67
 
68
  # Provide download link for the video
69
- video_base64 = get_video_base64(output_video_name)
70
  st.markdown(f'### Download Output Video πŸ“₯')
71
  href = f'<a href="data:video/mp4;base64,{video_base64}" download="{output_video_name}">Click here to download the video</a>'
72
  st.markdown(href, unsafe_allow_html=True)
 
1
  # Import required libraries
2
  import streamlit as st
3
+ from moviepy.editor import VideoFileClip, concatenate_videoclips
4
  import tempfile
5
  import base64
6
 
7
  # Streamlit app title
8
  st.title("Video Concatenator App πŸŽ₯")
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Function to convert video file to base64
11
  def get_video_base64(video_path):
12
  with open(video_path, "rb") as file:
13
  video_base64 = base64.b64encode(file.read()).decode()
14
  return video_base64
15
 
 
 
 
 
 
 
 
 
 
16
  # Textbox for user to specify output video name
17
  output_video_name = st.text_input("Enter the name for the output video:", "Output_Video.mp4")
18
 
 
20
  uploaded_files = st.file_uploader("Upload Video Files πŸ“€", type=["mp4"], accept_multiple_files=True)
21
 
22
  if uploaded_files:
23
+ video_clips = []
24
  video_paths = []
25
  for file in uploaded_files:
26
+ tfile = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
27
  tfile.write(file.read())
28
  video_paths.append(tfile.name)
29
+ clip = VideoFileClip(tfile.name)
30
+ video_clips.append(clip)
31
 
32
+ st.write("Uploaded video files: πŸ“‚", video_paths)
 
 
 
 
 
 
33
 
34
+ # Concatenate video clips
35
+ final_video = concatenate_videoclips(video_clips)
36
 
37
+ # Save the result
38
+ final_video_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
39
+ final_video.write_videofile(final_video_path, codec="libx264")
40
 
41
  # Provide download link for the video
42
+ video_base64 = get_video_base64(final_video_path)
43
  st.markdown(f'### Download Output Video πŸ“₯')
44
  href = f'<a href="data:video/mp4;base64,{video_base64}" download="{output_video_name}">Click here to download the video</a>'
45
  st.markdown(href, unsafe_allow_html=True)