Compare commits
3 Commits
23de915b82
...
760587c20b
Author | SHA1 | Date | |
---|---|---|---|
|
760587c20b | ||
|
ce016cc451 | ||
|
fb1b1bb71f |
@ -6,7 +6,7 @@ from frame_forge.utils import exit_application
|
|||||||
|
|
||||||
|
|
||||||
program_name = "FrameForge"
|
program_name = "FrameForge"
|
||||||
__version__ = "1.0.2"
|
__version__ = "1.0.3"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -26,7 +26,7 @@ if __name__ == "__main__":
|
|||||||
help="Indexer choice",
|
help="Indexer choice",
|
||||||
)
|
)
|
||||||
parser.add_argument("--index-dir", type=str, help="Path to look/create indexes")
|
parser.add_argument("--index-dir", type=str, help="Path to look/create indexes")
|
||||||
parser.add_argument("--sub-size", type=int, help="Size of subtitles")
|
parser.add_argument("--sub-size", type=int, default=20, help="Size of subtitles")
|
||||||
parser.add_argument("--left-crop", type=int, help="Left crop")
|
parser.add_argument("--left-crop", type=int, help="Left crop")
|
||||||
parser.add_argument("--right-crop", type=int, help="Right crop")
|
parser.add_argument("--right-crop", type=int, help="Right crop")
|
||||||
parser.add_argument("--top-crop", type=int, help="Top crop")
|
parser.add_argument("--top-crop", type=int, help="Top crop")
|
||||||
|
@ -8,7 +8,6 @@ from unidecode import unidecode
|
|||||||
import awsmfunc
|
import awsmfunc
|
||||||
import vapoursynth as vs
|
import vapoursynth as vs
|
||||||
from frame_forge.exceptions import FrameForgeError
|
from frame_forge.exceptions import FrameForgeError
|
||||||
from frame_forge.font_scaler import FontScaler
|
|
||||||
from frame_forge.utils import get_working_dir, hex_to_bgr
|
from frame_forge.utils import get_working_dir, hex_to_bgr
|
||||||
|
|
||||||
|
|
||||||
@ -71,9 +70,10 @@ class GenerateImages:
|
|||||||
num_source_frames = len(self.source_node)
|
num_source_frames = len(self.source_node)
|
||||||
num_encode_frames = len(self.encode_node)
|
num_encode_frames = len(self.encode_node)
|
||||||
|
|
||||||
# Format: Name, Fontname, Font-size, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic,
|
# ASS subtitle styles
|
||||||
# Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL,
|
# Font Name, Font Size, Primary Color, Secondary Color, Outline Color, Back Color, Bold,
|
||||||
# MarginR, MarginV,
|
# Italic, Underline, Strikeout, Scale X, Scale Y, Spacing, Angle, Border Style, Outline Width,
|
||||||
|
# Shadow Depth, Alignment, Left Margin, Right Margin, Vertical Margin, Encoding
|
||||||
|
|
||||||
# bgr color
|
# bgr color
|
||||||
color = "&H000ac7f5"
|
color = "&H000ac7f5"
|
||||||
@ -82,11 +82,17 @@ class GenerateImages:
|
|||||||
|
|
||||||
selected_sub_style = (
|
selected_sub_style = (
|
||||||
f"Segoe UI,{self.sub_size},{color},&H00000000,&H00000000,&H00000000,"
|
f"Segoe UI,{self.sub_size},{color},&H00000000,&H00000000,&H00000000,"
|
||||||
"1,0,0,0,100,100,0,0,1,1,0,7,5,0,0,1"
|
"1,0,0,0,100,100,0,0,1,1,0,7,10,10,10,1"
|
||||||
)
|
)
|
||||||
|
sync_sub_base = (
|
||||||
selected_sub_style_ref, selected_sub_style_sync = self.sync_font_scaling(
|
"Segoe UI,{size},&H31FF31&,&H00000000,&H00000000,&H00000000,"
|
||||||
num_source_frames=num_source_frames, scaling_factor=1.35
|
"1,0,0,0,100,100,0,0,1,1,0,{pos},10,10,10,1"
|
||||||
|
)
|
||||||
|
selected_sub_style_ref = sync_sub_base.format(
|
||||||
|
size=str(self.sub_size + 5), pos="7"
|
||||||
|
)
|
||||||
|
selected_sub_style_sync = sync_sub_base.format(
|
||||||
|
size=str(self.sub_size + 5), pos="9"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.check_de_interlaced(num_source_frames, num_encode_frames)
|
self.check_de_interlaced(num_source_frames, num_encode_frames)
|
||||||
@ -122,30 +128,6 @@ class GenerateImages:
|
|||||||
flush=True,
|
flush=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def sync_font_scaling(
|
|
||||||
self, num_source_frames, scaling_factor: float
|
|
||||||
) -> Tuple[str, str]:
|
|
||||||
calculate_str_len = max(
|
|
||||||
len("frame: reference"), len(str(f"frame: {num_source_frames}"))
|
|
||||||
)
|
|
||||||
sync_size_offset = 5
|
|
||||||
scale_position = FontScaler().get_adjusted_scale(
|
|
||||||
self.sub_size + sync_size_offset, scaling_factor
|
|
||||||
)
|
|
||||||
calculate_right_subs = int(
|
|
||||||
self.source_node.width
|
|
||||||
- ((calculate_str_len + self.sub_size + sync_size_offset) * scale_position)
|
|
||||||
)
|
|
||||||
selected_sub_style_ref = (
|
|
||||||
f"Segoe UI,{self.sub_size + sync_size_offset},&H31FF31&,&H00000000,&H00000000,&H00000000,"
|
|
||||||
f"1,0,0,0,100,100,0,0,1,1,0,7,5,0,0,1"
|
|
||||||
)
|
|
||||||
selected_sub_style_sync = (
|
|
||||||
f"Segoe UI,{self.sub_size + sync_size_offset},&H31FF31&,&H00000000,&H00000000,&H00000000,"
|
|
||||||
f"1,0,0,0,100,100,0,0,1,1,0,7,{calculate_right_subs},0,0,1"
|
|
||||||
)
|
|
||||||
return selected_sub_style_ref, selected_sub_style_sync
|
|
||||||
|
|
||||||
def generate_ref_screens(
|
def generate_ref_screens(
|
||||||
self, selected_sub_style_ref, frames: list, screenshot_sync_dir
|
self, selected_sub_style_ref, frames: list, screenshot_sync_dir
|
||||||
):
|
):
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
import math
|
|
||||||
|
|
||||||
|
|
||||||
class FontScaler:
|
|
||||||
def __init__(self, original_font_size=100, original_scale=3.5):
|
|
||||||
self.original_font_size = original_font_size
|
|
||||||
self.original_scale = original_scale
|
|
||||||
|
|
||||||
def calculate_scale_factor(self, desired_font_size):
|
|
||||||
"""Calculate the scale factor based on the desired font size."""
|
|
||||||
return math.log(desired_font_size) / math.log(self.original_font_size)
|
|
||||||
|
|
||||||
def adjust_scale_factor(self, scale_factor, multiplier):
|
|
||||||
"""Adjust the scale factor with a multiplier."""
|
|
||||||
return scale_factor * multiplier
|
|
||||||
|
|
||||||
def scale_font(self, scale_factor):
|
|
||||||
"""Scale the font size based on the original scale and scale factor."""
|
|
||||||
return self.original_scale * scale_factor
|
|
||||||
|
|
||||||
def get_adjusted_scale(self, desired_font_size, multiplier=1.0):
|
|
||||||
"""Get the adjusted font scale based on the desired font size and multiplier."""
|
|
||||||
scale_factor = self.calculate_scale_factor(desired_font_size)
|
|
||||||
adjusted_scale_factor = self.adjust_scale_factor(scale_factor, multiplier)
|
|
||||||
return self.scale_font(adjusted_scale_factor)
|
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "frame-forge"
|
name = "frame-forge"
|
||||||
version = "1.0.2"
|
version = "1.0.3"
|
||||||
description = "CLI to offload image generation to"
|
description = "CLI to offload image generation to"
|
||||||
authors = ["jlw4049 <jlw_4049@hotmail.com>"]
|
authors = ["jlw4049 <jlw_4049@hotmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
Loading…
Reference in New Issue
Block a user