[FFmpeg-devel] [PATCH] avfilter: add dumpwave filter.
From: Dmytro Humeniuk Signed-off-by: Dmytro Humeniuk --- Changelog | 1 + libavfilter/Makefile | 1 + libavfilter/af_dumpwave.c | 273 + libavfilter/allfilters.c | 1 + libavfilter/version.h | 4 +- tests/fate/filter-audio.mak| 5 + tests/ref/fate/filter-dumpwave | 1 + 7 files changed, 284 insertions(+), 2 deletions(-) create mode 100644 libavfilter/af_dumpwave.c create mode 100644 tests/ref/fate/filter-dumpwave diff --git a/Changelog b/Changelog index 61075b3392..40fd624449 100644 --- a/Changelog +++ b/Changelog @@ -38,6 +38,7 @@ version : - Removed the ffserver program - Removed the ffmenc and ffmdec muxer and demuxer - VideoToolbox HEVC encoder and hwaccel +- dumpwave audio filter version 3.4: diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 256dfabd66..020d90ee01 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -122,6 +122,7 @@ OBJS-$(CONFIG_TREMOLO_FILTER)+= af_tremolo.o OBJS-$(CONFIG_VIBRATO_FILTER)+= af_vibrato.o generate_wave_table.o OBJS-$(CONFIG_VOLUME_FILTER) += af_volume.o OBJS-$(CONFIG_VOLUMEDETECT_FILTER) += af_volumedetect.o +OBJS-$(CONFIG_DUMPWAVE_FILTER) += af_dumpwave.o OBJS-$(CONFIG_AEVALSRC_FILTER) += aeval.o OBJS-$(CONFIG_ANOISESRC_FILTER) += asrc_anoisesrc.o diff --git a/libavfilter/af_dumpwave.c b/libavfilter/af_dumpwave.c new file mode 100644 index 00..493b5b7ff2 --- /dev/null +++ b/libavfilter/af_dumpwave.c @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2017 Dmytro Humeniuk + * + * 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 + * waveform audio filter – dumps RMS amplitude to JSON file like SoundCloud does + */ + +#include "libavutil/avassert.h" +#include "libavutil/avstring.h" +#include "libavutil/channel_layout.h" +#include "libavutil/opt.h" +#include "libavutil/parseutils.h" +#include "avfilter.h" +#include "formats.h" +#include "audio.h" +#include "internal.h" + +typedef struct DumpWaveContext { +const AVClass *class; +int w, h; +AVRational rate; +int col; +char *json; +char *str; +double *values; +int64_t c, n, max_samples; +double sum; /* sum of the squared samples per segment */ +} DumpWaveContext; + +#define OFFSET(x) offsetof(DumpWaveContext, x) +#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM + +static const AVOption dumpwave_options[] = { +{ "s","set dump size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS }, +{ "c", "set number of samples per item", OFFSET(c), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, FLAGS }, +{ "json", "set dump file", OFFSET(json), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS }, +{ NULL } +}; + +AVFILTER_DEFINE_CLASS(dumpwave); + +static int config_output(AVFilterLink *outlink) +{ +DumpWaveContext *dumpwave = outlink->src->priv; +const int ch_width = dumpwave->w; +dumpwave->values = av_malloc(ch_width * sizeof(double)); +dumpwave->str = av_malloc(ch_width*sizeof(int)); +dumpwave->max_samples = dumpwave->c * outlink->channels; + +return 0; +} + +static av_cold void uninit(AVFilterContext *ctx) +{ +DumpWaveContext *dumpwave = ctx->priv; +const int ch_height = dumpwave->h; +const int ch_width = dumpwave->w; +char *result = dumpwave->str; +FILE *dump_fp = NULL; + +if (dumpwave->json && !(dump_fp = av_fopen_utf8(dumpwave->json, "w"))) +av_log(ctx, AV_LOG_WARNING, "dump failed.\n"); + +if (dump_fp) { +fprintf(dump_fp, "{\"width\":%d,\"height\":%d,\"samples\":[%s]}", ch_width, ch_height, result); +fclose(dump_fp); +} +av_freep(&dumpwave->str); +av_freep(&dumpwave->values); +} + +static int dumpwave_request_frame(AVFilterLink *outlink) +{ +AVFilterContext *ctx = outlink->src; +DumpWaveContext *dumpwave = ctx->priv; +const int ch_height = dumpwave->h; +const int ch_width = dumpwave->w; +const double *values = dumpwave->values; +char *result = dumpwave->str; + +AVFilterLink *inlink = ctx->inputs[0]; +int ret, val; + +ret = ff_request_
[FFmpeg-devel] dumpwave audio filter
Let me introduce dumpwave waveform audio filter – dumps RMS amplitude to JSON file just like SoundCloud does As there is no duration knowledge, samples count should be precalculated ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] add dumpwave filter
From: Dmytro Humeniuk Signed-off-by: Dmytro Humeniuk --- Changelog | 1 + doc/filters.texi | 23 libavfilter/Makefile | 1 + libavfilter/af_dumpwave.c | 285 + libavfilter/allfilters.c | 1 + libavfilter/version.h | 4 +- tests/fate/filter-audio.mak| 5 + tests/ref/fate/filter-dumpwave | 1 + 8 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 libavfilter/af_dumpwave.c create mode 100644 tests/ref/fate/filter-dumpwave diff --git a/Changelog b/Changelog index 61075b3392..40fd624449 100644 --- a/Changelog +++ b/Changelog @@ -38,6 +38,7 @@ version : - Removed the ffserver program - Removed the ffmenc and ffmdec muxer and demuxer - VideoToolbox HEVC encoder and hwaccel +- dumpwave audio filter version 3.4: diff --git a/doc/filters.texi b/doc/filters.texi index d29c40080f..98e54aec6e 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2529,6 +2529,29 @@ Optional. It should have a value much less than 1 (e.g. 0.05 or 0.02) and is used to prevent clipping. @end table +@section dumpwave +Dumps RMS amplitude to JSON file. +Converts samples to decibels and calculates RMS (Root-Mean-Square) audio power scaled to desired values. + +@table @option +@item d +Dimensions @code{WxH}. +@code{W} - number of data values in json, values will be scaled according to @code{H}. +The default value is @var{640x480} + +@item s +Samples count per value per channel + +@item json +Path to json file +@end table + +For example, to generate RMS amplitude for 44.1 kHz 6 seconds length audio +with dimensions @var{1800x140}, samples count @code{44100*6/1800=147} and store it to @var{/tmp/out.json}, you might use: +@example +dumpwave=d=1800x140:s=147:json=/tmp/out.json +@end example + @section dynaudnorm Dynamic Audio Normalizer. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index ef4729dd3f..2ffbc9497a 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -87,6 +87,7 @@ OBJS-$(CONFIG_COMPENSATIONDELAY_FILTER) += af_compensationdelay.o OBJS-$(CONFIG_CROSSFEED_FILTER) += af_crossfeed.o OBJS-$(CONFIG_CRYSTALIZER_FILTER)+= af_crystalizer.o OBJS-$(CONFIG_DCSHIFT_FILTER)+= af_dcshift.o +OBJS-$(CONFIG_DUMPWAVE_FILTER) += af_dumpwave.o OBJS-$(CONFIG_DYNAUDNORM_FILTER) += af_dynaudnorm.o OBJS-$(CONFIG_EARWAX_FILTER) += af_earwax.o OBJS-$(CONFIG_EBUR128_FILTER)+= f_ebur128.o diff --git a/libavfilter/af_dumpwave.c b/libavfilter/af_dumpwave.c new file mode 100644 index 00..a1aa33d090 --- /dev/null +++ b/libavfilter/af_dumpwave.c @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2017 Dmytro Humeniuk + * + * 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 + * waveform audio filter – dumps RMS amplitude to JSON file like SoundCloud does + */ + +#include "libavutil/avassert.h" +#include "libavutil/avstring.h" +#include "libavutil/channel_layout.h" +#include "libavutil/opt.h" +#include "libavutil/parseutils.h" +#include "avfilter.h" +#include "formats.h" +#include "audio.h" +#include "internal.h" + +typedef struct DumpWaveContext { +const AVClass *class; /**< class for AVOptions */ +int w; /**< number of data values in json */ +int h; /**< values will be scaled according to provided */ +int is_disabled;/**< disable filter in case it's misconfigured */ +int i; /**< index of value */ +char *json; /**< path to json */ +char *str; /**< comma separated values */ +double *values; /**< scaling factors */ +int64_t s; /**< samples per value per channel */ +int64_t n; /**< current number of samples counted */ +int64_t max_samples;/**< samples per value */ +double sum; /**< sum of the squared samples per value */ +} DumpWaveContext; + +#define OFFSET(x) offsetof(DumpWaveContext, x) +#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM + +static const AVOption dumpwave_options[] = { +{ "d", "set width and height", OFFSET(w), AV_OPT_TYPE_IMAGE_SI
Re: [FFmpeg-devel] [PATCH] avfilter: add dumpwave filter.
Hi, >Can you provide some context for this? Please add docs as well. filter converts samples to decibels and calculates RMS (Root-Mean-Square) audio power scaled to desired values, it supposed to generate something like SoundCloud does http://plnkr.co/edit/WeppGcEPQiOyKDsA0C4Y I added docs. >Can't really test this because it segfaults for me: ./ffmpeg -f lavfi >-i anoisesrc -af dumpwave -f null - it expected some config - fixed >Just set the sample format to something like AV_SAMPLE_FMT_DBL in >query_format. There's no need for this big switch statement. it handles samples in different way, you may look at the astats filter 2018-01-08 23:58 GMT+01:00 Kyle Swanson : > Hi, > > Can you provide some context for this? Please add docs as well. > Can't really test this because it segfaults for me: ./ffmpeg -f lavfi > -i anoisesrc -af dumpwave -f null - > > On Sun, Jan 7, 2018 at 4:36 PM, wrote: >> >> From: Dmytro Humeniuk >> >> Signed-off-by: Dmytro Humeniuk >> --- >> Changelog | 1 + >> libavfilter/Makefile | 1 + >> libavfilter/af_dumpwave.c | 273 >> + >> libavfilter/allfilters.c | 1 + >> libavfilter/version.h | 4 +- >> tests/fate/filter-audio.mak| 5 + >> tests/ref/fate/filter-dumpwave | 1 + >> 7 files changed, 284 insertions(+), 2 deletions(-) >> create mode 100644 libavfilter/af_dumpwave.c >> create mode 100644 tests/ref/fate/filter-dumpwave >> >> diff --git a/Changelog b/Changelog >> index 61075b3392..40fd624449 100644 >> --- a/Changelog >> +++ b/Changelog >> @@ -38,6 +38,7 @@ version : >> - Removed the ffserver program >> - Removed the ffmenc and ffmdec muxer and demuxer >> - VideoToolbox HEVC encoder and hwaccel >> +- dumpwave audio filter >> >> >> version 3.4: >> diff --git a/libavfilter/Makefile b/libavfilter/Makefile >> index 256dfabd66..020d90ee01 100644 >> --- a/libavfilter/Makefile >> +++ b/libavfilter/Makefile >> @@ -122,6 +122,7 @@ OBJS-$(CONFIG_TREMOLO_FILTER)+= >> af_tremolo.o >> OBJS-$(CONFIG_VIBRATO_FILTER)+= af_vibrato.o >> generate_wave_table.o >> OBJS-$(CONFIG_VOLUME_FILTER) += af_volume.o >> OBJS-$(CONFIG_VOLUMEDETECT_FILTER) += af_volumedetect.o >> +OBJS-$(CONFIG_DUMPWAVE_FILTER) += af_dumpwave.o >> >> OBJS-$(CONFIG_AEVALSRC_FILTER) += aeval.o >> OBJS-$(CONFIG_ANOISESRC_FILTER) += asrc_anoisesrc.o >> diff --git a/libavfilter/af_dumpwave.c b/libavfilter/af_dumpwave.c >> new file mode 100644 >> index 00..493b5b7ff2 >> --- /dev/null >> +++ b/libavfilter/af_dumpwave.c >> @@ -0,0 +1,273 @@ >> +/* >> + * Copyright (c) 2017 Dmytro Humeniuk >> + * >> + * 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 >> + * waveform audio filter – dumps RMS amplitude to JSON file like SoundCloud >> does >> + */ >> + >> +#include "libavutil/avassert.h" >> +#include "libavutil/avstring.h" >> +#include "libavutil/channel_layout.h" >> +#include "libavutil/opt.h" >> +#include "libavutil/parseutils.h" >> +#include "avfilter.h" >> +#include "formats.h" >> +#include "audio.h" >> +#include "internal.h" >> + >> +typedef struct DumpWaveContext { >> +const AVClass *class; >> +int w, h; >> +AVRational rate; >> +int col; >> +char *json; >> +char *str; >> +double *values; >> +int64_t c, n, max_samples; >> +double sum; /* sum of the squared samples per segment */ >> +} DumpWaveContext; >> + >> +#define OFFSET(x) offsetof(DumpWaveContext, x) >> +#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM >> + >> +static const AVOption dumpwave_options[] = { >> +{ "s","set dump size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = >> "600x240"}, 0, 0, FLAGS }, >> +{ "c", "set number of samples per item", OFFSET(c), AV_OPT_TYPE_INT64, >> {.i64 = 0}, 0, INT64_MAX, FLAGS }, > > Use more descriptive parameter names. Also, per item? What is an item? > >> +{ "json", "set dump file", OFFSET(json), AV_OPT_TYPE_STRING, { .str = >> NULL }, 0, 0, FLAGS }, >> +{ NULL } >> +}; >> + >> +AVFILTER_DEFINE_CLASS(dumpwave); >> + >> +static int config_output(AVFilterL
[FFmpeg-devel] [PATCH] avfilter: add dumpwave filter.
From: Dmytro Humeniuk Signed-off-by: Dmytro Humeniuk --- Changelog | 1 + doc/filters.texi | 23 libavfilter/Makefile | 1 + libavfilter/af_dumpwave.c | 285 + libavfilter/allfilters.c | 1 + libavfilter/version.h | 4 +- tests/fate/filter-audio.mak| 5 + tests/ref/fate/filter-dumpwave | 1 + 8 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 libavfilter/af_dumpwave.c create mode 100644 tests/ref/fate/filter-dumpwave diff --git a/Changelog b/Changelog index 61075b3392..40fd624449 100644 --- a/Changelog +++ b/Changelog @@ -38,6 +38,7 @@ version : - Removed the ffserver program - Removed the ffmenc and ffmdec muxer and demuxer - VideoToolbox HEVC encoder and hwaccel +- dumpwave audio filter version 3.4: diff --git a/doc/filters.texi b/doc/filters.texi index d29c40080f..98e54aec6e 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2529,6 +2529,29 @@ Optional. It should have a value much less than 1 (e.g. 0.05 or 0.02) and is used to prevent clipping. @end table +@section dumpwave +Dumps RMS amplitude to JSON file. +Converts samples to decibels and calculates RMS (Root-Mean-Square) audio power scaled to desired values. + +@table @option +@item d +Dimensions @code{WxH}. +@code{W} - number of data values in json, values will be scaled according to @code{H}. +The default value is @var{640x480} + +@item s +Samples count per value per channel + +@item json +Path to json file +@end table + +For example, to generate RMS amplitude for 44.1 kHz 6 seconds length audio +with dimensions @var{1800x140}, samples count @code{44100*6/1800=147} and store it to @var{/tmp/out.json}, you might use: +@example +dumpwave=d=1800x140:s=147:json=/tmp/out.json +@end example + @section dynaudnorm Dynamic Audio Normalizer. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index ef4729dd3f..2ffbc9497a 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -87,6 +87,7 @@ OBJS-$(CONFIG_COMPENSATIONDELAY_FILTER) += af_compensationdelay.o OBJS-$(CONFIG_CROSSFEED_FILTER) += af_crossfeed.o OBJS-$(CONFIG_CRYSTALIZER_FILTER)+= af_crystalizer.o OBJS-$(CONFIG_DCSHIFT_FILTER)+= af_dcshift.o +OBJS-$(CONFIG_DUMPWAVE_FILTER) += af_dumpwave.o OBJS-$(CONFIG_DYNAUDNORM_FILTER) += af_dynaudnorm.o OBJS-$(CONFIG_EARWAX_FILTER) += af_earwax.o OBJS-$(CONFIG_EBUR128_FILTER)+= f_ebur128.o diff --git a/libavfilter/af_dumpwave.c b/libavfilter/af_dumpwave.c new file mode 100644 index 00..35b970af6c --- /dev/null +++ b/libavfilter/af_dumpwave.c @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2017 Dmytro Humeniuk + * + * 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 + * waveform audio filter – dumps RMS amplitude to JSON file + */ + +#include "libavutil/avassert.h" +#include "libavutil/avstring.h" +#include "libavutil/channel_layout.h" +#include "libavutil/opt.h" +#include "libavutil/parseutils.h" +#include "avfilter.h" +#include "formats.h" +#include "audio.h" +#include "internal.h" + +typedef struct DumpWaveContext { +const AVClass *class; /**< class for AVOptions */ +int w; /**< number of data values in json */ +int h; /**< values will be scaled according to provided */ +int is_disabled;/**< disable filter in case it's misconfigured */ +int i; /**< index of value */ +char *json; /**< path to json */ +char *str; /**< comma separated values */ +double *values; /**< scaling factors */ +int64_t s; /**< samples per value per channel */ +int64_t n; /**< current number of samples counted */ +int64_t max_samples;/**< samples per value */ +double sum; /**< sum of the squared samples per value */ +} DumpWaveContext; + +#define OFFSET(x) offsetof(DumpWaveContext, x) +#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM + +static const AVOption dumpwave_options[] = { +{ "d", "set width and height", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x480"
Re: [FFmpeg-devel] [PATCH] avfilter: add dumpwave filter.
Hello 2018-01-10 11:33 GMT+01:00 Moritz Barsnick : > On Wed, Jan 10, 2018 at 08:58:05 +0100, dmitry.gumen...@gmail.com wrote: > >> +@table @option >> +@item d >> +Dimensions @code{WxH}. >> +@code{W} - number of data values in json, values will be scaled according >> to @code{H}. >> +The default value is @var{640x480} >> + >> +@item s >> +Samples count per value per channel > > In most other filters/filtersources, s+size is used for dimensions, > d+duration for time, and n for an amount/number of frames/samples or > so. Might be a good idea to align with this. And use aliases (i.e. > implement both "s" and "size"). > >> +static const AVOption dumpwave_options[] = { >> +{ "d", "set width and height", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str >> = "640x480"}, 0, 0, FLAGS }, >> +{ "s", "set number of samples per value per channel", OFFSET(s), >> AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, FLAGS }, >> +{ "json", "set json dump file", OFFSET(json), AV_OPT_TYPE_STRING, { >> .str = NULL }, 0, 0, FLAGS }, >> +{ NULL } > [...] >> +static av_cold int init(AVFilterContext *ctx) >> +{ >> +DumpWaveContext *dumpwave = ctx->priv; >> +if(!dumpwave->s) { >> +dumpwave->is_disabled = 1; >> +av_log(ctx, AV_LOG_ERROR, "Invalid samples per value config\n"); >> +} >> +return 0; > > I don't like the idea of having to provide the "s" parameter. Is there > really no useful default? > > And now, if s=0, what does the filter do? Just sit around? Couldn't it > fail instead? > > Apart from that: > "if (" is the bracket style ffmpeg uses. > >> +if (dumpwave->json && !(dump_fp = av_fopen_utf8(dumpwave->json, >> "w"))) >> +av_log(ctx, AV_LOG_WARNING, "Flushing dump failed\n"); > > I would appreciate evaluation of errno and printing the appropriate > string (using av_strerror(), I believe). > >> +switch (inlink->format) { >> +case AV_SAMPLE_FMT_DBLP: > > As Kyle hinted: Can this not force a conversion (implicit insertion of > aformat filter) to e.g. double by only supporting this format, and > reducing this switch to one or two cases? (The filter's output isn't > really meant for transparent reuse anyway? af_volumedetect e.g. also > supports only one, meaning its output can be a different format than > its input.) It's also really hard to go through and later to maintain. > It the big switch/case remains, one or two code macros would be > appropriate. I checked solution used in volumedetect and couldn't find a way to read across formats. How would you implement such macros? Since version 3.2 astats filter uses same approach for reading different formats and as far as I know macros harder to debug >> +for (i = 0; i < buf->nb_samples; i++) { >> +for (c = 0; c < channels; c++, src++) >> +calc_db_rms(dumpwave, *src); >> +}} > > I believe the curly brackets need to be placed differently. > >> +.description = NULL_IF_CONFIG_SMALL("Dumps RMS amplitude to JSON >> file"), > > Imperative, i.e. "Dump RMS ...". > >> +FATE_AFILTER-$(call FILTERDEMDEC, DUMPWAVE, WAV, PCM_S16LE) += >> fate-filter-dumpwave >> +fate-filter-dumpwave: SRC = $(TARGET_PATH)/tests/data/asynth-44100-2.wav >> +fate-filter-dumpwave: CMD = ffmpeg -i $(SRC) -af >> dumpwave=d=1800x140:s=147:json=$(TARGET_PATH)/tests/data/fate/filter-dumpwave.out >> -f null - && cat $(TARGET_PATH)/tests/data/fate/filter-dumpwave.out >> + > > If you need to implement all formats, you might want to test them all. > Just a thought. > > Moritz > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add dumpwave filter.
> On 11 Jan 2018, at 22:41, Paul B Mahol wrote: > >> On 1/11/18, Dmitry Gumenyuk wrote: >> Hello >> >> 2018-01-10 11:33 GMT+01:00 Moritz Barsnick : >>>> On Wed, Jan 10, 2018 at 08:58:05 +0100, dmitry.gumen...@gmail.com wrote: >>>> >>>> +@table @option >>>> +@item d >>>> +Dimensions @code{WxH}. >>>> +@code{W} - number of data values in json, values will be scaled >>>> according to @code{H}. >>>> +The default value is @var{640x480} >>>> + >>>> +@item s >>>> +Samples count per value per channel >>> >>> In most other filters/filtersources, s+size is used for dimensions, >>> d+duration for time, and n for an amount/number of frames/samples or >>> so. Might be a good idea to align with this. And use aliases (i.e. >>> implement both "s" and "size"). >>> >>>> +static const AVOption dumpwave_options[] = { >>>> +{ "d", "set width and height", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, >>>> {.str = "640x480"}, 0, 0, FLAGS }, >>>> +{ "s", "set number of samples per value per channel", OFFSET(s), >>>> AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, FLAGS }, >>>> +{ "json", "set json dump file", OFFSET(json), AV_OPT_TYPE_STRING, { >>>> .str = NULL }, 0, 0, FLAGS }, >>>> +{ NULL } >>> [...] >>>> +static av_cold int init(AVFilterContext *ctx) >>>> +{ >>>> +DumpWaveContext *dumpwave = ctx->priv; >>>> +if(!dumpwave->s) { >>>> +dumpwave->is_disabled = 1; >>>> +av_log(ctx, AV_LOG_ERROR, "Invalid samples per value config\n"); >>>> +} >>>> +return 0; >>> >>> I don't like the idea of having to provide the "s" parameter. Is there >>> really no useful default? >>> >>> And now, if s=0, what does the filter do? Just sit around? Couldn't it >>> fail instead? >>> >>> Apart from that: >>> "if (" is the bracket style ffmpeg uses. >>> >>>> +if (dumpwave->json && !(dump_fp = av_fopen_utf8(dumpwave->json, >>>> "w"))) >>>> +av_log(ctx, AV_LOG_WARNING, "Flushing dump failed\n"); >>> >>> I would appreciate evaluation of errno and printing the appropriate >>> string (using av_strerror(), I believe). >>> >>>> +switch (inlink->format) { >>>> +case AV_SAMPLE_FMT_DBLP: >>> >>> As Kyle hinted: Can this not force a conversion (implicit insertion of >>> aformat filter) to e.g. double by only supporting this format, and >>> reducing this switch to one or two cases? (The filter's output isn't >>> really meant for transparent reuse anyway? af_volumedetect e.g. also >>> supports only one, meaning its output can be a different format than >>> its input.) It's also really hard to go through and later to maintain. >>> It the big switch/case remains, one or two code macros would be >>> appropriate. >> >> I checked solution used in volumedetect and couldn't find a way to >> read across formats. > > I do not understand what you are trying to do. Sorry, I'm trying to add support for 8, 16, 24, 32, 64 bit sample formats >> How would you implement such macros? Since version 3.2 astats filter >> uses same approach for reading different formats and as far as I know >> macros harder to debug > > astats is using all formats because of numerous reasons. astats uses raw > values, > your filter just convert each raw value to float representation. Is this wrong, as I'd like to have high precision? > This filter does not need support for so many formats, it could > support just s16. > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel smime.p7s Description: S/MIME cryptographic signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add dumpwave filter.
> On 11 Jan 2018, at 23:02, Paul B Mahol wrote: > >> On 1/11/18, Dmitry Gumenyuk wrote: >> >>>> On 11 Jan 2018, at 22:41, Paul B Mahol wrote: >>>> >>>> On 1/11/18, Dmitry Gumenyuk wrote: >>>> Hello >>>> >>>> 2018-01-10 11:33 GMT+01:00 Moritz Barsnick : >>>>>> On Wed, Jan 10, 2018 at 08:58:05 +0100, dmitry.gumen...@gmail.com >>>>>> wrote: >>>>>> >>>>>> +@table @option >>>>>> +@item d >>>>>> +Dimensions @code{WxH}. >>>>>> +@code{W} - number of data values in json, values will be scaled >>>>>> according to @code{H}. >>>>>> +The default value is @var{640x480} >>>>>> + >>>>>> +@item s >>>>>> +Samples count per value per channel >>>>> >>>>> In most other filters/filtersources, s+size is used for dimensions, >>>>> d+duration for time, and n for an amount/number of frames/samples or >>>>> so. Might be a good idea to align with this. And use aliases (i.e. >>>>> implement both "s" and "size"). >>>>> >>>>>> +static const AVOption dumpwave_options[] = { >>>>>> +{ "d", "set width and height", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, >>>>>> {.str = "640x480"}, 0, 0, FLAGS }, >>>>>> +{ "s", "set number of samples per value per channel", OFFSET(s), >>>>>> AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, FLAGS }, >>>>>> +{ "json", "set json dump file", OFFSET(json), AV_OPT_TYPE_STRING, >>>>>> { >>>>>> .str = NULL }, 0, 0, FLAGS }, >>>>>> +{ NULL } >>>>> [...] >>>>>> +static av_cold int init(AVFilterContext *ctx) >>>>>> +{ >>>>>> +DumpWaveContext *dumpwave = ctx->priv; >>>>>> +if(!dumpwave->s) { >>>>>> +dumpwave->is_disabled = 1; >>>>>> +av_log(ctx, AV_LOG_ERROR, "Invalid samples per value >>>>>> config\n"); >>>>>> +} >>>>>> +return 0; >>>>> >>>>> I don't like the idea of having to provide the "s" parameter. Is there >>>>> really no useful default? >>>>> >>>>> And now, if s=0, what does the filter do? Just sit around? Couldn't it >>>>> fail instead? >>>>> >>>>> Apart from that: >>>>> "if (" is the bracket style ffmpeg uses. >>>>> >>>>>> +if (dumpwave->json && !(dump_fp = >>>>>> av_fopen_utf8(dumpwave->json, >>>>>> "w"))) >>>>>> +av_log(ctx, AV_LOG_WARNING, "Flushing dump failed\n"); >>>>> >>>>> I would appreciate evaluation of errno and printing the appropriate >>>>> string (using av_strerror(), I believe). >>>>> >>>>>> +switch (inlink->format) { >>>>>> +case AV_SAMPLE_FMT_DBLP: >>>>> >>>>> As Kyle hinted: Can this not force a conversion (implicit insertion of >>>>> aformat filter) to e.g. double by only supporting this format, and >>>>> reducing this switch to one or two cases? (The filter's output isn't >>>>> really meant for transparent reuse anyway? af_volumedetect e.g. also >>>>> supports only one, meaning its output can be a different format than >>>>> its input.) It's also really hard to go through and later to maintain. >>>>> It the big switch/case remains, one or two code macros would be >>>>> appropriate. >>>> >>>> I checked solution used in volumedetect and couldn't find a way to >>>> read across formats. >>> >>> I do not understand what you are trying to do. >> Sorry, I'm trying to add support for 8, 16, 24, 32, 64 bit sample formats >>>> How would you implement such macros? Since version 3.2 astats filter >>>> uses same approach for reading different formats and as far as I know >>>> macros harder to debug >>> >>> astats is using all formats because of numerous reasons. astats uses raw >>> values, >>> your filter just convert each raw value to float representation. >> Is this wrong, as I'd like to have high precision? > > For rendering to small size image? Data can be used for analysis as well. Any size I would say as user may define size > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel smime.p7s Description: S/MIME cryptographic signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add dumpwave filter.
-- Best regards, Dmytro > On 11 Jan 2018, at 23:57, Paul B Mahol wrote: > >> On 1/11/18, Dmitry Gumenyuk wrote: >> >>>> On 11 Jan 2018, at 23:02, Paul B Mahol wrote: >>>> >>>> On 1/11/18, Dmitry Gumenyuk wrote: >>>> >>>>>> On 11 Jan 2018, at 22:41, Paul B Mahol wrote: >>>>>> >>>>>> On 1/11/18, Dmitry Gumenyuk wrote: >>>>>> Hello >>>>>> >>>>>> 2018-01-10 11:33 GMT+01:00 Moritz Barsnick : >>>>>>>> On Wed, Jan 10, 2018 at 08:58:05 +0100, dmitry.gumen...@gmail.com >>>>>>>> wrote: >>>>>>>> >>>>>>>> +@table @option >>>>>>>> +@item d >>>>>>>> +Dimensions @code{WxH}. >>>>>>>> +@code{W} - number of data values in json, values will be scaled >>>>>>>> according to @code{H}. >>>>>>>> +The default value is @var{640x480} >>>>>>>> + >>>>>>>> +@item s >>>>>>>> +Samples count per value per channel >>>>>>> >>>>>>> In most other filters/filtersources, s+size is used for dimensions, >>>>>>> d+duration for time, and n for an amount/number of frames/samples or >>>>>>> so. Might be a good idea to align with this. And use aliases (i.e. >>>>>>> implement both "s" and "size"). >>>>>>> >>>>>>>> +static const AVOption dumpwave_options[] = { >>>>>>>> +{ "d", "set width and height", OFFSET(w), >>>>>>>> AV_OPT_TYPE_IMAGE_SIZE, >>>>>>>> {.str = "640x480"}, 0, 0, FLAGS }, >>>>>>>> +{ "s", "set number of samples per value per channel", >>>>>>>> OFFSET(s), >>>>>>>> AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, FLAGS }, >>>>>>>> +{ "json", "set json dump file", OFFSET(json), >>>>>>>> AV_OPT_TYPE_STRING, >>>>>>>> { >>>>>>>> .str = NULL }, 0, 0, FLAGS }, >>>>>>>> +{ NULL } >>>>>>> [...] >>>>>>>> +static av_cold int init(AVFilterContext *ctx) >>>>>>>> +{ >>>>>>>> +DumpWaveContext *dumpwave = ctx->priv; >>>>>>>> +if(!dumpwave->s) { >>>>>>>> +dumpwave->is_disabled = 1; >>>>>>>> +av_log(ctx, AV_LOG_ERROR, "Invalid samples per value >>>>>>>> config\n"); >>>>>>>> +} >>>>>>>> +return 0; >>>>>>> >>>>>>> I don't like the idea of having to provide the "s" parameter. Is >>>>>>> there >>>>>>> really no useful default? >>>>>>> >>>>>>> And now, if s=0, what does the filter do? Just sit around? Couldn't >>>>>>> it >>>>>>> fail instead? >>>>>>> >>>>>>> Apart from that: >>>>>>> "if (" is the bracket style ffmpeg uses. >>>>>>> >>>>>>>> +if (dumpwave->json && !(dump_fp = >>>>>>>> av_fopen_utf8(dumpwave->json, >>>>>>>> "w"))) >>>>>>>> +av_log(ctx, AV_LOG_WARNING, "Flushing dump failed\n"); >>>>>>> >>>>>>> I would appreciate evaluation of errno and printing the appropriate >>>>>>> string (using av_strerror(), I believe). >>>>>>> >>>>>>>> +switch (inlink->format) { >>>>>>>> +case AV_SAMPLE_FMT_DBLP: >>>>>>> >>>>>>> As Kyle hinted: Can this not force a conversion (implicit insertion >>>>>>> of >>>>>>> aformat filter) to e.g. double by only supporting this format, and >>>>>>> reducing this switch to one or two cases? (The filter's output isn't >>>>>>> really meant for transparent reuse anyway? af_volumedetect e.g. also >>>>>>> supports only one, meaning its output can be a different format than >>>>>>> its input.) It's also really hard to go through and later to >>>>>>> maintain. >>>>>>> It the big switch/case remains, one or two code macros would be >>>>>>> appropriate. >>>>>> >>>>>> I checked solution used in volumedetect and couldn't find a way to >>>>>> read across formats. >>>>> >>>>> I do not understand what you are trying to do. >>>> Sorry, I'm trying to add support for 8, 16, 24, 32, 64 bit sample >>>> formats >>>>>> How would you implement such macros? Since version 3.2 astats filter >>>>>> uses same approach for reading different formats and as far as I know >>>>>> macros harder to debug >>>>> >>>>> astats is using all formats because of numerous reasons. astats uses >>>>> raw >>>>> values, >>>>> your filter just convert each raw value to float representation. >>>> Is this wrong, as I'd like to have high precision? >>> >>> For rendering to small size image? >> Data can be used for analysis as well. Any size I would say as user may >> define size > > Than use floats. Ok, will give it a try > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel smime.p7s Description: S/MIME cryptographic signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH v2] avfilter: add dumpwave filter.
> On 12 Jan 2018, at 08:36, Kyle Swanson wrote: > > Hi, > > Make sure you go back and read our comments. There were several things you > didn't address in your most recent patch. Sorry, seems I missed few emails. Sure > Thanks, > Kyle > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel smime.p7s Description: S/MIME cryptographic signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel