I'm trying to store an image from a video file in django in the save method of a model. I've based in on this thread
This is my save method for the model
def save(self, *args, **kwargs):
if not self.slug:
orig = self.slug = slugify(unidecode(self.name))
for x in itertools.count(1):
if not Project.objects.filter(slug=self.slug).exists() or (Project.objects.filter(slug=self.slug).exists() and self == Project.objects.get(slug=self.slug)):
break
self.slug = '%s-%d' % (orig, x)
super(Project, self).save(*args, **kwargs)
if not self.image and self.project_type=='video':
vidcap = cv2.VideoCapture(settings.MEDIA_ROOT + self.video.url)
success,image = vidcap.read()
self.image = image
self.image.name = 'video_images/' + self.slug + '.jpg'
new_path = settings.MEDIA_ROOT + self.image.name
cv2.imwrite(new_path, image)
super(Project, self).save(*args, **kwargs)
I've taken a look at success
and it always comes out False
(I've tried looping while not success
and it eventually timesout)