[MPlayer-users] Aspect Ratio Detection

Alexander Roalter alex at roalter.it
Mon Jun 18 11:28:40 CEST 2007


I don't know if it is the right place to post, but here's some 
suggestion for a feature I often need and used the cropdetect filter to 
implement.

As I'm using the english language version, there's a patch also applied 
to help/help_mp-en.h, which should instead go to all the different 
languages, but I have not yet done this...

diff help/help_mp-en.h help/help_mp-en-aspect.h

1659c1659
< #define MSGTR_MPCODECS_CropArea "[CROP] Crop area: X: %d..%d  Y: 
%d..%d  (-vf crop=%d:%d:%d:%d).\n"
---
 > #define MSGTR_MPCODECS_CropArea "[CROP] Crop area: X: %d..%d  Y: 
%d..%d R:%0.2f:1 (-vf crop=%d:%d:%d:%d).\n"

And of course the fleshy part in libmpcodecs:

diff libmpcodecs/vf_cropdetect.c libmpcodecs/vf_cropdetect-aspect.c
18a19
 >       float aspect;
52a54,57
 >       if (d_height == 0)
 >               vf->priv->aspect = 1;
 >       else
 >               vf->priv->aspect = (float)d_width/(float)d_height;
57a63,64
 >       float ratio;
 >       float stretch;
127,131c134,149
<
<     mp_msg(MSGT_VFILTER, MSGL_INFO, MSGTR_MPCODECS_CropArea,
<       vf->priv->x1,vf->priv->x2,
<       vf->priv->y1,vf->priv->y2,
<       w,h,x,y);
---
 >       ratio = (((float)(vf->priv->x2 - vf->priv->x1 + 1))/
 >               ((float)(vf->priv->y2 - vf->priv->y1 + 1)));
 >       if ((mpi->height == 0) || (mpi->width == 0))
 >               stretch = 1;
 >       else
 >               stretch = vf->priv->aspect / 
((float)mpi->width/(float)mpi->height);
 >
 >       mp_msg(MSGT_VFILTER, MSGL_INFO, MSGTR_MPCODECS_CropArea,
 >       vf->priv->x1,vf->priv->x2,
 >       vf->priv->y1,vf->priv->y2, ratio * stretch,
 >       w,h,x,y);
 >
 > //    mp_msg(MSGT_VFILTER, MSGL_INFO, MSGTR_MPCODECS_CropArea,
 > //    vf->priv->x1,vf->priv->x2,
 > //    vf->priv->y1,vf->priv->y2,
 > //    w,h,x,y);

The Output of -vf cropdetect then looks like this:

[CROP] Crop area: X: 0..719  Y: 13..562 R:1.86:1 (-vf crop=720:544:0:16).

The the point 1.86:1 is especially interesting for me. For those only 
using the crop hinting for doing cropping this is easily another 
information (which can also be used to set the aspect ratio of the 
outcoming of the encoded video if all black bars are to be removed, and 
I can use the info for my DVD database with exact aspect ratios instead 
of the often wrong specified 1.33, 2.35 or 1.85 on the box cover.

-- 
cheers,
Alex



More information about the MPlayer-users mailing list