天天看點

python opencv擷取視訊基本資訊

video_path = "./test0.mp4"
video_capture = cv2.VideoCapture(video_path)
video_FourCC = int(video_capture.get(cv2.CAP_PROP_FOURCC))  # 視訊編碼
video_width = int(video_capture.get(3))
video_height = int(video_capture.get(4))
video_size = (int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH)),
              int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print("video size:{}".format(video_size))  # (540, 960)
# 視訊總幀數
total_frames = int(video_capture.get(cv2.CAP_PROP_FRAME_COUNT))  # 799
print("total_frame:{}".format(total_frames))

# 視訊幀率
video_fps = int(video_capture.get(5))
print("video_fps:{}".format(video_fps))
# video_fps_1 = video_capture.get(cv2.CAP_PROP_FPS)  # 視訊幀率30
# print("video_fps_1:{}".format(video_fps_1))