在工作中刚好用到,按自己的需求写了一段

import cv2
cap = cv2.VideoCapture('video.mp4')
cap.isOpened()
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

print(width,height)

if cap.isOpened():  # 当成功打开视频时cap.isOpened()返回True,否则返回False
    # get方法参数按顺序对应下表(从0开始编号)
    rate = cap.get(5)  # 帧速率
    FrameNumber = int(cap.get(7))  # 视频文件的帧数
    duration = FrameNumber / rate  # 帧速率/视频总帧数 是时间,除以60之后单位是分钟
    fps = int(rate)  #每一段小视频帧数

    i = 0
    while (True):
        success, frame = cap.read()
        if success:
            i += 1
            if (i % fps == 1):
                videoWriter = cv2.VideoWriter(str(i) + '.mp4',
                                              cv2.VideoWriter_fourcc('D', 'I', 'V', 'X'), fps,
                                              (int(width), int(height)))
                videoWriter.write(frame)
            else:
                videoWriter.write(frame)
        else:
            print('end')
            break

cap.release()

 

相关文章:

  • 2021-06-12
  • 2021-11-29
  • 2022-12-23
  • 2022-01-24
  • 2021-10-19
  • 2022-01-18
  • 2021-12-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-07
  • 2021-07-06
  • 2022-02-22
  • 2021-12-28
  • 2021-04-08
  • 2021-12-06
相关资源
相似解决方案