-
Notifications
You must be signed in to change notification settings - Fork 1
/
video.py
executable file
·62 lines (47 loc) · 1.6 KB
/
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
59
60
61
62
from __future__ import print_function
import cv2
import skvideo.io
class Video(object):
"""Class to handle the datasets"""
def __init__(self, vidDir=None):
self.vidDir = vidDir
def load_video(self, video_name, vidLib='skvideo'):
videoFrames = {}
if vidLib == 'ocv':
cap = cv2.VideoCapture(self.vidDir+video_name)
# Check if camera opened successfully
if (cap.isOpened()== False):
print("\nError opening video stream or file!!!!!\n")
# Read until video is completed
frameNum = 0
while(cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:
videoFrames[frameNum] = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
frameNum += 1
else:
break
# When everything done, release the video capture object
cap.release()
vidHeight = videoFrames[0].shape[1]
vidWidth = videoFrames[0].shape[0]
self.videoFrames = videoFrames
self.vidHeight = vidHeight
self.vidWidth = vidWidth
self.video_name = video_name
self.size = [vidWidth, vidHeight]
elif vidLib == 'skvideo':
videogen = skvideo.io.vreader(self.vidDir+video_name)
for frameNum, frame in enumerate(videogen):
videoFrames[frameNum] = frame
vidHeight = videoFrames[0].shape[1]
vidWidth = videoFrames[0].shape[0]
videometadata = skvideo.io.ffprobe(self.vidDir+video_name)
self.frame_rate = eval(videometadata['video']['@avg_frame_rate'])
self.videoFrames = videoFrames
self.vidHeight = vidHeight
self.vidWidth = vidWidth
self.video_name = video_name
self.size = [vidWidth, vidHeight]
return videoFrames, vidHeight, vidWidth