* [FFmpeg-devel] [PATCH] avfilter/af_replaygain: export results into read-only options
@ 2023-05-05 23:53 Paul B Mahol
0 siblings, 0 replies; only message in thread
From: Paul B Mahol @ 2023-05-05 23:53 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 10 bytes --]
Attached.
[-- Attachment #2: 0001-avfilter-af_replaygain-export-results-into-read-only.patch --]
[-- Type: text/x-patch, Size: 3757 bytes --]
From 4c9bf661c74e598c623d05e4a170e5b48150e7cd Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Sat, 6 May 2023 01:50:08 +0200
Subject: [PATCH] avfilter/af_replaygain: export results into read-only options
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
doc/filters.texi | 10 ++++++++++
libavfilter/af_replaygain.c | 37 ++++++++++++++++++++++++++++++++-----
2 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 61c424a5fd..f5fc0811d7 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -6065,6 +6065,16 @@ ReplayGain scanner filter. This filter takes an audio stream as an input and
outputs it unchanged.
At end of filtering it displays @code{track_gain} and @code{track_peak}.
+The filter accepts the following exported read-only options:
+
+@table @option
+@item track_gain
+Exported track gain in dB at end of stream.
+
+@item track_peak
+Exported track peak at end of stream.
+@end table
+
@section resample
Convert the audio sample format, sample rate and channel layout. It is
diff --git a/libavfilter/af_replaygain.c b/libavfilter/af_replaygain.c
index 53852ac8bc..128454aa6b 100644
--- a/libavfilter/af_replaygain.c
+++ b/libavfilter/af_replaygain.c
@@ -23,8 +23,11 @@
* ReplayGain scanner
*/
+#include <float.h>
+
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
+#include "libavutil/opt.h"
#include "audio.h"
#include "avfilter.h"
#include "internal.h"
@@ -306,8 +309,11 @@ static const ReplayGainFreqInfo freqinfos[] =
};
typedef struct ReplayGainContext {
+ const AVClass *class;
+
uint32_t histogram[HISTOGRAM_SLOTS];
float peak;
+ float gain;
int yule_hist_i, butter_hist_i;
const double *yule_coeff_a;
const double *yule_coeff_b;
@@ -576,13 +582,22 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
return ff_filter_frame(outlink, in);
}
-static av_cold void uninit(AVFilterContext *ctx)
+static int request_frame(AVFilterLink *outlink)
{
+ AVFilterContext *ctx = outlink->src;
ReplayGainContext *s = ctx->priv;
- float gain = calc_replaygain(s->histogram);
+ int ret = 0;
- av_log(ctx, AV_LOG_INFO, "track_gain = %+.2f dB\n", gain);
- av_log(ctx, AV_LOG_INFO, "track_peak = %.6f\n", s->peak);
+ ret = ff_request_frame(ctx->inputs[0]);
+
+ if (ret == AVERROR_EOF) {
+ s->gain = calc_replaygain(s->histogram);
+
+ av_log(ctx, AV_LOG_INFO, "track_gain = %+.2f dB\n", s->gain);
+ av_log(ctx, AV_LOG_INFO, "track_peak = %.6f\n", s->peak);
+ }
+
+ return ret;
}
static const AVFilterPad replaygain_inputs[] = {
@@ -598,14 +613,26 @@ static const AVFilterPad replaygain_outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
+ .request_frame = request_frame,
},
};
+#define OFFSET(x) offsetof(ReplayGainContext, x)
+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_EXPORT|AV_OPT_FLAG_READONLY
+
+static const AVOption replaygain_options[] = {
+ { "track_gain", "track gain (dB)", OFFSET(gain), AV_OPT_TYPE_FLOAT,{.dbl=0}, -FLT_MAX, FLT_MAX, FLAGS },
+ { "track_peak", "track peak", OFFSET(peak), AV_OPT_TYPE_FLOAT,{.dbl=0}, -FLT_MAX, FLT_MAX, FLAGS },
+ { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(replaygain);
+
const AVFilter ff_af_replaygain = {
.name = "replaygain",
.description = NULL_IF_CONFIG_SMALL("ReplayGain scanner."),
- .uninit = uninit,
.priv_size = sizeof(ReplayGainContext),
+ .priv_class = &replaygain_class,
.flags = AVFILTER_FLAG_METADATA_ONLY,
FILTER_INPUTS(replaygain_inputs),
FILTER_OUTPUTS(replaygain_outputs),
--
2.39.1
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-05 23:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05 23:53 [FFmpeg-devel] [PATCH] avfilter/af_replaygain: export results into read-only options Paul B Mahol
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git