How to use opencv image as input

Hello,

I try to use that turorial on my webcam:

I want to replace image input by a video as input:

vid = cv2.VideoCapture("videoplayback.mp4")
while (True):
    ret, frame = vid.read()
    cv2.imshow('frame', frame)

    run_detector_image(detector, frame)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        break


How should I modify the load_img to feed the opencv frame ?

Read the video frame by frame and convert them to JPEG format

import cv2
video = cv2.VideoCapture("videoplayback.mp4")
success,image = video.read()
count = 0
success =True
while success:
  success,image = video.read()
  cv2.imwrite("frame%d.jpg" % count, image)     # save frame as JPEG file
  count += 1