视频合并

视频合并

将多个视频合并为一个视频

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*-coding:utf-8 -*-
import cv2
import 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()