12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- from os.path import exists
- import cv2
- from pycs.projects.ImageFile import ImageFile
- from pycs.projects.MediaFile import MediaFile
- class VideoFile(MediaFile):
- def __init__(self, obj, project, type='data'):
-
- obj['type'] = 'video'
-
- super().__init__(obj, project, type)
-
- self.__thumbnail = self.__read_video()
- def __read_video(self):
-
- copy = self.copy()
- copy['extension'] = '.jpg'
- resized = ImageFile(copy, self.project, 'temp')
-
- video = cv2.VideoCapture(self.path)
-
- self['fps'] = video.get(cv2.CAP_PROP_FPS)
- self['frameCount'] = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
-
- if not exists(resized.path):
- _, image = video.read()
- cv2.imwrite(resized.path, image)
-
- video.release()
-
- return resized
- def resize(self, maximum_width):
- return self.__thumbnail.resize(maximum_width)
|