summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-09-26 16:53:17 +0200
committerwm4 <wm4@nowhere>2013-09-26 17:29:14 +0200
commit9a55c4e70cebe6da6b7c7796119f84c4c9ad2a60 (patch)
tree2b998cc92f0b0d091cc48051cb3cfebff8370837
parentf5bf6c0fb33fb6ff11f3250de708eb6e658772c9 (diff)
downloadmpv-9a55c4e70cebe6da6b7c7796119f84c4c9ad2a60.tar.bz2
mpv-9a55c4e70cebe6da6b7c7796119f84c4c9ad2a60.tar.xz
video: let sh_video->aspect always be container aspect ratio
Now writing -1 to the 'aspect' property resets the video to the auto aspect ratio. Returning the aspect from the property becomes a bit more complicated, because we still try to return the container aspect ratio if no frame has been decoded yet.
-rw-r--r--mpvcore/command.c22
-rw-r--r--mpvcore/options.c6
-rw-r--r--video/decode/vd.c11
-rw-r--r--video/decode/vd_lavc.c14
4 files changed, 33 insertions, 20 deletions
diff --git a/mpvcore/command.c b/mpvcore/command.c
index 35e72cb3ad..bce0300bc5 100644
--- a/mpvcore/command.c
+++ b/mpvcore/command.c
@@ -1478,22 +1478,30 @@ static int mp_property_fps(m_option_t *prop, int action, void *arg,
static int mp_property_aspect(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
+ struct sh_video *sh_video = mpctx->sh_video;
if (!mpctx->sh_video)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_SET: {
- float f = *(float *)arg;
- if (f < 0.1)
- f = (float)mpctx->sh_video->disp_w / mpctx->sh_video->disp_h;
- mpctx->opts->movie_aspect = f;
+ mpctx->opts->movie_aspect = *(float *)arg;
reinit_video_filters(mpctx);
mp_force_video_refresh(mpctx);
return M_PROPERTY_OK;
}
- case M_PROPERTY_GET:
- *(float *)arg = mpctx->sh_video->aspect;
+ case M_PROPERTY_GET: {
+ float aspect = -1;
+ struct mp_image_params *params = sh_video->vf_input;
+ if (params && params->d_w && params->d_h) {
+ aspect = (float)params->d_w / params->d_h;
+ } else if (sh_video->disp_w && sh_video->disp_h) {
+ aspect = (float)sh_video->disp_w / sh_video->disp_h;
+ }
+ if (aspect <= 0)
+ return M_PROPERTY_UNAVAILABLE;
+ *(float *)arg = aspect;
return M_PROPERTY_OK;
}
+ }
return M_PROPERTY_NOT_IMPLEMENTED;
}
@@ -1874,7 +1882,7 @@ static const m_option_t mp_properties[] = {
{ "fps", mp_property_fps, CONF_TYPE_FLOAT,
0, 0, 0, NULL },
{ "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
- CONF_RANGE, 0, 10, NULL },
+ CONF_RANGE, -1, 10, NULL },
M_OPTION_PROPERTY_CUSTOM("vid", mp_property_video),
{ "program", mp_property_program, CONF_TYPE_INT,
CONF_RANGE, -1, 65535, NULL },
diff --git a/mpvcore/options.c b/mpvcore/options.c
index d73faa1cbe..9cffb07284 100644
--- a/mpvcore/options.c
+++ b/mpvcore/options.c
@@ -497,8 +497,10 @@ const m_option_t mp_opts[] = {
// scaling:
{"sws", &sws_flags, CONF_TYPE_INT, 0, 0, 2, NULL},
{"ssf", (void *) scaler_filter_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
- OPT_FLOATRANGE("aspect", movie_aspect, 0, 0.1, 10.0),
- OPT_FLOAT_STORE("no-aspect", movie_aspect, 0, 0),
+ // -1 means auto aspect (prefer container size until aspect change)
+ // 0 means square pixels
+ OPT_FLOATRANGE("aspect", movie_aspect, 0, -1.0, 10.0),
+ OPT_FLOAT_STORE("no-aspect", movie_aspect, 0, 0.0),
OPT_FLAG_CONSTANTS("flip", flip, 0, 0, 1),
diff --git a/video/decode/vd.c b/video/decode/vd.c
index ad2af3a2cd..574f0468d4 100644
--- a/video/decode/vd.c
+++ b/video/decode/vd.c
@@ -115,12 +115,13 @@ int mpcodecs_reconfig_vo(sh_video_t *sh, const struct mp_image_params *params)
}
// time to do aspect ratio corrections...
- if (opts->movie_aspect > -1.0)
- sh->aspect = opts->movie_aspect; // cmdline overrides autodetect
- else if (sh->stream_aspect != 0.0)
- sh->aspect = sh->stream_aspect;
+ float force_aspect = opts->movie_aspect;
+ if (force_aspect > -1.0 && sh->stream_aspect != 0.0)
+ force_aspect = sh->stream_aspect;
+
+ if (force_aspect >= 0)
+ vf_set_dar(&p.d_w, &p.d_h, p.w, p.h, force_aspect);
- vf_set_dar(&p.d_w, &p.d_h, p.w, p.h, sh->aspect);
if (abs(p.d_w - p.w) >= 4 || abs(p.d_h - p.h) >= 4) {
mp_tmsg(MSGT_CPLAYER, MSGL_V, "Aspect ratio is %.2f:1 - "
"scaling to correct movie aspect.\n", sh->aspect);
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 7fbf9d8401..86c1c92541 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -492,8 +492,9 @@ static void update_image_params(sh_video_t *sh, AVFrame *frame)
// But set it even if the sample aspect did not change, since a
// resolution change can cause an aspect change even if the
// _sample_ aspect is unchanged.
- if (sh->aspect == 0 || ctx->last_sample_aspect_ratio.den)
- sh->aspect = aspect;
+ float use_aspect = sh->aspect;
+ if (use_aspect == 0 || ctx->last_sample_aspect_ratio.den)
+ use_aspect = aspect;
ctx->last_sample_aspect_ratio = frame->sample_aspect_ratio;
sh->disp_w = width;
sh->disp_h = height;
@@ -501,14 +502,15 @@ static void update_image_params(sh_video_t *sh, AVFrame *frame)
ctx->pix_fmt = pix_fmt;
ctx->best_csp = pixfmt2imgfmt(pix_fmt);
+ int d_w, d_h;
+ vf_set_dar(&d_w, &d_h, width, height, use_aspect);
+
ctx->image_params = (struct mp_image_params) {
.imgfmt = ctx->best_csp,
.w = width,
.h = height,
- // Ideally, we should also set aspect ratio, but we aren't there yet
- // - so vd.c calculates display size from sh->aspect.
- .d_w = width,
- .d_h = height,
+ .d_w = d_w,
+ .d_h = d_h,
.colorspace = avcol_spc_to_mp_csp(ctx->avctx->colorspace),
.colorlevels = avcol_range_to_mp_csp_levels(ctx->avctx->color_range),
.chroma_location =