football_analysis / utils /video_utils.py
M.Shoaib Shafique
let's deploy to huggingface spaces
e19f940
raw
history blame contribute delete
774 Bytes
import cv2
def check_video_resolution(video_path):
vid = cv2.VideoCapture(video_path)
height = vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
width = vid.get(cv2.CAP_PROP_FRAME_WIDTH)
return height,width
def read_video(video_path):
cap = cv2.VideoCapture(video_path)
frames = []
while True:
ret, frame = cap.read()
if not ret:
break
frame = cv2.resize(frame,(1280,720))
frames.append(frame)
return frames
def save_video(ouput_video_frames,output_video_path):
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter(output_video_path, fourcc, 24, (ouput_video_frames[0].shape[1], ouput_video_frames[0].shape[0]))
for frame in ouput_video_frames:
out.write(frame)
out.release()