[FFmpeg-devel] [PATCH] lavfi: add asetnsamples filter

Stefano Sabatini stefasab at gmail.com
Tue Jun 12 01:28:03 CEST 2012


On date Monday 2012-06-11 00:29:19 +0200, Clément Bœsch encoded:
> On Mon, Jun 11, 2012 at 12:09:05AM +0200, Stefano Sabatini wrote:
> > On date Saturday 2012-02-25 01:00:03 +0100, Stefano Sabatini encoded:
> > > On date Thursday 2012-02-23 17:49:10 +0200, Andrey Utkin encoded:
> > > > Filter that changes number of samples on single output operation
> > > > ---
> > > >  libavfilter/Makefile           |    1 +
> > > >  libavfilter/af_asetframesize.c |  191 ++++++++++++++++++++++++++++++++++++++++
> > > >  libavfilter/allfilters.c       |    1 +
> > > >  3 files changed, 193 insertions(+), 0 deletions(-)
> > > >  create mode 100644 libavfilter/af_asetframesize.c
> > 
> > Updated against latest API, and making use of the nifty
> > libavutil/audio_buffer.
> > 
> > I'm not very satifisfied with the name of the filter, alternative
> > names which I also somehow dislike but which seem more proper are:
> > - asetnbsamples
> > - asetnsamples
> > - asetsamplesn
> > - asetsamplesnb
> 
> Agreed, another alternative: asetwinsize (for audio window size).

Changed to asetnsamples, shorter than asetframesize and less ambiguous
than asetframesize/asetwinsize.

> 
> > 
> > Also I don't know if I should add an option for padding the last
> > packet in order to have all the packets with the same size (this can
> > be added later though).
> 
> This kind of filter is especially useful when you want a fixed window size
> (for FFT for instance), where padding with silence is very welcome since
> you can use the output unconditionally; I would make it the default
> actually. It shouldn't be hard to add it with the help of
> lavu:av_samples_set_silence().

Yes good idea, done.
 
> > -- 
> > FFmpeg = Fiendish & Funny Minimalistic Practical Enlightened Guru
> 
> > From a58c7db8d5c627d7b454d2798cda83e1b1dbd190 Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefasab at gmail.com>
> > Date: Fri, 25 May 2012 13:14:53 +0200
> > Subject: [PATCH] lavfi: add asetframesize audio filter
> > 
> > The asetframesize filter changes the number of samples on single output
> > operation.
> > 
> > Based on a patch by Andrey Utkin <andrey.krieger.utkin at gmail.com>.
> > ---
> >  libavfilter/Makefile           |    1 +
> >  libavfilter/af_asetframesize.c |  176 ++++++++++++++++++++++++++++++++++++++++
> >  libavfilter/allfilters.c       |    1 +
> >  3 files changed, 178 insertions(+), 0 deletions(-)
> >  create mode 100644 libavfilter/af_asetframesize.c
> > 
> > diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> > index 2a0a283..d97c52a 100644
> > --- a/libavfilter/Makefile
> > +++ b/libavfilter/Makefile
> > @@ -50,6 +50,7 @@ OBJS-$(CONFIG_AMERGE_FILTER)                 += af_amerge.o
> >  OBJS-$(CONFIG_AMIX_FILTER)                   += af_amix.o
> >  OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
> >  OBJS-$(CONFIG_ARESAMPLE_FILTER)              += af_aresample.o
> > +OBJS-$(CONFIG_ASETFRAMESIZE_FILTER)          += af_asetframesize.o
> >  OBJS-$(CONFIG_ASHOWINFO_FILTER)              += af_ashowinfo.o
> >  OBJS-$(CONFIG_ASPLIT_FILTER)                 += split.o
> >  OBJS-$(CONFIG_ASTREAMSYNC_FILTER)            += af_astreamsync.o
> > diff --git a/libavfilter/af_asetframesize.c b/libavfilter/af_asetframesize.c
> > new file mode 100644
> > index 0000000..d46a87c
> > --- /dev/null
> > +++ b/libavfilter/af_asetframesize.c
> > @@ -0,0 +1,176 @@
> > +/*
> > + * Copyright (c) 2012 Andrey Utkin
> > + *
> 
> Maybe you could add yourself too?

Done.

> 
> > + * 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
> > + */
> > +
> > +/**
> > + * @file
> > + * Filter that changes number of samples on single output operation
> > + */
> > +
> > +#include "libavutil/audio_fifo.h"
> > +#include "libavutil/avassert.h"
> > +#include "avfilter.h"
> > +#include "audio.h"
> > +#include "formats.h"
> > +
> > +typedef struct {
> > +    int nb_out_samples;  ///< how many samples to output
> > +    AVAudioFifo *fifo;  ///< samples are queued here
> 
> nit+: align the comments

Fixed.
 
> [...]
> > +
> > +AVFilter avfilter_af_asetframesize = {
> > +    .name           = "asetframesize",
> > +    .description    = NULL_IF_CONFIG_SMALL("Set the number of samples for the output audio frames."),
> 
> Total number of samples, or samples per channel?

Reworded.
 
> [...]
> 

> Just curious: how do you plan to use this? By making some filters (such as
> af_show* filters) request a particular window size and auto insert the
> filter?

I wanted this to test my showwaves (it turned out that the problem was
in showwaves), but I believe the filter is useful for generic testing
purposes. Also it was apparently useful to the original contributor.
-- 
FFmpeg = Formidable & Frenzy Magic Philosofic Evil God
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-lavfi-add-asetnsamples-audio-filter.patch
Type: text/x-diff
Size: 10196 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120612/e244be32/attachment.bin>


More information about the ffmpeg-devel mailing list