From b6db99a3930b609ca1ba5a0b9930b5c6dc5701dc Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 9 Sep 2022 01:01:52 +0200 Subject: render: improve storage res fallback when PAR is set When storage size is not set, we currently use PlayRes as a fallback hoping it matches the original storage res. We know this is flawed, but even if PlayRes relates to a dimension of the source video, in case of anamorphic video either the native display width or storage width may have been used. We always want the latter, so if PAR information was supplied, try to ensure we get something in the storage aspect ratio. Note, that this could actually also worsen the rendering for unknown storage res cases eg if PlayRes already was the original storage size but the subs got repurposed for a non-anamorphic (re)encode. Though, such reused subs won't render correctly in VSFilter too anyway, so we probably don't need to worry to much about this. --- libass/ass_render.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libass/ass_render.c b/libass/ass_render.c index 15ce092..682c588 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -978,7 +978,21 @@ ASS_Vector ass_layout_res(ASS_Renderer *render_priv) return (ASS_Vector) { settings->storage_width, settings->storage_height }; ASS_Track *track = render_priv->track; - return (ASS_Vector) { track->PlayResX, track->PlayResY }; + if (settings->par <= 0 || settings->par == 1 || + !render_priv->orig_width || !render_priv->orig_height) + return (ASS_Vector) { track->PlayResX, track->PlayResY }; + if (settings->par > 1) + return (ASS_Vector) { + lround(track->PlayResY * render_priv->orig_width / render_priv->orig_height + / settings->par), + track->PlayResY + }; + else + return (ASS_Vector) { + track->PlayResX, + lround(track->PlayResX * render_priv->orig_height / render_priv->orig_width + * settings->par) + }; } static void init_font_scale(ASS_Renderer *render_priv) -- cgit v1.2.3