From 64ab2402e2e08cdd4f710b2278b1d67cfc74cbe6 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 22 Oct 2010 17:36:11 +0000 Subject: vd_ffmpeg: improve aspect ratio handling Respect container aspect first if available, but change to ratio based on video codec level information if there's a resolution or pixel aspect change from the original codec values in the middle of the video. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32525 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/vd_ffmpeg.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c index 1bb7c2e94b..8105eb8f83 100644 --- a/libmpcodecs/vd_ffmpeg.c +++ b/libmpcodecs/vd_ffmpeg.c @@ -181,8 +181,6 @@ static int init(sh_video_t *sh){ ctx = sh->context = talloc_zero(NULL, vd_ffmpeg_ctx); - ctx->last_sample_aspect_ratio = (AVRational){0, 1}; - lavc_codec = avcodec_find_decoder_by_name(sh->codec->dll); if(!lavc_codec){ mp_tmsg(MSGT_DECVIDEO, MSGL_ERR, "Cannot find codec '%s' in libavcodec...\n", sh->codec->dll); @@ -476,9 +474,13 @@ static int init_vo(sh_video_t *sh, enum PixelFormat pix_fmt){ !ctx->vo_initialized) { mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] aspect_ratio: %f\n", aspect); - if (sh->aspect == 0 || - av_cmp_q(avctx->sample_aspect_ratio, - ctx->last_sample_aspect_ratio)) + + // Do not overwrite s->aspect on the first call, so that a container + // aspect if available is preferred. + // 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; ctx->last_sample_aspect_ratio = avctx->sample_aspect_ratio; sh->disp_w = width; -- cgit v1.2.3