|
@@ -1,4 +1,4 @@
|
|
|
-from os.path import splitext, join, exists
|
|
|
+from os.path import exists
|
|
|
|
|
|
import cv2
|
|
|
|
|
@@ -7,44 +7,40 @@ from pycs.projects.MediaFile import MediaFile
|
|
|
|
|
|
|
|
|
class VideoFile(MediaFile):
|
|
|
- def __init__(self, obj, project_id):
|
|
|
+ def __init__(self, obj, project_id, type='data'):
|
|
|
# add type to object
|
|
|
obj['type'] = 'video'
|
|
|
|
|
|
# call parent constructor
|
|
|
- super().__init__(obj, project_id)
|
|
|
+ super().__init__(obj, project_id, type)
|
|
|
|
|
|
# generate thumbnail
|
|
|
self.__thumbnail = self.__read_video()
|
|
|
|
|
|
def __read_video(self):
|
|
|
- # determine some properties
|
|
|
- path, name = self.get_file()
|
|
|
+ # create image file from properties
|
|
|
+ copy = self.copy()
|
|
|
+ copy['extension'] = '.jpg'
|
|
|
|
|
|
- file_name, file_ext = splitext(name)
|
|
|
- video_path = join(path, name)
|
|
|
- image_path = join(path, f'{file_name}.jpg')
|
|
|
+ resized = ImageFile(copy, self.project_id, 'temp')
|
|
|
|
|
|
# open video file
|
|
|
- video = cv2.VideoCapture(video_path)
|
|
|
+ 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(image_path):
|
|
|
+ if not exists(resized.path):
|
|
|
_, image = video.read()
|
|
|
- cv2.imwrite(image_path, image)
|
|
|
+ cv2.imwrite(resized.path, image)
|
|
|
|
|
|
# close video file
|
|
|
video.release()
|
|
|
|
|
|
- # return ImageFile from thumbnail
|
|
|
- copy = self.copy()
|
|
|
- copy['extension'] = '.jpg'
|
|
|
-
|
|
|
- return ImageFile(copy, self.project_id)
|
|
|
+ # return
|
|
|
+ return resized
|
|
|
|
|
|
def resize(self, maximum_width):
|
|
|
return self.__thumbnail.resize(maximum_width)
|