[FFmpeg-devel] [PATCH] libavfilter-soc?: implement fish filter

Stefano Sabatini stefano.sabatini-lala
Sun May 31 17:12:56 CEST 2009


On date Saturday 2009-05-30 22:04:52 +0200, Michael Niedermayer encoded:
> On Sat, May 30, 2009 at 11:38:11AM +0200, Stefano Sabatini wrote:
> > Hi all,
> > fish filter is back!!
> > -- 
> > FFmpeg = Fundamentalist Frightening Mysterious Peaceful Eager Gadget
> 
> note, i review this with the intent of it hitting ffmpeg svn not soc
> i wont review patches twice for 2 trees

Fine to me. 

> >  doc/vfilters.texi        |   55 +++++++
> >  libavfilter/Makefile     |    1 
> >  libavfilter/allfilters.c |    1 
> >  libavfilter/vf_fish.c    |  346 +++++++++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 403 insertions(+)
> > e2421aedd3da958b39eb104bddd731d633e93748  fish-implement.patch
> > Index: libavfilter-soc/ffmpeg/doc/vfilters.texi
> > ===================================================================
> > --- libavfilter-soc.orig/ffmpeg/doc/vfilters.texi	2009-05-28 21:05:20.000000000 +0200
> > +++ libavfilter-soc/ffmpeg/doc/vfilters.texi	2009-05-30 11:35:20.000000000 +0200
> > @@ -92,6 +92,61 @@
> >  ./ffmpeg -i in.avi -vfilters "fifo" out.avi
> >  @end example
> >  
> > + at section fish
> > +
> > +A fish detector. It is used to see when a goldfish passes in front of
> > +the camera. It does this by counting the number of input pixels that
> > +fall within a particular HSV range.
> > +
> > +When this happens the picture is sent to the output.
> > +
> > +Parameters are specified as a list of non-positional key=value pairs
> > +separated by ``:''
> > +
> > + at table @option
> > +
> > + at item h, s, v
> > +
> > +Specify the range of H, S, V values that are fish. Takes as argument an
> > +expression of the form: @var{first}- at var{second}, where @var{first} and
> > + at var{second} are the values which detects the component interval.
> > +Value for H are in the range 0-360, for S and V are in the range 0-255.
> > +
> 
> > + at item zap, zap_color
> > +
> > +If zap is set to 1, set all non-fish values to the color specified by
> > +zap_color (default is black).
> 
> redundant
> (zap could be 1 if zap_color is specified)
> 
> 
> > +
> > + at item fill, fill_color
> > +
> > +If fill is set to 1, set all fish values to the color specified by
> > +fill_color (default is black).
> 
> same

Fixed.
 
> btw, setting the alpha plane to fishiness would be funny for things like
> a blend filter ...
> 
> 
> > +
> > + at item debug
> > +
> > +If set to 1 turn debugging on.
> > +
> 
> > + at item threshold
> > +
> > +Specify the threshold for the amount of fish pixels (range from 0.0 to
> > +1.0).
> 
> unclear

Please check again.
  
> > +
> > + at item interval
> > +
> > +Specify how much time (in AV_TIME_BASE units) to wait before to try
> > +again another fish detection.
> 
> float in seconds is nicer for humans

Fixed.
  
> > +
> > + at end table
> > +
> > + at example
> > +ffplay -f video4linux /dev/video0 -vfilters "fish=debug=1: h=350-20 : v=100-255 : threshold=10 : zap=1 :zap_color=blue"
> > + at end example
> > +
> > +The filter will look for all the pixels with a near-red color, if at
> > +at least 10/1000 of the pixels are in that interval, it will send to
> > +output the image, setting to the color ``blue'' all the other pixels
> > +not ranging in the specified interval.
> > +

Updated.

> >  @section format
> >  
> >  @example
> > Index: libavfilter-soc/ffmpeg/libavfilter/allfilters.c
> > ===================================================================
> > --- libavfilter-soc.orig/ffmpeg/libavfilter/allfilters.c	2009-05-28 21:03:30.000000000 +0200
> > +++ libavfilter-soc/ffmpeg/libavfilter/allfilters.c	2009-05-28 21:03:55.000000000 +0200
> > @@ -37,6 +37,7 @@
> >      REGISTER_FILTER(CROP,crop,vf);
> >      REGISTER_FILTER(DRAWBOX,drawbox,vf);
> >      REGISTER_FILTER(FIFO,fifo,vf);
> > +    REGISTER_FILTER(FISH,fish,vf);
> >      REGISTER_FILTER(FORMAT,format,vf);
> >      REGISTER_FILTER(FPS,fps,vf);
> >      REGISTER_FILTER(HFLIP,hflip,vf);
> > Index: libavfilter-soc/ffmpeg/libavfilter/vf_fish.c
> > ===================================================================
> > --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> > +++ libavfilter-soc/ffmpeg/libavfilter/vf_fish.c	2009-05-30 11:24:54.000000000 +0200
> > @@ -0,0 +1,346 @@
> > +/*
> > + * Fish Detector filter
> > + * Copyright (c) 2002 Philip Gladstone
> > + * Copyright (c) 2009 Stefano Sabatini
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg 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
> > + * Lesser General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU Lesser General Public
> > + * License along with FFmpeg; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> > + */
> > +
> > +#include "libavcodec/colorspace.h"
> > +#include "libavcodec/dsputil.h"
> > +#include "parseutils.h"
> > +#include "avfilter.h"
> > +
> 
> > +typedef struct HSV {
> > +    int h;  /* 0 .. 360 */
> > +    int s;  /* 0 .. 255 */
> > +    int v;  /* 0 .. 255 */
> > +} HSV;
> 
> doxy

Fixed.
  
> > +
> > +typedef struct {
> > +    const AVClass *class;
> > +
> > +    int w, h;
> 
> > +    char *h_range, *s_range, *v_range;
> 
> They are ultimately not strings

Yes, but then how should I put them in the context when using
av_set_options_string()? (BTW this is the same "trick" used to set an
expression).

> > +
> > +    int hsub, vsub;
> > +
> > +    char *zap_color_str;    ///< if enabled zapping, not matched pixels will be set to zap_color
> > +    uint8_t zap_color[4];
> > +    int zap;
> > +
> > +    char *fill_color_str;   ///< if enabled filling, matched pixels will be set to fill_color
> > +    uint8_t fill_color[4];
> > +    int fill;
> 
> same

Again.

Note that the previous version had a bug, a pixel (x, y) with values
(y1, u1, v1) was set, then the pixel (x, y+1) was checked and the
values previously set u1 and u2 was used instead of the input values.

My solution is to preserve the input frame, and copy it eventually
modified to an output frame (unfortunately is slower).

Regards.
-- 
FFmpeg = Forgiving Faboulous Multimedia Pacific Extended Gorilla
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fish-implement.patch
Type: text/x-diff
Size: 16140 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090531/afe3e250/attachment.patch>



More information about the ffmpeg-devel mailing list