1.视频分帧
def saveframes(video_path):
os.system("rm /home/documents/coding1/demo/gui/image/*")
print(video_path)
vidcap = cv2.VideoCapture(video_path)
success, image = vidcap.read()
count = 0
success = True
while success:
success, image = vidcap.read()
if success:
# image = cv2.resize(frame, (533, 300))
print(count)
cv2.imwrite("image/frame%d.jpg" % count, image) # save frame as JPEG file
if cv2.waitKey(10) == 27:
break
count += 1
2.合成视频
import cv2
def images_to_video():
fps = 30 # 帧率
num_frames = 500
img_array = []
img_width = 720
img_height = 1280
for i in range(num_frames+1):
filename = "./frames/"+str(i)+".png"
img = cv2.imread(filename)