How to get the duration of video using cv2

前端 未结 5 1946
北恋
北恋 2021-01-03 19:24

I can only get the number of frames CAP_PROP_FRAME_COUNT using CV2.

However, I cannot find the parameter to get the duration of the video using cv2.

5条回答
  •  耶瑟儿~
    2021-01-03 20:09

    Capture the video and output the duration is seconds

    vidcapture = cv2.VideoCapture('myvideo.mp4')
    fps = vidcapture.get(cv2.CAP_PROP_FPS)
    totalNoFrames = vidcapture.get(cv2.CAP_PROP_FRAME_COUNT);
    durationInSeconds = float(totalNoFrames) / float(fps)
    
    print("durationInSeconds: ",durationInSeconds,"s")
    

提交回复
热议问题