opencv统计视频帧数脚本

def countFrame1(path):# 系统自带的统计方法
    video = cv2.VideoCapture(path)
    total = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
    print(total)


def countFrame2(path):# 手动统计(特别慢)
    video = cv2.VideoCapture(path)
    total = 0
    while True:
        (current, frame) = video.read()
        if not current:
            break
        total += 1
        print(total)
    print(total)


if __name__ == '__main__':
    countFrame1("video.mp4")  # 快方法
    countFrame2("video.mp4")  # 慢方法

opencv版本3及以上版本才可以用快方法

猜你喜欢

转载自blog.csdn.net/weixin_42630613/article/details/114674137
今日推荐