Re: [FFmpeg-devel] [PATCH] avfilter: add loop filters

2016-02-14 Thread Paul B Mahol
On 2/12/16, Paul B Mahol  wrote:
> On 2/11/16, Paul B Mahol  wrote:
>> Hi,
>>
>> patch attached.
>>
>
> Better version attached.
>

Even better version attached.
From 5a96e8103b2556291e1fe1922adb16945e70f64b Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Thu, 11 Feb 2016 22:05:54 +0100
Subject: [PATCH] avfilter: add loop filters

Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |  19 +++
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   2 +
 libavfilter/f_loop.c | 381 +++
 libavutil/audio_fifo.c   |  24 +++
 libavutil/audio_fifo.h   |  17 +++
 6 files changed, 445 insertions(+)
 create mode 100644 libavfilter/f_loop.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 68f54f1..dc83c1b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8147,6 +8147,25 @@ The formula that generates the correction is:
 where @var{r_0} is halve of the image diagonal and @var{r_src} and @var{r_tgt} are the
 distances from the focal point in the source and target images, respectively.
 
+@section loop, aloop
+
+Loop video frames or audio samples.
+
+Those filters accepts the following options:
+
+@table @option
+@item loop
+Set the number of loops.
+
+@item size
+Set maximal size in number of frames for @code{loop} filter or maximal number
+of samples in case of @code{aloop} filter.
+
+@item start
+Set first frame of loop for @code{loop} filter or first sample of loop in case
+of @code{aloop} filter.
+@end table
+
 @anchor{lut3d}
 @section lut3d
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 8916588..35ac53a 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -38,6 +38,7 @@ OBJS-$(CONFIG_AGATE_FILTER)  += af_agate.o
 OBJS-$(CONFIG_AINTERLEAVE_FILTER)+= f_interleave.o
 OBJS-$(CONFIG_ALIMITER_FILTER)   += af_alimiter.o
 OBJS-$(CONFIG_ALLPASS_FILTER)+= af_biquads.o
+OBJS-$(CONFIG_ALOOP_FILTER)  += f_loop.o
 OBJS-$(CONFIG_AMERGE_FILTER) += af_amerge.o
 OBJS-$(CONFIG_AMETADATA_FILTER)  += f_metadata.o
 OBJS-$(CONFIG_AMIX_FILTER)   += af_amix.o
@@ -180,6 +181,7 @@ OBJS-$(CONFIG_INTERLACE_FILTER)  += vf_interlace.o
 OBJS-$(CONFIG_INTERLEAVE_FILTER) += f_interleave.o
 OBJS-$(CONFIG_KERNDEINT_FILTER)  += vf_kerndeint.o
 OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o
+OBJS-$(CONFIG_LOOP_FILTER)   += f_loop.o
 OBJS-$(CONFIG_LUT3D_FILTER)  += vf_lut3d.o
 OBJS-$(CONFIG_LUT_FILTER)+= vf_lut.o
 OBJS-$(CONFIG_LUTRGB_FILTER) += vf_lut.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index fa7d304..6331fe5 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -58,6 +58,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(AINTERLEAVE,ainterleave,af);
 REGISTER_FILTER(ALIMITER,   alimiter,   af);
 REGISTER_FILTER(ALLPASS,allpass,af);
+REGISTER_FILTER(ALOOP,  aloop,  af);
 REGISTER_FILTER(AMERGE, amerge, af);
 REGISTER_FILTER(AMETADATA,  ametadata,  af);
 REGISTER_FILTER(AMIX,   amix,   af);
@@ -201,6 +202,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(INTERLEAVE, interleave, vf);
 REGISTER_FILTER(KERNDEINT,  kerndeint,  vf);
 REGISTER_FILTER(LENSCORRECTION, lenscorrection, vf);
+REGISTER_FILTER(LOOP,   loop,   vf);
 REGISTER_FILTER(LUT3D,  lut3d,  vf);
 REGISTER_FILTER(LUT,lut,vf);
 REGISTER_FILTER(LUTRGB, lutrgb, vf);
diff --git a/libavfilter/f_loop.c b/libavfilter/f_loop.c
new file mode 100644
index 000..d8eb692
--- /dev/null
+++ b/libavfilter/f_loop.c
@@ -0,0 +1,381 @@
+/*
+ * Copyright (c) 2016 Paul B Mahol
+ *
+ * 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/audio_fifo.h"
+#include "libavutil/avassert.h"
+#include "libavutil/fifo.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+#include 

Re: [FFmpeg-devel] [PATCH] avfilter: add loop filters

2016-02-14 Thread Paul B Mahol
On 2/13/16, Stefano Sabatini  wrote:
> On date Friday 2016-02-12 15:28:15 +0100, Paul B Mahol encoded:
>> On 2/11/16, Paul B Mahol  wrote:
>> > Hi,
>> >
>> > patch attached.
>> >
>>
>> Better version attached.
>
>> From d953f78bffbf3db8f0209b41b189ece12b402afa Mon Sep 17 00:00:00 2001
>> From: Paul B Mahol 
>> Date: Thu, 11 Feb 2016 22:05:54 +0100
>> Subject: [PATCH] avfilter: add loop filters
>>
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavfilter/Makefile |   2 +
>>  libavfilter/allfilters.c |   2 +
>>  libavfilter/f_loop.c | 339
>> +++
>>  libavutil/audio_fifo.c   |  24 
>>  libavutil/audio_fifo.h   |  17 +++
> [...]
>> +int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int nb_samples,
>> int offset)
>> +{
>> +int i, ret, size;
>> +
>> +if (offset < 0 || offset >= af->nb_samples)
>> +return AVERROR(EINVAL);
>> +if (nb_samples < 0)
>> +return AVERROR(EINVAL);
>> +nb_samples = FFMIN(nb_samples, af->nb_samples);
>> +if (!nb_samples)
>> +return 0;
>
>> +if (offset > af->nb_samples - nb_samples)
>> +return AVERROR(EINVAL);
>
> is this check really required, or could you have something like:
> nb_samples = FFMIN(nb_samples, af->nb_samples - offset);
>
> ?

I prefer direct approach, if user supplied invalid values, notify him.
Do not try to silently guess what user wants.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter: add loop filters

2016-02-12 Thread Paul B Mahol
On 2/11/16, Paul B Mahol  wrote:
> Hi,
>
> patch attached.
>

Better version attached.
From d953f78bffbf3db8f0209b41b189ece12b402afa Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Thu, 11 Feb 2016 22:05:54 +0100
Subject: [PATCH] avfilter: add loop filters

Signed-off-by: Paul B Mahol 
---
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   2 +
 libavfilter/f_loop.c | 339 +++
 libavutil/audio_fifo.c   |  24 
 libavutil/audio_fifo.h   |  17 +++
 5 files changed, 384 insertions(+)
 create mode 100644 libavfilter/f_loop.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 8916588..35ac53a 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -38,6 +38,7 @@ OBJS-$(CONFIG_AGATE_FILTER)  += af_agate.o
 OBJS-$(CONFIG_AINTERLEAVE_FILTER)+= f_interleave.o
 OBJS-$(CONFIG_ALIMITER_FILTER)   += af_alimiter.o
 OBJS-$(CONFIG_ALLPASS_FILTER)+= af_biquads.o
+OBJS-$(CONFIG_ALOOP_FILTER)  += f_loop.o
 OBJS-$(CONFIG_AMERGE_FILTER) += af_amerge.o
 OBJS-$(CONFIG_AMETADATA_FILTER)  += f_metadata.o
 OBJS-$(CONFIG_AMIX_FILTER)   += af_amix.o
@@ -180,6 +181,7 @@ OBJS-$(CONFIG_INTERLACE_FILTER)  += vf_interlace.o
 OBJS-$(CONFIG_INTERLEAVE_FILTER) += f_interleave.o
 OBJS-$(CONFIG_KERNDEINT_FILTER)  += vf_kerndeint.o
 OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o
+OBJS-$(CONFIG_LOOP_FILTER)   += f_loop.o
 OBJS-$(CONFIG_LUT3D_FILTER)  += vf_lut3d.o
 OBJS-$(CONFIG_LUT_FILTER)+= vf_lut.o
 OBJS-$(CONFIG_LUTRGB_FILTER) += vf_lut.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index fa7d304..6331fe5 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -58,6 +58,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(AINTERLEAVE,ainterleave,af);
 REGISTER_FILTER(ALIMITER,   alimiter,   af);
 REGISTER_FILTER(ALLPASS,allpass,af);
+REGISTER_FILTER(ALOOP,  aloop,  af);
 REGISTER_FILTER(AMERGE, amerge, af);
 REGISTER_FILTER(AMETADATA,  ametadata,  af);
 REGISTER_FILTER(AMIX,   amix,   af);
@@ -201,6 +202,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(INTERLEAVE, interleave, vf);
 REGISTER_FILTER(KERNDEINT,  kerndeint,  vf);
 REGISTER_FILTER(LENSCORRECTION, lenscorrection, vf);
+REGISTER_FILTER(LOOP,   loop,   vf);
 REGISTER_FILTER(LUT3D,  lut3d,  vf);
 REGISTER_FILTER(LUT,lut,vf);
 REGISTER_FILTER(LUTRGB, lutrgb, vf);
diff --git a/libavfilter/f_loop.c b/libavfilter/f_loop.c
new file mode 100644
index 000..b902af0
--- /dev/null
+++ b/libavfilter/f_loop.c
@@ -0,0 +1,339 @@
+/*
+ * Copyright (c) 2016 Paul B Mahol
+ *
+ * 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/audio_fifo.h"
+#include "libavutil/avassert.h"
+#include "libavutil/fifo.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "audio.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct LoopContext {
+const AVClass *class;
+
+AVAudioFifo *fifo;
+AVFrame **frames;
+int nb_frames;
+int current_frame;
+int64_t start_pts;
+int64_t duration;
+int64_t current_sample;
+int64_t nb_samples;
+int64_t ignored_samples;
+
+int loop;
+int64_t size;
+int64_t start;
+int64_t pts;
+} LoopContext;
+
+#define AFLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+#define VFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+#define OFFSET(x) offsetof(LoopContext, x)
+
+#if CONFIG_ALOOP_FILTER
+
+static int aconfig_input(AVFilterLink *inlink)
+{
+AVFilterContext *ctx = inlink->dst;
+LoopContext *s  = ctx->priv;
+
+s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, 8192);
+if (!s->fifo)
+return AVERROR(ENOMEM);
+
+return 0;
+}
+
+static 

Re: [FFmpeg-devel] [PATCH] avfilter: add loop filters

2016-02-12 Thread Nicolas George
Le quartidi 24 pluviôse, an CCXXIV, Michael Niedermayer a écrit :
> This shoudl use av_frame_get_pkt_duration()
> 
> /**
>  * duration of the corresponding packet, expressed in
>  * AVStream->time_base units, 0 if unknown.
>  * Code outside libavutil should access this field using:
>  * av_frame_get_pkt_duration(frame)

This was necessary to ensure ABI compatibility both backwards and with the
fork. Since we do not support the latter, we could allow direct access.

Regards,

-- 
  Nicolas George


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


Re: [FFmpeg-devel] [PATCH] avfilter: add loop filters

2016-02-12 Thread Michael Niedermayer
On Thu, Feb 11, 2016 at 11:11:49PM +0100, Paul B Mahol wrote:
> Hi,
> 
> patch attached.

>  Makefile |2 
>  allfilters.c |2 
>  f_loop.c |  220 
> +++
>  3 files changed, 224 insertions(+)
> 9acd18c6b2dff1cc2c1b5d5e9cfcc94760a02821  0001-avfilter-add-loop-filters.patch
> From 1fd9636e9040b2a6b321cdd16ebd392c8db2de1b Mon Sep 17 00:00:00 2001
> From: Paul B Mahol 
> Date: Thu, 11 Feb 2016 22:05:54 +0100
> Subject: [PATCH] avfilter: add loop filters
> 
> Signed-off-by: Paul B Mahol 
[...]

> +static int push_frame(AVFilterContext *ctx)
> +{
> +AVFilterLink *outlink = ctx->outputs[0];
> +LoopContext *s = ctx->priv;
> +int64_t pts;
> +int ret;
> +
> +AVFrame *out = av_frame_clone(s->frames[s->current_frame]);
> +
> +if (!out)
> +return AVERROR(ENOMEM);
> +out->pts += s->duration - s->start_pts;

> +pts = out->pts + out->pkt_duration;

[...]

> +s->duration = frame->pts + frame->pkt_duration;

This shoudl use av_frame_get_pkt_duration()

/**
 * duration of the corresponding packet, expressed in
 * AVStream->time_base units, 0 if unknown.
 * Code outside libavutil should access this field using:
 * av_frame_get_pkt_duration(frame)



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

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 


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 loop filters

2016-02-11 Thread Paul B Mahol
Hi,

patch attached.
From 1fd9636e9040b2a6b321cdd16ebd392c8db2de1b Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Thu, 11 Feb 2016 22:05:54 +0100
Subject: [PATCH] avfilter: add loop filters

Signed-off-by: Paul B Mahol 
---
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   2 +
 libavfilter/f_loop.c | 220 +++
 3 files changed, 224 insertions(+)
 create mode 100644 libavfilter/f_loop.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 8916588..35ac53a 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -38,6 +38,7 @@ OBJS-$(CONFIG_AGATE_FILTER)  += af_agate.o
 OBJS-$(CONFIG_AINTERLEAVE_FILTER)+= f_interleave.o
 OBJS-$(CONFIG_ALIMITER_FILTER)   += af_alimiter.o
 OBJS-$(CONFIG_ALLPASS_FILTER)+= af_biquads.o
+OBJS-$(CONFIG_ALOOP_FILTER)  += f_loop.o
 OBJS-$(CONFIG_AMERGE_FILTER) += af_amerge.o
 OBJS-$(CONFIG_AMETADATA_FILTER)  += f_metadata.o
 OBJS-$(CONFIG_AMIX_FILTER)   += af_amix.o
@@ -180,6 +181,7 @@ OBJS-$(CONFIG_INTERLACE_FILTER)  += vf_interlace.o
 OBJS-$(CONFIG_INTERLEAVE_FILTER) += f_interleave.o
 OBJS-$(CONFIG_KERNDEINT_FILTER)  += vf_kerndeint.o
 OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o
+OBJS-$(CONFIG_LOOP_FILTER)   += f_loop.o
 OBJS-$(CONFIG_LUT3D_FILTER)  += vf_lut3d.o
 OBJS-$(CONFIG_LUT_FILTER)+= vf_lut.o
 OBJS-$(CONFIG_LUTRGB_FILTER) += vf_lut.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index fa7d304..6331fe5 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -58,6 +58,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(AINTERLEAVE,ainterleave,af);
 REGISTER_FILTER(ALIMITER,   alimiter,   af);
 REGISTER_FILTER(ALLPASS,allpass,af);
+REGISTER_FILTER(ALOOP,  aloop,  af);
 REGISTER_FILTER(AMERGE, amerge, af);
 REGISTER_FILTER(AMETADATA,  ametadata,  af);
 REGISTER_FILTER(AMIX,   amix,   af);
@@ -201,6 +202,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(INTERLEAVE, interleave, vf);
 REGISTER_FILTER(KERNDEINT,  kerndeint,  vf);
 REGISTER_FILTER(LENSCORRECTION, lenscorrection, vf);
+REGISTER_FILTER(LOOP,   loop,   vf);
 REGISTER_FILTER(LUT3D,  lut3d,  vf);
 REGISTER_FILTER(LUT,lut,vf);
 REGISTER_FILTER(LUTRGB, lutrgb, vf);
diff --git a/libavfilter/f_loop.c b/libavfilter/f_loop.c
new file mode 100644
index 000..beef4fc
--- /dev/null
+++ b/libavfilter/f_loop.c
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2016 Paul B Mahol
+ *
+ * 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/avassert.h"
+#include "libavutil/fifo.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "audio.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct LoopContext {
+const AVClass *class;
+
+AVFrame **frames;
+int nb_frames;
+int current_frame;
+int64_t start_pts;
+int64_t duration;
+
+int loop;
+int size;
+int64_t start;
+} LoopContext;
+
+#define OFFSET(x) offsetof(LoopContext, x)
+#define DEFINE_OPTIONS(filt_name, FLAGS) \
+static const AVOption filt_name##_options[] = { \
+{ "loop",  "number of loops",  OFFSET(loop),  AV_OPT_TYPE_INT,   {.i64 = 0 }, -1, INT_MAX,   FLAGS }, \
+{ "size",  "max number of frames to loop", OFFSET(size),  AV_OPT_TYPE_INT,   {.i64 = 0 },  0, INT16_MAX, FLAGS }, \
+{ "start", "set the loop start frame", OFFSET(start), AV_OPT_TYPE_INT64, {.i64 = 0 },  0, INT64_MAX, FLAGS }, \
+{ NULL } \
+}
+
+static av_cold int init(AVFilterContext *ctx)
+{
+LoopContext *s = ctx->priv;
+
+s->frames = av_calloc(s->size, sizeof(*s->frames));
+if (!s->frames)
+return AVERROR(ENOMEM);
+
+return 0;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+LoopContext *s =