[MPlayer-dev-eng] [PATCH] Avoid scaling for tiny aspect ratio differences
- Date: Fri, 28 Mar 2008 13:51:07 +0100
- From: Kurt Garloff <kurt@xxxxxxxxxx>
- Subject: [MPlayer-dev-eng] [PATCH] Avoid scaling for tiny aspect ratio differences
Hi,
I recoded (Full-)HD material with mencoder into high-Q FMP4 with
the native resolution for my LCD screen, which has 1366x768 pixels.
(The nice side effect is that this now consumes much less CPU to
decode and runs without dropped frames on a not so fast machine.)
The graphics driver supports 1360x768 only (needs /8 x resolution),
so I decided to encode 1360x765. YUV420 requires an even number, so
mencode made 1360x766 from it. So far so good.
Playing it with mplayer, it does however rescale the material to
1362x766 (1362 ~ 16/9*766) -- which is absolutely not what I want.
No matter how good the scaler, the result will be worse than the
format I have encoded with. (The difference shows especially on
a digital screen, where you can get really sharp images.)
In general I think we should avoid scaling if the difference in
aspect ratio is tiny.
Attached patch does this for AVI files.
I guess this patch could be complemented by a similar patch that avoids
other tiny adjustments (e.g. if the video was encoded with 1366x768 and
our screen would only display 1360x768, one would rather discard 3
columns on left and right than having the sharpness reduced by
rescaling). I have not looked into that, though.
I would rather send this out and see whether people think it's
worthwhile ...
Best,
--
Kurt Garloff <kurt@xxxxxxxxxx> [Koeln, DE]
Physics:Plasma modeling <garloff@xxxxxxxxxxxxxxxxxxx> [TU Eindhoven, NL]
Linux: VP PM OPS <garloff@xxxxxxx> [Novell Inc]
--- mplayer/libmpdemux/aviheader.c.orig 2008-03-24 14:32:03.000000000 +0100
+++ mplayer/libmpdemux/aviheader.c 2008-03-28 13:49:47.000000000 +0100
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
+#include <math.h>
#include "config.h"
#include "mp_msg.h"
@@ -352,7 +353,24 @@ while(1){
le2me_VIDEO_FIELD_DESC(&vprp->FieldInfo[i]);
}
if (sh_video) {
+ float calc_aspect = (float)vprp->dwHTotalInT / vprp->dwVTotalInLines;
sh_video->aspect = GET_AVI_ASPECT(vprp->dwFrameAspectRatio);
+ /*
+ * We may face slight distortion of Aspect ratio due to rounding
+ * or the fact that we need an even number of lines or the fact that
+ * 1360x768 is a tiny bit different from 16:9 (1360x765 or 1366/768).
+ * In that case avoid scaling (which always compromises quality).
+ * TODO: In the same spirit, we want to disregard tiny differences
+ * also in output and rather risk to have a few pixels unused or
+ * invisible than do scaling.
+ */
+ if (fabs(calc_aspect - sh_video->aspect) < 0.02) {
+ mp_msg(MSGT_HEADER,MSGL_V,"Aspect %.3f(%i:%i) -> %.3f(%i:%i)\n",
+ sh_video->aspect, vprp->dwFrameAspectRatio >> 16,
+ vprp->dwFrameAspectRatio & 0xffff, calc_aspect,
+ vprp->dwHTotalInT, vprp->dwVTotalInLines);
+ sh_video->aspect = calc_aspect;
+ }
}
if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_vprp(vprp,MSGL_V);
free(vprp);
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng