diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 591f9d5105..fd545cdbda 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -142,7 +142,10 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts, if (!ctx->is_converted && (!opts->ass_style_override || opts->ass_vsfilter_aspect_compat)) { - scale = scale * dim.video_par; + // Let's use the original video PAR for vsfilter compatibility: + scale = scale + * (ctx->video_params.d_w / (double)ctx->video_params.d_h) + / (ctx->video_params.w / (double)ctx->video_params.h); } mp_ass_configure(renderer, opts, &dim); ass_set_aspect_ratio(renderer, scale, 1); diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index b03861025d..2cce6ea4cd 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -26,6 +26,7 @@ #include "mpvcore/av_common.h" #include "mpvcore/options.h" #include "demux/stheader.h" +#include "video/mp_image.h" #include "sd.h" #include "dec_sub.h" #include "sub.h" @@ -41,6 +42,7 @@ struct sd_lavc_priv { bool bitmaps_changed; double pts; double endpts; + struct mp_image_params video_params; }; static bool supports_format(const char *format) @@ -223,10 +225,13 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts, double yscale = (double)vidh / inh; if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE) { // For DVD subs, try to keep the subtitle PAR at display PAR. - if (d.video_par > 1.0) { - xscale /= d.video_par; + double video_par = + (priv->video_params.d_w / (double)priv->video_params.d_h) + / (priv->video_params.w / (double)priv->video_params.h); + if (video_par > 1.0) { + xscale /= video_par; } else { - yscale *= d.video_par; + yscale *= video_par; } } int cx = vidw / 2 - (int)(inw * xscale) / 2; @@ -268,12 +273,25 @@ static void uninit(struct sd *sd) talloc_free(priv); } +static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) +{ + struct sd_lavc_priv *priv = sd->priv; + switch (cmd) { + case SD_CTRL_SET_VIDEO_PARAMS: + priv->video_params = *(struct mp_image_params *)arg; + return CONTROL_OK; + default: + return CONTROL_UNKNOWN; + } +} + const struct sd_functions sd_lavc = { .name = "lavc", .supports_format = supports_format, .init = init, .decode = decode, .get_bitmaps = get_bitmaps, + .control = control, .reset = reset, .uninit = uninit, };