Spaces:
Runtime error
Runtime error
File size: 1,834 Bytes
048e6a3 5d25310 048e6a3 5d25310 048e6a3 5d25310 |
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 |
import streamlit as st
import os
import zipfile
import cv2
import base64
from pathlib import Path
# Function to extract zip file
def extract_zip(input_zip, output_folder):
with zipfile.ZipFile(input_zip, 'r') as zip_ref:
zip_ref.extractall(output_folder)
# Function to convert images to video
def images_to_video(folder_path, output_video):
images = [img for img in os.listdir(folder_path) if img.endswith(".png")]
frame = cv2.imread(os.path.join(folder_path, images[0]))
height, width, layers = frame.shape
# Change to MP4 format
video = cv2.VideoWriter(output_video, cv2.VideoWriter_fourcc(*'mp4v'), 1, (width, height))
for image in images:
video.write(cv2.imread(os.path.join(folder_path, image)))
video.release()
# Function to get base64 of a file for download
def get_video_base64(binary_file):
with open(binary_file, 'rb') as file:
data = file.read()
return base64.b64encode(data).decode()
st.title("ZipToVideo π₯π¦")
uploaded_file = st.file_uploader("Choose a ZIP file", type="zip")
if uploaded_file is not None:
file_name = uploaded_file.name
st.write("Processing uploaded file:", file_name)
# Save uploaded file
with open(file_name, "wb") as f:
f.write(uploaded_file.getbuffer())
output_folder = file_name.split('.')[0]
if not os.path.exists(output_folder):
os.mkdir(output_folder)
# Extract ZIP
extract_zip(file_name, output_folder)
# Convert to Video
output_video = f"{output_folder}.mp4"
images_to_video(output_folder, output_video)
# Generate download link
video_file_base64 = get_video_base64(output_video)
href = f'<a href="data:file/mp4;base64,{video_file_base64}" download="{output_video}">Download Video File</a>'
st.markdown(href, unsafe_allow_html=True) |