How to get the duration of video using cv2

前端 未结 5 1957
北恋
北恋 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:24

    First calculate frame per second like this

    fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
    

    Then duration can be calculated as (number of frames) / (frames per second)

     duration = float(num_frames) / float(fps) # in seconds
    

提交回复
热议问题