Merge branch 'master' of 192.168.0.2:photoassistant

BUT, the thumbnails for the videos are fixed ratios, so the resizing doesnt work for them.. Odd
This commit is contained in:
2021-01-12 01:48:11 +11:00
3 changed files with 22 additions and 2 deletions

2
README
View File

@@ -8,4 +8,4 @@ pip packages:
* pymediainfo
* PIL (should be there by default)
* ExifRead
*
* opencv-python

View File

@@ -13,6 +13,7 @@ import hashlib
import exifread
import base64
import numpy
import cv2
################################################################################
# Local Class imports
@@ -76,6 +77,24 @@ class FileData():
except:
return False
def generateVideoThumbnail(self, file):
#overall wrapper function for generating video thumbnails
vcap = cv2.VideoCapture(file)
res, im_ar = vcap.read()
while im_ar.mean() < 15 and res:
res, im_ar = vcap.read()
im_ar = cv2.resize(im_ar, (160, 90), 0, 0, cv2.INTER_LINEAR)
#save on a buffer for direct transmission
res, thumb_buf = cv2.imencode('.jpeg', im_ar)
# '.jpeg' etc are permitted
#get the bytes content
bt = thumb_buf.tostring()
fthumbnail = base64.b64encode(bt)
fthumbnail = str(fthumbnail)[2:-1]
print(fthumbnail)
return fthumbnail
##############################################################################
# HACK: At present this only handles one path (need to re-factor if we have #
# multiple valid paths in import_path) #
@@ -106,6 +125,7 @@ class FileData():
fthumbnail = self.getExif(file)
elif self.isVideo(file):
ftype = 'Video'
fthumbnail = self.generateVideoThumbnail(file)
else:
ftype = 'File'

View File

@@ -30,7 +30,7 @@
{% if obj.type=="Image" %}
<a href="{{file_data.symlink}}/{{obj.name}}"><img class="thumb" height="128" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img></a>
{% elif obj.type == "Video" %}
<i style="font-size:128" class="thumb fas fa-file-video"></i>
<img height="128" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img>
{% endif %}
<figcaption class="figure-caption text-center">{{obj.name}}</figcaption>
</figure>