-
Notifications
You must be signed in to change notification settings - Fork 1
/
mov2frames.py
33 lines (30 loc) · 1.05 KB
/
mov2frames.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
import os
import cv2
import sys
def make_frames(direc, movie):
vidcap = cv2.VideoCapture(f'movies/{direc}/{movie} 3D-FS 720p.mkv')
success,image = vidcap.read()
if(not success):
print("Tried reading non-existant file!")
return None
count = 0
os.mkdir(f'./left/{movie}')
os.mkdir(f'./right/{movie}')
while success:
#sys.stdout.write("\r"+str(count))
#sys.stdout.flush()
image = cv2.resize(image, (1280,720))
if count % 2 == 0:
cv2.imwrite(f'left/{movie}/{movie}_%06d.jpg' % (count/2), image)
else:
cv2.imwrite(f'right/{movie}/{movie}_%06d_R.jpg' % ((count-1)/2), image)
success,image = vidcap.read()
count += 1
if count % 10000 == 0:
print("10000 frames compeleted")
if __name__ == '__main__':
for direc in os.listdir('movies/'):
movie = os.listdir(f'movies/{direc}')[0]
movie = movie.split(' ', 1)[0]
make_frames(direc, movie)
print(f'Completed movie: {movie}\n in directory: {direc}')