Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
# Import required libraries
|
2 |
import streamlit as st
|
3 |
import cv2
|
4 |
-
import numpy as np
|
5 |
import tempfile
|
6 |
import base64
|
7 |
|
8 |
# Streamlit app title
|
9 |
-
st.title("Video
|
10 |
|
11 |
-
# Function to read video and return frames
|
12 |
def read_video(video_path):
|
13 |
cap = cv2.VideoCapture(video_path)
|
14 |
frames = []
|
@@ -17,8 +16,10 @@ def read_video(video_path):
|
|
17 |
if not ret:
|
18 |
break
|
19 |
frames.append(frame)
|
|
|
|
|
20 |
cap.release()
|
21 |
-
return frames
|
22 |
|
23 |
# Function to convert video file to base64
|
24 |
def get_video_base64(video_path):
|
@@ -27,13 +28,9 @@ def get_video_base64(video_path):
|
|
27 |
return video_base64
|
28 |
|
29 |
# Function to save frames to video
|
30 |
-
def save_frames_to_video(frames, output_video_path):
|
31 |
-
if not frames:
|
32 |
-
return
|
33 |
-
|
34 |
-
height, width, _ = frames[0].shape
|
35 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
36 |
-
out = cv2.VideoWriter(output_video_path, fourcc,
|
37 |
|
38 |
for frame in frames:
|
39 |
out.write(frame)
|
@@ -48,7 +45,7 @@ uploaded_files = st.file_uploader("Upload Video Files 📤", type=["mp4"], accep
|
|
48 |
if uploaded_files:
|
49 |
video_paths = []
|
50 |
for file in uploaded_files:
|
51 |
-
tfile = tempfile.NamedTemporaryFile(delete=False)
|
52 |
tfile.write(file.read())
|
53 |
video_paths.append(tfile.name)
|
54 |
|
@@ -56,15 +53,17 @@ if uploaded_files:
|
|
56 |
|
57 |
# Read videos and get frames
|
58 |
all_frames = []
|
|
|
|
|
59 |
for path in video_paths:
|
60 |
-
frames = read_video(path)
|
61 |
all_frames.extend(frames)
|
62 |
|
63 |
# Placeholder for future functionality
|
64 |
-
st.write("
|
65 |
|
66 |
# Save frames to video
|
67 |
-
save_frames_to_video(all_frames, output_video_name)
|
68 |
|
69 |
# Provide download link for the video
|
70 |
video_base64 = get_video_base64(output_video_name)
|
|
|
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 = []
|
|
|
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):
|
|
|
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)
|
|
|
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 |
|
|
|
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)
|