Hi I am extracting frames from video and want to store these frames into database using Django. Here is my code :
def saveFrame(request):
video = Video.objects.last()
path = os.path.dirname(__file__)
path = path.replace('videos',video.video.url)
clip = VideoFileClip(path)
clip = clip.subclip(0, 15)
clip = clip.cutout(3, 10)
clip.ipython_display(width = 360)
cap= cv2.VideoCapture('__temp__.mp4')
i=0
image = Image()
while(cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break
image.video_id = video
image.title = video.title +str(i)
image.imagefile = frame
image.save()
print(i)
i+=1
cap.release()
cv2.destroyAllWindows()
When I run this code i recieve this error :
Error in image.save()
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() Here is my Image Class that I created in model.py:
Class Image(models.Model):
video_id = models.ForeignKey(Video,
on_delete=models.CASCADE,null="false")
title= models.CharField(max_length=50)
imagefile= models.FileField(upload_to='images/', null=True)
def __str__(self):
return self.video_id + ": " +self.title+ ": " +
str(self.imagefile)
Can anyone help me with this issue so I can save images into database.