How to slice a video second by second using python

**Origin:** At the beginning, the video was sliced ​​frame by frame, but in the end it was found that the amount was too large, and the difference between each frame within one second was not big, so I finally chose to slice by second.

import cv2

# vidcap = cv2.VideoCapture('需要切片的视频的地址')
vidcap = cv2.VideoCapture('./Videos/test.mp4')
success,image = vidcap.read()
fps = int(vidcap.get(cv2.CAP_PROP_FPS))
count = 0
while success:
    if count % fps == 0:
        # cv2.imwrite("图片的保存目录/%d.jpg" % int(count / fps), image)
        cv2.imwrite("./Images/%d.jpg" % int(count / fps), image)
    print('Process %dth seconds: ' % int(count / fps), success)
    success,image = vidcap.read()
    count += 1

Guess you like

Origin blog.csdn.net/weixin_44747173/article/details/127237699