add get frames

This commit is contained in:
Yioutpi
2023-04-13 22:27:42 +08:00
parent 0618c12d63
commit 4279d86333

24
app.py
View File

@@ -9,6 +9,30 @@ def play_video():
print("play video")
print(time.time)
def get_frames_from_video(video_path, timestamp):
"""
video_path:str
timestamp:float64
return [[0:nearest_frame-1], [nearest_frame+1], nearest_frame]
"""
frames = []
try:
cap = cv2.VideoCapture(video_path)
fps = cap.get(cv2.CAP_PROP_FPS)
while cap.isOpened():
ret, frame = cap.read()
if ret == True:
frames.append(frame)
else:
break
except (OSError, TypeError, ValueError, KeyError, SyntaxError) as e:
print("read_frame_source:{} error. {}\n".format(video_path, str(e)))
key_frame_index = int(timestamp * fps)
nearest_frame = frames[key_frame_index]
frames = [frames[:key_frame_index], frames[key_frame_index:], nearest_frame]
return frames
with gr.Blocks() as iface:
with gr.Row():