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'):
- # add type to object
- obj['type'] = 'video'
- # call parent constructor
- super().__init__(obj, project, type)
- # generate thumbnail
- self.__thumbnail = self.__read_video()
- def __read_video(self):
- # create image file from properties
- copy = self.copy()
- copy['extension'] = '.jpg'
- resized = ImageFile(copy, self.project, 'temp')
- # open video file
- video = cv2.VideoCapture(self.path)
- # read fps value
- self['fps'] = video.get(cv2.CAP_PROP_FPS)
- self['frameCount'] = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
- # create thumbnail
- if not exists(resized.path):
- _, image = video.read()
- cv2.imwrite(resized.path, image)
- # close video file
- video.release()
- # return
- return resized
- def resize(self, maximum_width):
- return self.__thumbnail.resize(maximum_width)
|