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.
This commit is contained in:
wm4 2013-07-16 23:04:21 +02:00
parent 3d439368a1
commit 130866e269
1 changed files with 16 additions and 4 deletions

View File

@ -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;
}