add/improve refreshing logic & metadata management, improve thumbnail logic & regenerate kwarg, overall more documentation/commands

This commit is contained in:
Xevion
2020-11-03 18:26:12 -06:00
parent ed3e656ee8
commit 09e82944d7
2 changed files with 54 additions and 9 deletions

View File

@@ -3,6 +3,8 @@ helpers.py
Contains helper functions used as refactored shortcuts or in order to separate code for readability.
"""
from typing import Tuple
import cv2
from PIL import Image
@@ -14,8 +16,8 @@ def generate_thumbnail(path: str, output_path: str) -> None:
:param path: The absolute path to the file.
:param output_path: The absolute path to the intended output thumbnail file.
"""
vidcap = cv2.VideoCapture(path)
success, image = vidcap.read()
file = cv2.VideoCapture(path)
success, image = file.read()
if success:
img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
im_pil = Image.fromarray(img)
@@ -26,3 +28,13 @@ def generate_thumbnail(path: str, output_path: str) -> None:
# im_pil.resize((200, 66))
im_pil.save(output_path)
def get_resolution(path: str) -> Tuple[int, int]:
"""
Retrieves the resolution of a image or video
:return: A tuple containing two positive integers representing width and height
"""
file = cv2.VideoCapture(path)
return file.get(cv2.CAP_PROP_FRAME_HEIGHT), file.get(cv2.CAP_PROP_FRAME_WIDTH)