Fixed BUG-19 - video thumbs being out of ratio, using THUMBSIZE in shared.py to also make sure images and videos have at least one of their width / height be 256 in their thumbnail
This commit is contained in:
6
BUGs
6
BUGs
@@ -1,7 +1 @@
|
|||||||
### Next: 21
|
### Next: 21
|
||||||
BUG-20: (many) video thumbnails are actually taken in portrait, but the thumbnail is 128x128, if I hand reset it to 72x128 (which seems like my cameras vid ratio, they look much better)
|
|
||||||
- so need to know video is rotated and adjust width OR, do width right from start somehow
|
|
||||||
-- see: 20180612_104826.mp4:
|
|
||||||
20180612_104826.mp4[1] MP4 1080x1920 1080x1920+0+0 8-bit TrueColor sRGB 9.160u 0:44.030
|
|
||||||
(its obvious if its 1080 x 1920, its in portrait)
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ from sqlalchemy.orm import scoped_session
|
|||||||
|
|
||||||
### LOCAL FILE IMPORTS ###
|
### LOCAL FILE IMPORTS ###
|
||||||
|
|
||||||
from shared import DB_URL, PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT
|
from shared import DB_URL, PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT, THUMBSIZE
|
||||||
from datetime import datetime, timedelta, date
|
from datetime import datetime, timedelta, date
|
||||||
import pytz
|
import pytz
|
||||||
import time
|
import time
|
||||||
@@ -750,7 +750,7 @@ def GenImageThumbnail(job, file):
|
|||||||
try:
|
try:
|
||||||
im_orig = Image.open(file)
|
im_orig = Image.open(file)
|
||||||
im = ImageOps.exif_transpose(im_orig)
|
im = ImageOps.exif_transpose(im_orig)
|
||||||
im.thumbnail((256,256))
|
im.thumbnail((THUMBSIZE,THUMBSIZE))
|
||||||
img_bytearray = io.BytesIO()
|
img_bytearray = io.BytesIO()
|
||||||
im.save(img_bytearray, format='JPEG')
|
im.save(img_bytearray, format='JPEG')
|
||||||
img_bytearray = img_bytearray.getvalue()
|
img_bytearray = img_bytearray.getvalue()
|
||||||
@@ -766,11 +766,21 @@ def GenVideoThumbnail(job, file):
|
|||||||
AddLogForJob( job, "Generate Thumbnail from Video file: {}".format( file ), file )
|
AddLogForJob( job, "Generate Thumbnail from Video file: {}".format( file ), file )
|
||||||
try:
|
try:
|
||||||
vcap = cv2.VideoCapture(file)
|
vcap = cv2.VideoCapture(file)
|
||||||
res, im_ar = vcap.read()
|
res, frame = vcap.read()
|
||||||
while im_ar.mean() < 15 and res:
|
# if the mean pixel value is > 15, we have something worth making a sshot of (no black frame at start being the sshot)
|
||||||
res, im_ar = vcap.read()
|
while frame.mean() < 15 and res:
|
||||||
im_ar = cv2.resize(im_ar, (160, 90), 0, 0, cv2.INTER_LINEAR)
|
res, frame = vcap.read()
|
||||||
res, thumb_buf = cv2.imencode('.jpeg', im_ar)
|
w = vcap.get(cv2.cv2.CAP_PROP_FRAME_WIDTH)
|
||||||
|
h = vcap.get(cv2.cv2.CAP_PROP_FRAME_HEIGHT)
|
||||||
|
if w > h:
|
||||||
|
factor = w / THUMBSIZE
|
||||||
|
else:
|
||||||
|
factor = h / THUMBSIZE
|
||||||
|
new_h = int(h / factor)
|
||||||
|
new_w = int(w / factor)
|
||||||
|
frame = cv2.resize(frame, (new_w, new_h), 0, 0, cv2.INTER_LINEAR)
|
||||||
|
|
||||||
|
res, thumb_buf = cv2.imencode('.jpeg', frame)
|
||||||
bt = thumb_buf.tobytes()
|
bt = thumb_buf.tobytes()
|
||||||
thumbnail = base64.b64encode(bt)
|
thumbnail = base64.b64encode(bt)
|
||||||
thumbnail = str(thumbnail)[2:-1]
|
thumbnail = str(thumbnail)[2:-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user