Spaces:
Runtime error
Runtime error
File size: 2,338 Bytes
0a3c439 bf69b71 0a3c439 1dc1e50 0a3c439 1dc1e50 0a3c439 1dc1e50 0a3c439 1dc1e50 0a3c439 bf69b71 13d5e58 1dc1e50 13d5e58 1dc1e50 13d5e58 0a3c439 13d5e58 0a3c439 1dc1e50 0a3c439 13d5e58 0a3c439 1dc1e50 0a3c439 1dc1e50 13d5e58 0a3c439 1dc1e50 13d5e58 1dc1e50 0a3c439 bf69b71 13d5e58 bf69b71 13d5e58 bf69b71 |
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 |
# Import required libraries
import streamlit as st
import cv2
import tempfile
import base64
# Streamlit app title
st.title("Video Concatenator App π₯")
# Function to read video and return frames and properties
def read_video(video_path):
cap = cv2.VideoCapture(video_path)
frames = []
while True:
ret, frame = cap.read()
if not ret:
break
frames.append(frame)
fps = int(cap.get(cv2.CAP_PROP_FPS))
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
cap.release()
return frames, fps, size
# Function to convert video file to base64
def get_video_base64(video_path):
with open(video_path, "rb") as file:
video_base64 = base64.b64encode(file.read()).decode()
return video_base64
# Function to save frames to video
def save_frames_to_video(frames, output_video_path, fps, size):
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(output_video_path, fourcc, fps, size)
for frame in frames:
out.write(frame)
out.release()
# Textbox for user to specify output video name
output_video_name = st.text_input("Enter the name for the output video:", "Output_Video.mp4")
# Upload videos
uploaded_files = st.file_uploader("Upload Video Files π€", type=["mp4"], accept_multiple_files=True)
if uploaded_files:
video_paths = []
for file in uploaded_files:
tfile = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
tfile.write(file.read())
video_paths.append(tfile.name)
st.write("Uploaded video files: π", video_paths)
# Read videos and get frames
all_frames = []
fps = 0
size = (0, 0)
for path in video_paths:
frames, fps, size = read_video(path)
all_frames.extend(frames)
# Placeholder for future functionality
st.write("Additional processing can be performed here. β³")
# Save frames to video
save_frames_to_video(all_frames, output_video_name, fps, size)
# Provide download link for the video
video_base64 = get_video_base64(output_video_name)
st.markdown(f'### Download Output Video π₯')
href = f'<a href="data:video/mp4;base64,{video_base64}" download="{output_video_name}">Click here to download the video</a>'
st.markdown(href, unsafe_allow_html=True)
|