[MPlayer-dev-eng] [PATCH] -aspect-tolerance option to avoid tiny prescaling
- Date: Mon, 31 Mar 2008 10:59:47 +0200
- From: Kurt Garloff <kurt@xxxxxxxxxx>
- Subject: [MPlayer-dev-eng] [PATCH] -aspect-tolerance option to avoid tiny prescaling
Attila, On Fri, Mar 28, 2008 at 02:08:38PM +0100, Attila Kinali wrote: > On Fri, 28 Mar 2008 13:51:07 +0100 > Kurt Garloff <kurt@xxxxxxxxxx> wrote: > > > In general I think we should avoid scaling if the difference in > > aspect ratio is tiny. > > > > Attached patch does this for AVI files. > > This code belongs into libvo/aspect.c > > You should also make the limit configurable by adding a command > line option. It should be also possible to switch this "protection" > off (in some cases, the resulting black bars are more annoying). Thanks for the good feedback! I could not find a clean way to add the logic to libvo/aspect.c, as the prescaling is configured before that code gets called. A new patch attached, putting the logic into libmpcodecs/vd.c, making it adjustable (-aspect-tolerance FLOAT) and documenting it. Best, -- Kurt Garloff <kurt@xxxxxxxxxx> [Koeln, DE] Physics:Plasma modeling <garloff@xxxxxxxxxxxxxxxxxxx> [TU Eindhoven, NL] Linux: VP PM OPS <garloff@xxxxxxx> [Novell Inc]
--- mplayer/libmpcodecs/vd.c.orig 2008-03-24 14:31:42.000000000 +0100
+++ mplayer/libmpcodecs/vd.c 2008-03-31 10:22:17.000000000 +0200
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#include "config.h"
#include "mp_msg.h"
@@ -118,6 +119,7 @@ int opt_screen_size_x=0;
int opt_screen_size_y=0;
float screen_size_xy=0;
float movie_aspect=-1.0;
+float aspect_tolerance=0.01;
int vo_flags=0;
int vd_use_slices=1;
@@ -278,10 +280,15 @@ csp_again:
}
}
if(sh->aspect>0.01){
- int w;
+ int w = screen_size_x;
+ float calc_aspect = (float)screen_size_x/screen_size_y;
mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MovieAspectIsSet,sh->aspect);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ASPECT=%1.4f\n", sh->aspect);
- w=(int)((float)screen_size_y*sh->aspect); w+=w%2; // round
+ // Avoid prescaling if the difference is tiny (rounding errors etc)
+ // so we don't do stupid things such as 1360x768 -> 1366x768
+ if (fabs(calc_aspect - sh->aspect) > aspect_tolerance) {
+ w=(int)((float)screen_size_y*sh->aspect); w+=w%2; // round
+ }
// we don't like horizontal downscale || user forced width:
if(w<screen_size_x || screen_size_xy>8){
screen_size_y=(int)((float)screen_size_x*(1.0/sh->aspect));
--- mplayer/cfg-common.h.orig 2008-03-24 14:32:03.000000000 +0100
+++ mplayer/cfg-common.h 2008-03-31 10:24:19.000000000 +0200
@@ -231,6 +231,7 @@
{"nozoom", &softzoom, CONF_TYPE_FLAG, 0, 1, 0, NULL},
{"aspect", &movie_aspect, CONF_TYPE_FLOAT, CONF_RANGE, 0.2, 3.0, NULL},
{"noaspect", &movie_aspect, CONF_TYPE_FLAG, 0, 0, 0, NULL},
+ {"aspect-tolerance", &aspect_tolerance, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.5, NULL},
{"xy", &screen_size_xy, CONF_TYPE_FLOAT, CONF_RANGE, 0.001, 4096, NULL},
{"flip", &flip, CONF_TYPE_FLAG, 0, -1, 1, NULL},
@@ -348,6 +349,7 @@ extern char *mp_msg_charset;
// codec/filter opts: (defined at libmpcodecs/vd.c)
extern float screen_size_xy;
extern float movie_aspect;
+extern float aspect_tolerance;
extern int softzoom;
extern int flip;
--- mplayer/DOCS/man/en/mplayer.1.orig 2008-03-24 14:31:56.000000000 +0100
+++ mplayer/DOCS/man/en/mplayer.1 2008-03-31 10:25:37.000000000 +0200
@@ -4262,6 +4262,21 @@ incorrect or missing in the file being p
Disable automatic movie aspect ratio compensation.
.
.TP
+.B \-aspect\-tolerance <0.0\-1.5>
+When decoding, the video material is prescaled from the encoding
+resolution to the advertised aspect ratio (e.g. from 720x576
+encoded PAL information to 768x576 with 4:3 aspect). Prescaling does
+however result in a loss of quality for video material encoded with
+high bit rates. This option allows you to avoid prescaling in case
+the difference between encoding resolution and the correct aspect
+ratio is small, which can happen due to rounding errors or sizes
+that are a tiny bit off the perfect ratio (e.g. 1360x768 vs. 1366x768).
+The value sets the maximum aspect ratio difference that the decoder
+should ignore at the expense of an apsect ratio that's a little bit
+off. Useful values are typically in the 0.00\-0.10 range
+(default: 0.01).
+.
+.TP
.B "\-field\-dominance <\-1\-1>"
Set first field for interlaced content.
Useful for deinterlacers that double the framerate: \-vf tfields=1,
Attachment:
pgpLefmp4Zo30.pgp
Description: PGP signature
_______________________________________________ MPlayer-dev-eng mailing list MPlayer-dev-eng@xxxxxxxxxxxx https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
- References:
- [MPlayer-dev-eng] [PATCH] Avoid scaling for tiny aspect ratio differences
- From: Kurt Garloff
- Re: [MPlayer-dev-eng] [PATCH] Avoid scaling for tiny aspect ratio differences
- From: Attila Kinali
- [MPlayer-dev-eng] [PATCH] Avoid scaling for tiny aspect ratio differences
- Prev by Date: Re: [MPlayer-dev-eng] [PATCH] Avoid scaling for tiny aspect ratio differences
- Next by Date: Re: [MPlayer-dev-eng] mplayer query
- Previous by thread: Re: [MPlayer-dev-eng] [PATCH] Avoid scaling for tiny aspect ratio differences
- Next by thread: Re: [MPlayer-dev-eng] [PATCH] Avoid scaling for tiny aspect ratio differences
- Index(es):