import cv2
import time

vid = cv2.VideoCapture("final.avi")

# allocate memort
gpu_frame = cv2.cuda.GpuMat()
video_format = cv2.VideoWriter_fourcc(*"X264")
final_clip = cv2.VideoWriter(
    "final_resized.mp4",
    video_format,
    25,
    (2000, 987),
)

fps = int(1000 / 25)

while True:
    ret, frame = vid.read()

    if not ret:
        print("break")
        break

    gpu_frame.upload(frame)
    gpu_frame = cv2.cuda.resize(gpu_frame, (2000, 987))
    frame = gpu_frame.download()
    final_clip.write(frame)


# cv2.destroyAllWindows()
vid.release()
final_clip.release()
