Spaces:
Runtime error
Runtime error
File size: 1,434 Bytes
9ee6ea9 cb3ac6d dba68de cb3ac6d 9ee6ea9 dba68de cb3ac6d dba68de cb3ac6d dba68de cb3ac6d dba68de cb3ac6d | 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 | import streamlit as st
import cv2
import tempfile
import os
from PIL import Image
st.set_page_config(page_title="AI Thumbnail Generator", layout="centered")
st.title("🎯 AI-Based Thumbnail Generator")
st.write("Upload a video to extract thumbnail-worthy frames using AI.")
uploaded_video = st.file_uploader("Upload Video File", type=["mp4", "mov", "avi", "mkv", "wmv"])
if uploaded_video is not None:
st.video(uploaded_video)
st.success("✅ Video uploaded successfully!")
# Save the uploaded video to a temp file
tfile = tempfile.NamedTemporaryFile(delete=False)
tfile.write(uploaded_video.read())
# Extract frames using OpenCV
vidcap = cv2.VideoCapture(tfile.name)
success, image = vidcap.read()
count = 0
thumbnail_frame = None
while success:
if count % 60 == 0: # extract every 2 seconds assuming 30 FPS
frame_path = f"frame_{count}.jpg"
cv2.imwrite(frame_path, image)
thumbnail_frame = frame_path # keep last extracted frame as mock thumbnail
success, image = vidcap.read()
count += 1
if thumbnail_frame:
st.subheader("Generated Thumbnail Frame")
image = Image.open(thumbnail_frame)
st.image(image, caption="Best Frame", use_column_width=True)
with open(thumbnail_frame, "rb") as file:
st.download_button("📥 Download Thumbnail", file, file_name="thumbnail.jpg")
|