diff --git a/BUGs b/BUGs index e9de2a0..1957c97 100644 --- a/BUGs +++ b/BUGs @@ -1,7 +1 @@ ### 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) - diff --git a/pa_job_manager.py b/pa_job_manager.py index 4b1a76b..93637ed 100644 --- a/pa_job_manager.py +++ b/pa_job_manager.py @@ -25,7 +25,7 @@ from sqlalchemy.orm import scoped_session ### 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 import pytz import time @@ -750,7 +750,7 @@ def GenImageThumbnail(job, file): try: im_orig = Image.open(file) im = ImageOps.exif_transpose(im_orig) - im.thumbnail((256,256)) + im.thumbnail((THUMBSIZE,THUMBSIZE)) img_bytearray = io.BytesIO() im.save(img_bytearray, format='JPEG') img_bytearray = img_bytearray.getvalue() @@ -766,11 +766,21 @@ def GenVideoThumbnail(job, file): AddLogForJob( job, "Generate Thumbnail from Video file: {}".format( file ), file ) try: 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) - res, thumb_buf = cv2.imencode('.jpeg', im_ar) + res, frame = vcap.read() + # if the mean pixel value is > 15, we have something worth making a sshot of (no black frame at start being the sshot) + while frame.mean() < 15 and res: + res, frame = vcap.read() + 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() thumbnail = base64.b64encode(bt) thumbnail = str(thumbnail)[2:-1] diff --git a/shared.py b/shared.py index dbf05e9..3ab59b2 100644 --- a/shared.py +++ b/shared.py @@ -9,3 +9,5 @@ if hostname == PROD_HOST: else: PA_JOB_MANAGER_HOST="localhost" PA_JOB_MANAGER_PORT=55430 + +THUMBSIZE=256