'video is not oppening in jupyter notebook using opencv

I have this function where I open a video and then return it's length and the counter, to check if the users watched the hole video. When I ran it in Visual Studio Code it worked fine, but in Jupyter is not opening the video, just returning the video_length and the counter. Can anyone help me solve this?

def play_video(path):
    cap = cv2.VideoCapture(path)
    player = MediaPlayer(path)
    video_length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    cv2.namedWindow("Frame", cv2.WND_PROP_FULLSCREEN)
    cv2.setWindowProperty("Frame",cv2.WND_PROP_FULLSCREEN ,cv2.WINDOW_FULLSCREEN)
    if (cap.isOpened()== False):
        print("Error opening video  file")
    counter = 0
    while(cap.isOpened()):
        ret, frame = cap.read()
        audio_frame, val = player.get_frame()
        if ret == True:
            cv2.imshow('Frame', frame)
            if cv2.waitKey(25) & 0xFF == ord('q'):
                break
            if val != 'eof' and audio_frame is not None:
                img, t = audio_frame
            else:
                break
            counter += 1
    cap.release()
    cv2.destroyAllWindows()
    return counter,video_length

output:

(0, 901)

I'm using Jupyter because I want to make an executable file for my script, so I'm going to convert it to .bat



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source