File size: 878 Bytes
6bcac2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25ec1ec
6bcac2c
 
 
 
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
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)