Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defaults for ASS track are wrong #2

Open
TheOneric opened this issue Feb 23, 2022 · 0 comments
Open

Defaults for ASS track are wrong #2

TheOneric opened this issue Feb 23, 2022 · 0 comments

Comments

@TheOneric
Copy link
Contributor

ASS has standard default values for those headers but ass_renderer assigns different ones. If those fields are linked with the actual C object from libass, i.e. the values are automatically updated when libass changes them, simply removing the custom defaults is the correct thing to do as libass will take care of it.
If not, and those fields are exposed/used somewhere (after #1 removes the usage as a bogus storage size) a patch similar to the following will emulate the correct fallbacks:

From 9c921570adae3bcdbdffc7b782be1ec5accf2edf Mon Sep 17 00:00:00 2001
From: Oneric <oneric@oneric.stub>
Date: Wed, 16 Feb 2022 19:38:24 +0100
Subject: [PATCH] Fix default values for ASS headers

 - ScaledBorderAndShadow defaults to no
 - WrapStyle defaults to 0 ("smart" mode)
 - PlayRes{X,Y} has obscure fallback values
---
 ass_renderer/libass.py | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/ass_renderer/libass.py b/ass_renderer/libass.py
index 0cad674..b714057 100644
--- a/ass_renderer/libass.py
+++ b/ass_renderer/libass.py
@@ -369,16 +369,26 @@ class AssTrack(ctypes.Structure):
         text = write_ass(ass_file).encode("utf-8")
         _libass.ass_process_data(ctypes.byref(self), text, len(text))
 
-        self.play_res_x = int(
-            ass_file.script_info.get("PlayResX") or video_resolution[0]
+        self.wrap_style = int(ass_file.script_info.get("WrapStyle") or 0)
+        self.scaled_border_and_shadow = (
+            ass_file.script_info.get("ScaledBorderAndShadow", "no") == "yes"
         )
-        self.play_res_y = int(
-            ass_file.script_info.get("PlayResY") or video_resolution[1]
+        res_x = int(
+            ass_file.script_info.get("PlayResX") or 0
         )
-        self.wrap_style = int(ass_file.script_info.get("WrapStyle") or 1)
-        self.scaled_border_and_shadow = (
-            ass_file.script_info.get("ScaledBorderAndShadow", "yes") == "yes"
+        res_y = int(
+            ass_file.script_info.get("PlayResY") or 0
         )
+        if res_x <= 0 and res_y <= 0:
+            res_x = 384
+            res_y = 288
+        elif res_x <= 0:
+            res_x = 1280 if res_y == 1024 else max(1, res_y * 4 // 3)
+        elif res_y <= 0:
+            res_y = 1024 if res_x == 1280 else max(1, res_x * 3 // 4)
+        self.play_res_x = res_x
+        self.play_res_y = res_y
+
 
 
 _libc.free.argtypes = [ctypes.c_void_p]
-- 
2.30.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant