python使用opencv获取视频时长

import cv2
def get_video_duration(filename):
  cap = cv2.VideoCapture(filename)
  if cap.isOpened():
    rate = cap.get(5)
    frame_num =cap.get(7)
    duration = frame_num/rate
    return duration
  return -1


print(get_video_duration('1.mp4'))

执行代码

你可能感兴趣的:(Opencv,Python,opencv,python,音视频)