Re: [FFmpeg-devel] [PATCH] avfilter: add deflash filter

2015-11-22 Thread Moritz Barsnick
On Fri, Nov 20, 2015 at 20:13:11 +0100, Paul B Mahol wrote:

Trivial, but:

> +{ "0fd", "set flash threshold detection for 1st color component",  
> OFFSET(fthrd[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.2}, 0, 5, FLAGS },
> +{ "0fr", "set ammount of flash reduction for 1st color component", 
> OFFSET(fthrr[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.05}, 0, 1, FLAGS },
 ^^^ amount
(Three times in the options declarations.)

Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter: add deflash filter

2015-11-21 Thread Paul B Mahol
On 11/21/15, Clement Boesch  wrote:
> On Fri, Nov 20, 2015 at 08:13:11PM +0100, Paul B Mahol wrote:
> [...]
>> +for (y = 0; y < h; y++) {
>> +for (x = 0; x < w; x++) {
>> +int diff = next[x] - src[x];
>> +int t = 0;
>> +
>> +for (z = 0; z < FF_BUFQUEUE_SIZE - 1; z++) {
>> +AVFrame *f1 = ff_bufqueue_peek(&s->q, z);
>> +AVFrame *f2 = ff_bufqueue_peek(&s->q, z+1);
>> +
>
> f1 and f2 are const
>
>> +t += FFABS(f2->data[p][f2->linesize[p] * y + x] -
>> f1->data[p][f1->linesize[p] * y + x]);
>
> fabs()?
>
> looks like you could use sad utils and/or threading
>
> [...]
>
> doc?
>
> --
> Clement B.
>

I'm more interested in beter algorithm for flash removal.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter: add deflash filter

2015-11-21 Thread Clément Bœsch
On Fri, Nov 20, 2015 at 08:13:11PM +0100, Paul B Mahol wrote:
[...]
> +for (y = 0; y < h; y++) {
> +for (x = 0; x < w; x++) {
> +int diff = next[x] - src[x];
> +int t = 0;
> +
> +for (z = 0; z < FF_BUFQUEUE_SIZE - 1; z++) {
> +AVFrame *f1 = ff_bufqueue_peek(&s->q, z);
> +AVFrame *f2 = ff_bufqueue_peek(&s->q, z+1);
> +

f1 and f2 are const

> +t += FFABS(f2->data[p][f2->linesize[p] * y + x] - 
> f1->data[p][f1->linesize[p] * y + x]);

fabs()?

looks like you could use sad utils and/or threading

[...]

doc?

-- 
Clément B.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter: add deflash filter

2015-11-21 Thread Michael Niedermayer
On Fri, Nov 20, 2015 at 08:13:11PM +0100, Paul B Mahol wrote:
[...]

> +static av_cold void uninit(AVFilterContext *ctx)
> +{
> +DeFlashContext *s = ctx->priv;
> +}



> +
> +static const AVFilterPad inputs[] = {
> +{
> +.name = "default",
> +.type = AVMEDIA_TYPE_VIDEO,
> +.filter_frame = filter_frame,
> +.config_props = config_input,
> +},
> +{ NULL }
> +};
> +
> +static const AVFilterPad outputs[] = {
> +{
> +.name = "default",
> +.type = AVMEDIA_TYPE_VIDEO,
> +},
> +{ NULL }
> +};
> +
> +AVFilter ff_vf_deflash = {
> +.name  = "deflash",
> +.description   = NULL_IF_CONFIG_SMALL("Deflash."),
> +.priv_size = sizeof(DeFlashContext),
> +.priv_class= &deflash_class,

> +.uninit= uninit,

function is empty, this could be removed, unless you want to
keep it / plan to add something to it

either way, patch shuld be ok


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avfilter: add deflash filter

2015-11-20 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/vf_deflash.c | 199 +++
 3 files changed, 201 insertions(+)
 create mode 100644 libavfilter/vf_deflash.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1f4abeb..f801566 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -122,6 +122,7 @@ OBJS-$(CONFIG_CURVES_FILTER) += vf_curves.o
 OBJS-$(CONFIG_DCTDNOIZ_FILTER)   += vf_dctdnoiz.o
 OBJS-$(CONFIG_DEBAND_FILTER) += vf_deband.o
 OBJS-$(CONFIG_DECIMATE_FILTER)   += vf_decimate.o
+OBJS-$(CONFIG_DEFLASH_FILTER)+= vf_deflash.o
 OBJS-$(CONFIG_DEFLATE_FILTER)+= vf_neighbor.o
 OBJS-$(CONFIG_DEJUDDER_FILTER)   += vf_dejudder.o
 OBJS-$(CONFIG_DELOGO_FILTER) += vf_delogo.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 63b8fdb..daacbc3 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -144,6 +144,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(DCTDNOIZ,   dctdnoiz,   vf);
 REGISTER_FILTER(DEBAND, deband, vf);
 REGISTER_FILTER(DECIMATE,   decimate,   vf);
+REGISTER_FILTER(DEFLASH,deflash,vf);
 REGISTER_FILTER(DEFLATE,deflate,vf);
 REGISTER_FILTER(DEJUDDER,   dejudder,   vf);
 REGISTER_FILTER(DELOGO, delogo, vf);
diff --git a/libavfilter/vf_deflash.c b/libavfilter/vf_deflash.c
new file mode 100644
index 000..3167989
--- /dev/null
+++ b/libavfilter/vf_deflash.c
@@ -0,0 +1,199 @@
+/*
+ * 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 "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/internal.h"
+#include "avfilter.h"
+
+#define FF_BUFQUEUE_SIZE 13
+#include "bufferqueue.h"
+
+#include "internal.h"
+#include "video.h"
+
+typedef struct DeFlashContext {
+const AVClass *class;
+
+AVFrame *frame;
+float fthrd[4];
+int thrd[4];
+float fthrr[4];
+int thrr[4];
+
+struct FFBufQueue q;
+
+int planeheight[4];
+int planewidth[4];
+} DeFlashContext;
+
+#define OFFSET(x) offsetof(DeFlashContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption deflash_options[] = {
+{ "0fd", "set flash threshold detection for 1st color component",  
OFFSET(fthrd[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.2}, 0, 5, FLAGS },
+{ "0fr", "set ammount of flash reduction for 1st color component", 
OFFSET(fthrr[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.05}, 0, 1, FLAGS },
+{ "1fd", "set flash threshold detection for 2nd color component",  
OFFSET(fthrd[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.2}, 0, 5, FLAGS },
+{ "1fr", "set ammount of flash reduction for 2nd color component", 
OFFSET(fthrr[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.05}, 0, 1, FLAGS },
+{ "2fd", "set flash threshold detection for 3rd color component",  
OFFSET(fthrd[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.2}, 0, 5, FLAGS },
+{ "2fr", "set ammount of flash reduction for 3rd color component", 
OFFSET(fthrr[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.05}, 0, 1, FLAGS },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(deflash);
+
+static int query_formats(AVFilterContext *ctx)
+{
+static const enum AVPixelFormat pixel_fmts[] = {
+AV_PIX_FMT_YUV410P,  AV_PIX_FMT_YUV411P,
+AV_PIX_FMT_YUV420P,  AV_PIX_FMT_YUV422P,
+AV_PIX_FMT_YUV440P,  AV_PIX_FMT_YUV444P,
+AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P,
+AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P,
+AV_PIX_FMT_YUVJ411P,
+AV_PIX_FMT_NONE
+};
+AVFilterFormats *formats = ff_make_format_list(pixel_fmts);
+if (!formats)
+return AVERROR(ENOMEM);
+return ff_set_common_formats(ctx, formats);
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+AVFilterContext *ctx = inlink->dst;
+DeFlashContext *s = ctx->priv;
+
+s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, 
desc->log2_chroma_h);
+s->planeheight[0] = s->planeheight[3] = inlink->h;
+s->p