python 视频抽帧

可以使用 Python 库中的 OpenCV 和 ffpyplayer 进行视频抽帧。

  1. 使用 OpenCV: ``` import cv2

Open the video file

video = cv2.VideoCapture("path/to/video.mp4")

Get the frames per second (fps) of the video

fps = video.get(cv2.CAP_PROP_FPS)

Get the total number of frames in the video

num_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))

Choose the interval for frames to be extracted (e.g. every 10th frame)

frame_interval = 10

Initialize a counter for the current frame

current_frame = 0

Loop through the frames of the video

while True: # Grab the current frame ret, frame = video.read() # Break the loop if the video has ended if not ret: break # Increment the frame counter current_frame += 1 # If the current frame is an interval frame, save it if current_frame % frame_interval == 0: cv2.imwrite("path/to/save/frame{}.jpg".format(current_frame), frame)

Release the video capture object

video.release() ```

你可能感兴趣的:(python,音视频,opencv,计算机视觉,人工智能)