ovi054's picture
update commit
25ec1ec
raw
history blame contribute delete
No virus
878 Bytes
import gradio as gr
import cv2
import numpy as np
# Function to extract the last frame from a video
def extract_last_frame(video_file):
cap = cv2.VideoCapture(video_file)
# print(cap)
# Get the total number of frames in the video
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
# Check if the video is empty
if total_frames <= 0:
return None
# Set the position to the last frame
cap.set(cv2.CAP_PROP_POS_FRAMES, total_frames - 1)
# Read and return the last frame
ret, last_frame = cap.read()
return cv2.cvtColor(last_frame, cv2.COLOR_BGR2RGB)
demo = gr.Interface(
fn=extract_last_frame,
inputs=gr.Video(),
outputs="image",
title="Video to Last Frame",
description="Extract the last frame from video (🖤 the project if it helps!)",
)
if __name__ == "__main__":
demo.launch(debug=True)