/* vf_blackframe.c * * search for black frames to detect scene transitions * (c) 2006 Julian Hall * * based on code designed for skipping commercials * (c) 2002-2003 Brian J. Murrell * * Can be used and reproduced under the terms of the GPL, version 2 * */ #include #include #include #include #include "../config.h" #include "../mp_msg.h" #include "img_format.h" #include "mp_image.h" #include "vf.h" #include "../libvo/fastmemcpy.h" #include "../postproc/rgb2rgb.h" //===========================================================================// struct vf_priv_s { unsigned int black_amount, black_thresh, frame; }; static int config(struct vf_instance_s* vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt){ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); } static void put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ int x, y; unsigned int num_black=0, pct_black=0, lines=0; for (y=mpi->h/2; yh; y++) { for (x=0; xw; x++) { if (mpi->planes[0][y*mpi->w+x]priv->black_thresh) { num_black++; } } lines++; pct_black=num_black*100/(mpi->w*lines); if (pct_blackpriv->black_amount) goto done; } for (y=mpi->h/2-1; y>-1; y--) { for (x=0; xw; x++) { if (mpi->planes[0][y*mpi->w+x]priv->black_thresh) { num_black++; } } lines++; pct_black=num_black*100/(mpi->w*lines); if (pct_blackpriv->black_amount) goto done; } done: if (pct_black>=vf->priv->black_amount) { fprintf (stderr, "\nBlack frame: frame %u (%2d%%)\n", vf->priv->frame, pct_black); } vf->priv->frame ++; return; } //===========================================================================// static int control(struct vf_instance_s* vf, int request, void* data){ return vf_next_control(vf,request,data); } static int open(vf_instance_t *vf, char* args){ vf->config=config; vf->put_image=put_image; vf->control=control; vf->priv=malloc(sizeof(struct vf_priv_s)); vf->priv->black_amount=98; vf->priv->black_thresh=0x20; vf->priv->frame = 0; if (args) sscanf(args, "%d:%d", &vf->priv->black_amount, &vf->priv->black_thresh); return 1; } vf_info_t vf_info_blackframe = { "detects black frames", "blackframe", "Brian J. Murrell, Julian Hall", "Useful for detecting scene transitions", open }; //===========================================================================//