[Python] Webcam captured/ saved Video not playing ( not UTF-8 encoded )

Discussão em 'Python' iniciado por Stack, Janeiro 31, 2025.

  1. Stack

    Stack Membro Participativo

    This is the code that i am using to record the webcam and save it. The video gets saved successfully and the last line is also exceuted, but i cannot open it in the directory as it gives this : "File Load Error for My webcam_new.mp4 C:\Users\PMLS\A( DIP lab)\My webcam_new.mp4 is not UTF-8 encoded" If someone can figure this out!

    cap = cv2.VideoCapture(0) # if we hav 2 webcams 0 for 1st and 1 for the2nd webcam

    frame_width = int(cap.get(3)) # 3 means that width will be taken
    frame_height = int(cap.get(4)) # 4 means that length or height will be taken

    fourcc=cv2.VideoWriter_fourcc(*"avc1") #this defines what format we need
    out=cv2.VideoWriter("My webcam_new.mp4", fourcc, 20,(frame_width, frame_height))

    while(cap.isOpened()): # if the webcam is not opened then we cannot capture
    ret, frame = cap.read()

    if not ret: # If the video has ended, break out of the loop
    print("End of webcam!!!")
    break

    out.write(frame)
    cv2.imshow("output_new", frame)

    if cv2.waitKey(30) & 0xFF == ord('q'):
    break

    cap.release()
    out.release()
    cv2.destroyAllWindows()
    print("Got it!!!!")

    Continue reading...

Compartilhe esta Página