Spaces:
Running
Running
first commit
Browse files- app.py +33 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
# Function to extract the last frame from a video
|
6 |
+
def extract_last_frame(video_file):
|
7 |
+
cap = cv2.VideoCapture(video_file)
|
8 |
+
# print(cap)
|
9 |
+
# Get the total number of frames in the video
|
10 |
+
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
11 |
+
|
12 |
+
# Check if the video is empty
|
13 |
+
if total_frames <= 0:
|
14 |
+
return None
|
15 |
+
|
16 |
+
# Set the position to the last frame
|
17 |
+
cap.set(cv2.CAP_PROP_POS_FRAMES, total_frames - 1)
|
18 |
+
|
19 |
+
# Read and return the last frame
|
20 |
+
ret, last_frame = cap.read()
|
21 |
+
|
22 |
+
return cv2.cvtColor(last_frame, cv2.COLOR_BGR2RGB)
|
23 |
+
|
24 |
+
demo = gr.Interface(
|
25 |
+
fn=extract_last_frame,
|
26 |
+
inputs=gr.Video(),
|
27 |
+
outputs="image",
|
28 |
+
title="Video to Last Frame",
|
29 |
+
description="Extract the last frame from a video",
|
30 |
+
)
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
opencv-python-headless
|