视频合并 发表于 2017-09-27 | 更新于 2020-06-02 | 分类于 scripts 视频合并将多个视频合并为一个视频 123456789101112131415161718192021222324252627282930313233# -*-coding:utf-8 -*-import cv2import glob__author__ = 'Heroinlj <heroinlj@gmail.com>'def combine_videos_to_one(videos_folder, save_video_path): video = cv2.VideoCapture() video_result = cv2.VideoWriter(save_video_path, cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), 25, frameSize=(320, 288), isColor=True) cv2.namedWindow("videos", cv2.WINDOW_NORMAL) for video_path in glob.glob(videos_folder+"/*.avi"): if not video.open(video_path): print("can not open the video.") exit(1) while True: ret, frame = video.read() if frame is None: break cv2.imshow("videos", frame) video_result.write(frame) if cv2.waitKey(1) == 27: break cv2.destroyAllWindows()def main(): combine_videos_to_one("./1", "result.avi")if __name__ == '__main__': main()