-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_parser.py
70 lines (55 loc) · 1.65 KB
/
video_parser.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
59
60
61
62
63
64
65
66
67
68
69
70
import cv2
import os
import numpy as np
# should convert the methods to load files in chucks
def generateFrames(video):
video = cv2.VideoCapture(video)
success,image = video.read()
count = 10000
images = []
while success:
file = "parsed_video/frame%d.jpg" % count
print(f"file: {file}")
images.append(file)
cv2.imwrite(file,image) # save frame as JPEG file
success,image = video.read()
print('Read a new frame: ', success)
count += 1
print(count)
return images
def createVideo(path):
files = os.listdir(path)
files.sort()
# codec = cv2.VideoWriter_fourcc('M','J','P','G')
codec = cv2.VideoWriter_fourcc(*'mp4v')
fps = 30
frame_size = (640, 640) # (width, height), must match the input image sizes
out = cv2.VideoWriter('output.avi', codec, fps, frame_size)
for file in files:
if file.endswith('.jpg'):
image_path = os.path.join(path,file)
frame = cv2.imread(image_path)
if frame is not None:
out.write(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
print(f'failed to read from {image_path}')
out.release
# while(True):
# ret, frame = cap.read()
# if ret == True:
# # Write the frame into the
# # file 'filename.avi'
# out.write(frame)
# # Display the frame
# # saved in the file
# cv2.imshow('Frame', frame)
# # Press S on keyboard
# # to stop the process
# if cv2.waitKey(1) & 0xFF == ord('s'):
# break
# # Break the loop
# else:
# break