|
|
from dataclasses import dataclass |
|
|
from typing import Tuple, Literal |
|
|
import os |
|
|
from src.config import get_config_value |
|
|
|
|
|
@dataclass |
|
|
class SafeZone: |
|
|
STANDARD_WIDTH = 1080 |
|
|
STANDARD_HEIGHT = 1920 |
|
|
|
|
|
|
|
|
|
|
|
TOP_SAFE_ZONE = 252 |
|
|
BOTTOM_SAFE_ZONE = 756 |
|
|
LEFT_SAFE_ZONE = 120 |
|
|
RIGHT_SAFE_ZONE = 240 |
|
|
|
|
|
@staticmethod |
|
|
def set_safe_zone_from_env(): |
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
def get_caption_position( |
|
|
video_width: int, |
|
|
video_height: int, |
|
|
caption_height: int, |
|
|
position: Literal["top", "center", "bottom"] = "bottom", |
|
|
padding: int = 20 |
|
|
) -> Tuple[str, int]: |
|
|
SafeZone.set_safe_zone_from_env() |
|
|
|
|
|
scale_y = video_height / SafeZone.STANDARD_HEIGHT |
|
|
|
|
|
|
|
|
top_safe = int(SafeZone.TOP_SAFE_ZONE * scale_y) |
|
|
bottom_safe = int(SafeZone.BOTTOM_SAFE_ZONE * scale_y) |
|
|
|
|
|
if position == "top": |
|
|
y_position = top_safe + padding |
|
|
|
|
|
elif position == "center": |
|
|
safe_area_height = video_height - top_safe - bottom_safe |
|
|
y_position = top_safe + (safe_area_height - caption_height) // 2 |
|
|
|
|
|
else: |
|
|
y_position = video_height - bottom_safe - caption_height - padding |
|
|
|
|
|
return ("center", y_position) |
|
|
|
|
|
@staticmethod |
|
|
def get_safe_area_bounds( |
|
|
video_width: int, |
|
|
video_height: int |
|
|
) -> dict: |
|
|
SafeZone.set_safe_zone_from_env() |
|
|
scale_y = video_height / SafeZone.STANDARD_HEIGHT |
|
|
scale_x = video_width / SafeZone.STANDARD_WIDTH |
|
|
|
|
|
top = int(SafeZone.TOP_SAFE_ZONE * scale_y) |
|
|
bottom = video_height - int(SafeZone.BOTTOM_SAFE_ZONE * scale_y) |
|
|
left = int(SafeZone.LEFT_SAFE_ZONE * scale_x) |
|
|
right = video_width - int(SafeZone.RIGHT_SAFE_ZONE * scale_x) |
|
|
|
|
|
return { |
|
|
'top': top, |
|
|
'bottom': bottom, |
|
|
'left': left, |
|
|
'right': right, |
|
|
'width': right - left, |
|
|
'height': bottom - top |
|
|
} |