[Python] read all mp4 files in the folder

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I want to read all mp4 files in the folder but when running it doesn't work, I want to read file 1.mp4 when it finishes running it automatically runs 2.mp4 .... n.mp4.

    import os
    import cv2
    import numpy as np
    for root, dirs, files in os.walk('f:\\a'):
    for file in files:
    tt = (os.path.join(root,file))
    print(tt)
    cap = cv2.VideoCapture(tt)

    while (cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:


    cv2.imshow('frame', frame)
    if cv2.waitKey(1) == ord('q'):
    break

    cap.release()
    cv2.destroyAllWindows()



    I have put in a loop (for) but it only shows a list of files (cv2.imshow('frame', frame), please guide me.

    Continue reading...

Compartilhe esta Página