需求:将长视频改成想要的分辨率的想要帧数的等长短视频
同样给自己备份
import cv2
def v_write(video_dir,fps,size):
'''合成视频
video_dir:要切的文件
fps:要合成的帧数
size:要合成的分辨率
'''
videoWriter = cv2.VideoWriter(video_dir, cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), fps, size)
i = 0
while True:
success, frame = videoCapture.read()
if success:
i += 1
if i>300:
a=1
break
#if (i >= 1000 and i <= 2000):
else:
frame = cv2.resize(frame, size)
videoWriter.write(frame)
else:
a=0
break
return a
video_d = 'cu\\test\\yj'#存放在哪
video_path='cu\\teacher.mp4'#剪切的视频
fps = 25 # 保存视频的帧率
size = (320,240) # 保存视频的大小
videoCapture = cv2.VideoCapture(video_path)
c=1 #已经剪了多少个
aa=1
while aa!=0:
video_dir=video_d+str(c)+'.avi'
aa=v_write(video_dir,fps,size)
c+=1
#if c==10:#只要十个
#break