-
Notifications
You must be signed in to change notification settings - Fork 5
/
convert_frame_to_video.py
executable file
·58 lines (47 loc) · 1.4 KB
/
convert_frame_to_video.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
'''
convert multiple frame to a single video
'''
import cv2
import numpy as np
import os
from os.path import isfile, join
def convert_frames_to_video(pathIn,pathOut,fps):
'''
convert frames to video
Args:
pathIn : input path for frames
pathOut: output path for video
fps: frame per second
'''
frame_array = []
files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
#for sorting the file names properly
files.sort()
# i1=files.index('um_000006.png')
# i2=files.index('um_000008.png')
# # print(i1)
# files=files[i1:i2+1]
# print(files)
for i in range(len(files)):
filename=pathIn + files[i]
# print(filename)
#reading each files
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width,height)
print(filename)
#inserting the frames into an image array
frame_array.append(img)
out = cv2.VideoWriter(pathOut,cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
for i in range(len(frame_array)):
# writing to a image array
out.write(frame_array[i])
out.release()
def main():
pathIn= '/home/ashlee/person_project/lidar/winter_project/video/'
pathOut = 'reatime_video.avi'
fps = 8.0
convert_frames_to_video(pathIn, pathOut, fps)
if __name__=="__main__":
main()