summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorivo <ivo@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-07-15 09:18:44 +0000
committerivo <ivo@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-07-15 09:18:44 +0000
commit761c684fc880d8f665eca8fa7ff1f4603dd3c5f1 (patch)
treee37dc5f662131b3a4c2afc9a55f273950b9e2005
parentee0a29934a4a5aee43e165eb701dbebbc8c33c3b (diff)
downloadmpv-761c684fc880d8f665eca8fa7ff1f4603dd3c5f1.tar.bz2
mpv-761c684fc880d8f665eca8fa7ff1f4603dd3c5f1.tar.xz
new black frame detection filter
by Brian J. Murrell, Julian Hall and me. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@19099 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--AUTHORS7
-rw-r--r--DOCS/man/en/mplayer.111
-rw-r--r--DOCS/tech/MAINTAINERS1
-rw-r--r--libmpcodecs/Makefile1
-rw-r--r--libmpcodecs/vf.c2
-rw-r--r--libmpcodecs/vf_blackframe.c141
6 files changed, 163 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index 731a7bfbc7..516788e30d 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -338,6 +338,9 @@ Guyomarch, Rémi (rguyom) <rguyom@pobox.com>
* unsharp video filter
* XviD encoding support
+Hall, Julian <jules@meridiandigital.co.uk>
+ * black frame detection filter (vf_blackframe)
+
Hammelmann, Jürgen <juergen.hammelmann@gmx.de>
* TOOLS/mencvcd author
@@ -572,6 +575,9 @@ Mohari, András <mayday@varoshaza.nagyatad.hu>
Mueller, Steven <diffusor@ugcs.caltech.edu>
* first implementation of live changing playback speed
+Murrel, Brian J. <brian@interlinx.bc.ca>
+ * black frame detection filter (vf_blackframe)
+
Neundorf, Alexander <neundorf@kde.org>
* raw DV demuxer
* demuxer packet refcounting
@@ -642,6 +648,7 @@ van Poorten, Ivo (ivop) <ivop@euronet.nl>
* vo_pnm video output driver
* vo_md5sum video output driver
* af_ladspa LADSPA plugin loader
+ * vf_blackframe cleanup and simplification
Ran, Lu <hephooey@fastmail.fm>
* Chinese documentation translation
diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1
index 53b8bbef6a..503412e752 100644
--- a/DOCS/man/en/mplayer.1
+++ b/DOCS/man/en/mplayer.1
@@ -6259,6 +6259,17 @@ Moves SSA/ASS subtitle rendering to an arbitrary point in the filter chain.
Only useful with the \-ass option.
.RE
.
+.TP
+.B blackframe[=amount:threshold]
+Detect frames that are (almost) completely black.
+Can be useful to detect chapter transitions or commercials.
+.RSs
+.IPs <amount>
+percentage of the pixels that have to be below the threshold (default: 98)
+.IPs <threshold>
+threshold below which a pixel value is considered black (default: 32)
+.RE
+.
.
.
.SH "GENERAL ENCODING OPTIONS (MENCODER ONLY)"
diff --git a/DOCS/tech/MAINTAINERS b/DOCS/tech/MAINTAINERS
index 4cca54fd00..41818ea683 100644
--- a/DOCS/tech/MAINTAINERS
+++ b/DOCS/tech/MAINTAINERS
@@ -125,6 +125,7 @@ codec support:
video filters:
* general: Richard Felker, Michael Niedermayer
* vf_filmdint.c - Zoltan Hidvegi
+ * vf_blackframe.c - Ivo van Poorten
audio filters:
* general: Alex Beregszaszi
diff --git a/libmpcodecs/Makefile b/libmpcodecs/Makefile
index a34ddca630..ceb9476f9f 100644
--- a/libmpcodecs/Makefile
+++ b/libmpcodecs/Makefile
@@ -120,6 +120,7 @@ VFILTER_SRCS=vf.c \
pullup.c \
vf_1bpp.c \
vf_2xsai.c \
+ vf_blackframe.c \
vf_bmovl.c \
vf_boxblur.c \
vf_crop.c \
diff --git a/libmpcodecs/vf.c b/libmpcodecs/vf.c
index 3df26ef639..5b08e521fa 100644
--- a/libmpcodecs/vf.c
+++ b/libmpcodecs/vf.c
@@ -103,6 +103,7 @@ extern vf_info_t vf_info_screenshot;
extern vf_info_t vf_info_ass;
extern vf_info_t vf_info_mcdeint;
extern vf_info_t vf_info_yadif;
+extern vf_info_t vf_info_blackframe;
// list of available filters:
static vf_info_t* filter_list[]={
@@ -199,6 +200,7 @@ static vf_info_t* filter_list[]={
&vf_info_ass,
#endif
&vf_info_yadif,
+ &vf_info_blackframe,
NULL
};
diff --git a/libmpcodecs/vf_blackframe.c b/libmpcodecs/vf_blackframe.c
new file mode 100644
index 0000000000..9f062f469e
--- /dev/null
+++ b/libmpcodecs/vf_blackframe.c
@@ -0,0 +1,141 @@
+/* vf_blackframe.c - detect frames that are (almost) black
+ *
+ * $Id$
+ *
+ * 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
+ *
+ * cleanup, simplify, speedup (c) 2006 by Ivo van Poorten
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ unsigned int bamount, bthresh, 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 int query_format(struct vf_instance_s *vf, unsigned fmt) {
+ switch(fmt) {
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_CLPL:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ case IMGFMT_NV12:
+ case IMGFMT_NV21:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ case IMGFMT_HM12:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+ int x, y;
+ int nblack=0, pblack=0;
+ unsigned char *yplane = mpi->planes[0];
+ unsigned int ystride = mpi->stride[0];
+ int w = mpi->w, h = mpi->h;
+ int bthresh = vf->priv->bthresh;
+ int bamount = vf->priv->bamount;
+
+ for (y=1; y<=h; y++) {
+ for (x=0; x<w; x++)
+ nblack += yplane[x] < bthresh;
+ pblack = nblack*100/(w*y);
+ if (pblack < bamount) break;
+ yplane += ystride;
+ }
+
+ if (pblack >= bamount)
+ mp_msg(MSGT_VFILTER, MSGL_INFO,"\nBlack frame: frame %u (%2d%%)\n",
+ vf->priv->frame, pblack);
+
+ vf->priv->frame++;
+
+ dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_EXPORT, 0,
+ mpi->width, mpi->height);
+ dmpi->planes[0] = mpi->planes[0];
+ dmpi->stride[0] = mpi->stride[0];
+ dmpi->planes[1] = mpi->planes[1];
+ dmpi->stride[1] = mpi->stride[1];
+ dmpi->planes[2] = mpi->planes[2];
+ dmpi->stride[2] = mpi->stride[2];
+
+ vf_clone_mpi_attributes(dmpi, mpi);
+
+ return vf_next_put_image(vf, dmpi, pts);
+}
+
+static int control(struct vf_instance_s* vf, int request, void* data){
+ return vf_next_control(vf,request,data);
+}
+
+static void uninit(struct vf_instance_s *vf) {
+ if (vf->priv) free(vf->priv);
+}
+
+static int open(vf_instance_t *vf, char* args){
+ vf->priv = malloc(sizeof(struct vf_priv_s));
+ if (!vf->priv) return 0;
+
+ vf->config = config;
+ vf->put_image = put_image;
+ vf->control = control;
+ vf->uninit = uninit;
+ vf->query_format = query_format;
+
+ vf->priv->bamount = 98;
+ vf->priv->bthresh = 0x20;
+ vf->priv->frame = 0;
+
+ if (args)
+ sscanf(args, "%u:%u", &vf->priv->bamount, &vf->priv->bthresh);
+ return 1;
+}
+
+vf_info_t vf_info_blackframe = {
+ "detects black frames",
+ "blackframe",
+ "Brian J. Murrell, Julian Hall, Ivo van Poorten",
+ "Useful for detecting scene transitions",
+ open,
+ NULL
+};