python获取视频时长

import cv2
def video_duration_3(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
输出的视频时长是秒
posted @ 2023-05-09 10:02  祥瑞哈哈哈  阅读(196)  评论(0)    收藏  举报