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:
2
README
2
README
@@ -8,4 +8,4 @@ pip packages:
|
|||||||
* pymediainfo
|
* pymediainfo
|
||||||
* PIL (should be there by default)
|
* PIL (should be there by default)
|
||||||
* ExifRead
|
* ExifRead
|
||||||
*
|
* opencv-python
|
||||||
|
|||||||
20
files.py
20
files.py
@@ -13,6 +13,7 @@ import hashlib
|
|||||||
import exifread
|
import exifread
|
||||||
import base64
|
import base64
|
||||||
import numpy
|
import numpy
|
||||||
|
import cv2
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Local Class imports
|
# Local Class imports
|
||||||
@@ -76,6 +77,24 @@ class FileData():
|
|||||||
except:
|
except:
|
||||||
return False
|
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 #
|
# HACK: At present this only handles one path (need to re-factor if we have #
|
||||||
# multiple valid paths in import_path) #
|
# multiple valid paths in import_path) #
|
||||||
@@ -106,6 +125,7 @@ class FileData():
|
|||||||
fthumbnail = self.getExif(file)
|
fthumbnail = self.getExif(file)
|
||||||
elif self.isVideo(file):
|
elif self.isVideo(file):
|
||||||
ftype = 'Video'
|
ftype = 'Video'
|
||||||
|
fthumbnail = self.generateVideoThumbnail(file)
|
||||||
else:
|
else:
|
||||||
ftype = 'File'
|
ftype = 'File'
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
{% if obj.type=="Image" %}
|
{% 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>
|
<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" %}
|
{% 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 %}
|
{% endif %}
|
||||||
<figcaption class="figure-caption text-center">{{obj.name}}</figcaption>
|
<figcaption class="figure-caption text-center">{{obj.name}}</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
|
|||||||
Reference in New Issue
Block a user