summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-16 23:04:21 +0200
committerwm4 <wm4@nowhere>2013-07-16 23:04:21 +0200
commit130866e2693ba08f7d00c404a3767f288d0c3faa (patch)
tree267a9413d3a921241762dee7139bd9bd5a8e1ead
parent3d439368a16310cf162d41bd9bd7047608b1b42c (diff)
downloadmpv-130866e2693ba08f7d00c404a3767f288d0c3faa.tar.bz2
mpv-130866e2693ba08f7d00c404a3767f288d0c3faa.tar.xz
sd_lavc: don't stretch DVD subtitles to video aspect
I'm not sure what's correct: stretching the DVD subtitles from storage aspect ratio to video display aspect ratio, or displaying subtitles using 1:1 PAR. Until now, DVD subtitles (as well as all other bitmap subtitles) were always stretched to the video. There are good arguments why this would be the correct behavior: DVDs were made for playback on TV, which display anamorphic video by adjusting the horizontal refresh rate, and thus wouldn't even be capable of DVD subtitles with square PAR (other than resampling the subtitles additionally). However, I haven't seen a sample yet where subtitles do _not_ look stretched using this method. Rendering them at 1:1 PAR looks better. Technically, we render them at display PAR (and not 1:1 PAR). Do this in a way so that the subtitle area is always inside of the video frame if display and video aspect ratios mismatch. For DVB subtitles, the old method looks more correct, so this is special cased to DVD subtitles. I might revert this commit if it turns out that it's an disimprovement.
-rw-r--r--sub/sd_lavc.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index 51c1d062c5..e39f537ba7 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -211,13 +211,25 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts,
int inw = priv->avctx->width;
int inh = priv->avctx->height;
guess_resolution(priv->avctx->codec_id, &inw, &inh);
- double xscale = (double) (d.w - d.ml - d.mr) / inw;
- double yscale = (double) (d.h - d.mt - d.mb) / inh;
+ int vidw = d.w - d.ml - d.mr;
+ int vidh = d.h - d.mt - d.mb;
+ double xscale = (double)vidw / inw;
+ 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;
+ } else {
+ yscale *= d.video_par;
+ }
+ }
+ int cx = vidw / 2 - (int)(inw * xscale) / 2;
+ int cy = vidh / 2 - (int)(inh * yscale) / 2;
for (int i = 0; i < priv->count; i++) {
struct sub_bitmap *bi = &priv->inbitmaps[i];
struct sub_bitmap *bo = &priv->outbitmaps[i];
- bo->x = bi->x * xscale + d.ml;
- bo->y = bi->y * yscale + d.mt;
+ bo->x = bi->x * xscale + cx + d.ml;
+ bo->y = bi->y * yscale + cy + d.mt;
bo->dw = bi->w * xscale;
bo->dh = bi->h * yscale;
}