Index: libmpcodecs/vf_combdetect.c =================================================================== --- libmpcodecs/vf_combdetect.c (revision 0) +++ libmpcodecs/vf_combdetect.c (revision 5746) @@ -0,0 +1,160 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include + +#include "config.h" +#include "mp_msg.h" +#include "help_mp.h" + +#include "img_format.h" +#include "mp_image.h" +#include "vf.h" + +#define PIXELS_THRESHOLD (0.01) +#define FRAMES_THRESHOLD (0.05) + +struct vf_priv_s { + int limit; + int fno; + int combed; +}; + +static int getpixel(unsigned char* src, int bpp){ + + switch(bpp){ + case 1: + return src[0]; + case 3: + case 4: + return (src[0]+src[1]+src[2])/3; + } + + return 0; +} + +//===========================================================================// + +static int config(struct vf_instance *vf, + int width, int height, int d_width, int d_height, + unsigned int flags, unsigned int outfmt){ + vf->priv->fno=-2; + vf->priv->combed = 0; + return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); +} + +static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ + mp_image_t *dmpi; + int bpp=mpi->bpp/8; + int x,y; + long combed; + long total = (long) mpi->w * (mpi->h - 2); + double combed_pixels, combed_frames; + int deint; + unsigned char* src; + int pxl, d1, d2; + + // hope we'll get DR buffer: + dmpi=vf_get_image(vf->next,mpi->imgfmt, + MP_IMGTYPE_EXPORT, 0, + mpi->w, mpi->h); + + dmpi->planes[0]=mpi->planes[0]; + dmpi->planes[1]=mpi->planes[1]; + dmpi->planes[2]=mpi->planes[2]; + dmpi->stride[0]=mpi->stride[0]; + dmpi->stride[1]=mpi->stride[1]; + dmpi->stride[2]=mpi->stride[2]; + dmpi->width=mpi->width; + dmpi->height=mpi->height; + + if(++vf->priv->fno>0){ // ignore first 2 frames - they may be empty + + combed = 0; + + for (y = 1; y < mpi->h - 1; y++) { + src = mpi->planes[0] + mpi->stride[0] * y; + + for (x = 0; x < mpi->w; x++) { + pxl = getpixel(src, bpp); + d1 = getpixel(src - mpi->stride[0], bpp) - pxl; + d2 = getpixel(src + mpi->stride[0], bpp) - pxl; + + src += bpp; + + if ( + (d1 > vf->priv->limit && d2 > vf->priv->limit) + || (d1 < -vf->priv->limit && d2 < -vf->priv->limit) + ) combed++; + + } + + } + + combed_pixels = (double) combed / total; + + if (combed_pixels > PIXELS_THRESHOLD) { + vf->priv->combed++; + } + + combed_frames = (double) vf->priv->combed / vf->priv->fno; + + deint = (combed_frames > FRAMES_THRESHOLD); + + mp_msg(MSGT_VFILTER, MSGL_INFO, MSGTR_MPCODECS_CombArea, combed, total, combed_pixels * 100 + , vf->priv->combed, vf->priv->fno, combed_frames * 100 + , deint ? MSGTR_MPCODECS_CombArea_Deinterlace : MSGTR_MPCODECS_CombArea_NoDeinterlace ); + + } + + return vf_next_put_image(vf,dmpi, pts); +} + +static int query_format(struct vf_instance *vf, unsigned int fmt) { + switch(fmt) { + // the default limit value works only right with YV12 right now. + case IMGFMT_YV12: + return vf_next_query_format(vf, fmt); + } + return 0; +} +//===========================================================================// + +static int vf_open(vf_instance_t *vf, char *args){ + vf->config=config; + vf->put_image=put_image; + vf->query_format=query_format; + vf->priv=malloc(sizeof(struct vf_priv_s)); + vf->priv->limit=24; + if(args) sscanf(args, "%d", &vf->priv->limit); + return 1; +} + +const vf_info_t vf_info_combdetect = { + "autodetect combing", + "combdetect", + "Christoper Key", + "", + vf_open, + NULL +}; + +//===========================================================================// Property changes on: libmpcodecs/vf_combdetect.c ___________________________________________________________________ Added: svn:eol-style + native Index: libmpcodecs/vf.c =================================================================== --- libmpcodecs/vf.c (revision 5734) +++ libmpcodecs/vf.c (revision 5746) @@ -59,6 +59,7 @@ extern const vf_info_t vf_info_zrmjpeg; extern const vf_info_t vf_info_dvbscale; extern const vf_info_t vf_info_cropdetect; +extern const vf_info_t vf_info_combdetect; extern const vf_info_t vf_info_test; extern const vf_info_t vf_info_noise; extern const vf_info_t vf_info_yvu9; @@ -150,6 +151,7 @@ #endif &vf_info_dvbscale, &vf_info_cropdetect, + &vf_info_combdetect, &vf_info_test, &vf_info_noise, &vf_info_yvu9, Index: Makefile =================================================================== --- Makefile (revision 5734) +++ Makefile (revision 5746) @@ -408,6 +408,7 @@ libmpcodecs/vf_boxblur.c \ libmpcodecs/vf_crop.c \ libmpcodecs/vf_cropdetect.c \ + libmpcodecs/vf_combdetect.c \ libmpcodecs/vf_decimate.c \ libmpcodecs/vf_delogo.c \ libmpcodecs/vf_denoise3d.c \ Index: DOCS/man/en/mplayer.1 =================================================================== --- DOCS/man/en/mplayer.1 (revision 5734) +++ DOCS/man/en/mplayer.1 (revision 5746) @@ -5900,6 +5900,18 @@ .PD 1 . .TP +.B combdetect[=limit] +Counts the number of pixels that show combing on each frame and +prints statistics to stdout. Recommends whether to deinterlace. +.PD 0 +.RSs +.IPs +Threshold difference between pixel and its neighbours, which can be optionally specified from nothing (0) to +everything (255) (default: 24). +.RE +.PD 1 +. +.TP .B rectangle[=w:h:x:y] Draws a rectangle of the requested width and height at the specified coordinates over the image and prints current rectangle parameters Index: help/help_mp-en.h =================================================================== --- help/help_mp-en.h (revision 5734) +++ help/help_mp-en.h (revision 5746) @@ -1674,6 +1674,11 @@ // libmpcodecs/vf_cropdetect.c #define MSGTR_MPCODECS_CropArea "[CROP] Crop area: X: %d..%d Y: %d..%d (-vf crop=%d:%d:%d:%d).\n" +// libmpcodecs/vf_combdetect.c +#define MSGTR_MPCODECS_CombArea "[COMB] Combed pixels: %ld/%ld (%.2f%%). Combed frames: %d/%d (%.2f%%). %s.\n" +#define MSGTR_MPCODECS_CombArea_Deinterlace "Recommend deinterlacing" +#define MSGTR_MPCODECS_CombArea_NoDeinterlace "Don't recommend deinterlacing" + // libmpcodecs/vf_format.c, vf_palette.c, vf_noformat.c #define MSGTR_MPCODECS_UnknownFormatName "[VF_FORMAT] Unknown format name: '%s'.\n"