mirror of
https://github.com/mpv-player/mpv
synced 2024-09-09 01:16:56 +02:00
sd_lavc: strictly letter-box PGS subtitles
Getting subtitle scaling and positioning right even if there are video filters, which completely change the image (like cropping), doesn't seem to have a single, correct solution. To some degree, the results are arbitrary, so we may as well do what is most useful to the user. In this case, if the PGS resolution aspect ratio and the video output aspect ratio mismatch, letter-box it, instead of stretching the subs over the video frame. (This will require additional fixes, should it turn out that there are PGS subtitles which are stretched by design.) Fixes #1205.
This commit is contained in:
parent
38420eb49e
commit
bcc3d72995
@ -344,7 +344,7 @@ void mp_nav_get_highlight(void *priv, struct mp_osd_res res,
|
|||||||
if (out_imgs->num_parts) {
|
if (out_imgs->num_parts) {
|
||||||
out_imgs->parts = nav->outputs;
|
out_imgs->parts = nav->outputs;
|
||||||
out_imgs->format = SUBBITMAP_RGBA;
|
out_imgs->format = SUBBITMAP_RGBA;
|
||||||
osd_rescale_bitmaps(out_imgs, sizes[0], sizes[1], res, -1);
|
osd_rescale_bitmaps(out_imgs, sizes[0], sizes[1], res, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&nav->osd_lock);
|
pthread_mutex_unlock(&nav->osd_lock);
|
||||||
|
@ -466,8 +466,9 @@ struct mp_osd_res osd_get_vo_res(struct osd_state *osd, int obj)
|
|||||||
// Position the subbitmaps in imgs on the screen. Basically, this fits the
|
// Position the subbitmaps in imgs on the screen. Basically, this fits the
|
||||||
// subtitle canvas (of size frame_w x frame_h) onto the screen, such that it
|
// subtitle canvas (of size frame_w x frame_h) onto the screen, such that it
|
||||||
// fills the whole video area (especially if the video is magnified, e.g. on
|
// fills the whole video area (especially if the video is magnified, e.g. on
|
||||||
// fullscreen). If compensate_par is given, adjust the way the subtitles are
|
// fullscreen). If compensate_par is >0, adjust the way the subtitles are
|
||||||
// "stretched" on the screen, and letter-box the result.
|
// "stretched" on the screen, and letter-box the result. If compensate_par
|
||||||
|
// is <0, strictly letter-box the subtitles. If it is 0, stretch them.
|
||||||
void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h,
|
void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h,
|
||||||
struct mp_osd_res res, double compensate_par)
|
struct mp_osd_res res, double compensate_par)
|
||||||
{
|
{
|
||||||
@ -475,6 +476,8 @@ void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h,
|
|||||||
int vidh = res.h - res.mt - res.mb;
|
int vidh = res.h - res.mt - res.mb;
|
||||||
double xscale = (double)vidw / frame_w;
|
double xscale = (double)vidw / frame_w;
|
||||||
double yscale = (double)vidh / frame_h;
|
double yscale = (double)vidh / frame_h;
|
||||||
|
if (compensate_par < 0)
|
||||||
|
compensate_par = xscale / yscale / res.display_par;
|
||||||
if (compensate_par > 0) {
|
if (compensate_par > 0) {
|
||||||
if (compensate_par > 1.0) {
|
if (compensate_par > 1.0) {
|
||||||
xscale /= compensate_par;
|
xscale /= compensate_par;
|
||||||
|
@ -292,7 +292,7 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts,
|
|||||||
priv->displayed_id = current->id;
|
priv->displayed_id = current->id;
|
||||||
res->format = SUBBITMAP_INDEXED;
|
res->format = SUBBITMAP_INDEXED;
|
||||||
|
|
||||||
double video_par = -1;
|
double video_par = 0;
|
||||||
if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE &&
|
if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE &&
|
||||||
opts->stretch_dvd_subs) {
|
opts->stretch_dvd_subs) {
|
||||||
// For DVD subs, try to keep the subtitle PAR at display PAR.
|
// For DVD subs, try to keep the subtitle PAR at display PAR.
|
||||||
@ -302,6 +302,8 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts,
|
|||||||
if (isnormal(par))
|
if (isnormal(par))
|
||||||
video_par = par;
|
video_par = par;
|
||||||
}
|
}
|
||||||
|
if (priv->avctx->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE)
|
||||||
|
video_par = -1;
|
||||||
int insize[2];
|
int insize[2];
|
||||||
get_resolution(sd, insize);
|
get_resolution(sd, insize);
|
||||||
osd_rescale_bitmaps(res, insize[0], insize[1], d, video_par);
|
osd_rescale_bitmaps(res, insize[0], insize[1], d, video_par);
|
||||||
|
Loading…
Reference in New Issue
Block a user