#動画の各種情報を取得7
import cv2
video_path = '動画のパス'
cap = cv2.VideoCapture(video_path)
幅
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
高さ
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
総フレーム数
count = cap.get(cv2.CAP_PROP_FRAME_COUNT)
fps
fps = cap.get(cv2.CAP_PROP_FPS)
print("width:{}, height:{}, count:{}, fps:{}".format(width,height,count,fps))
#1秒ごとに画像を生成
import cv2
video_path = "動画のパス"
cap = cv2.VideoCapture(video_path)
count = cap.get(cv2.CAP_PROP_FRAME_COUNT)
fps = cap.get(cv2.CAP_PROP_FPS)
print("width:{}, height:{}, count:{}, fps:{}".format(width,height,count,fps))
for num in range(1, int(count), int(fps)):
cap.set(cv2.CAP_PROP_POS_FRAMES, num)
cv2.imwrite("picture{:0=3}".format(int((num-1)/int(fps)))+".jpg", cap.read()[1])
print("save picture{:0=3}".format(int((num-1)/int(fps)))+".jpg")
cap.release()