mirror of
https://github.com/mpv-player/mpv
synced 2025-05-06 02:00:05 +00:00
sd_ass, sd_lavc: use the input video's pixel aspect for scaling subtitles.
The previous code used the output video's pixel aspect for stretching purposes, breaking rendering with e.g. -vf scale in the chain. Now subtitles are stretched using the input video's pixel aspect only, matching the intentions of the original subtitle author.
This commit is contained in:
parent
dbb7927a1e
commit
49caa0a775
@ -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 ||
|
if (!ctx->is_converted && (!opts->ass_style_override ||
|
||||||
opts->ass_vsfilter_aspect_compat))
|
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);
|
mp_ass_configure(renderer, opts, &dim);
|
||||||
ass_set_aspect_ratio(renderer, scale, 1);
|
ass_set_aspect_ratio(renderer, scale, 1);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "mpvcore/av_common.h"
|
#include "mpvcore/av_common.h"
|
||||||
#include "mpvcore/options.h"
|
#include "mpvcore/options.h"
|
||||||
#include "demux/stheader.h"
|
#include "demux/stheader.h"
|
||||||
|
#include "video/mp_image.h"
|
||||||
#include "sd.h"
|
#include "sd.h"
|
||||||
#include "dec_sub.h"
|
#include "dec_sub.h"
|
||||||
#include "sub.h"
|
#include "sub.h"
|
||||||
@ -41,6 +42,7 @@ struct sd_lavc_priv {
|
|||||||
bool bitmaps_changed;
|
bool bitmaps_changed;
|
||||||
double pts;
|
double pts;
|
||||||
double endpts;
|
double endpts;
|
||||||
|
struct mp_image_params video_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool supports_format(const char *format)
|
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;
|
double yscale = (double)vidh / inh;
|
||||||
if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
|
if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
|
||||||
// For DVD subs, try to keep the subtitle PAR at display PAR.
|
// For DVD subs, try to keep the subtitle PAR at display PAR.
|
||||||
if (d.video_par > 1.0) {
|
double video_par =
|
||||||
xscale /= d.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 {
|
} else {
|
||||||
yscale *= d.video_par;
|
yscale *= video_par;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int cx = vidw / 2 - (int)(inw * xscale) / 2;
|
int cx = vidw / 2 - (int)(inw * xscale) / 2;
|
||||||
@ -268,12 +273,25 @@ static void uninit(struct sd *sd)
|
|||||||
talloc_free(priv);
|
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 = {
|
const struct sd_functions sd_lavc = {
|
||||||
.name = "lavc",
|
.name = "lavc",
|
||||||
.supports_format = supports_format,
|
.supports_format = supports_format,
|
||||||
.init = init,
|
.init = init,
|
||||||
.decode = decode,
|
.decode = decode,
|
||||||
.get_bitmaps = get_bitmaps,
|
.get_bitmaps = get_bitmaps,
|
||||||
|
.control = control,
|
||||||
.reset = reset,
|
.reset = reset,
|
||||||
.uninit = uninit,
|
.uninit = uninit,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user