History

avfilter/f_ebur128: export results into read-only options

Paul B Mahol committed 3 years ago

Commit 1c8bf691 parent 71536423 files · +49 −13Browse files

Unified · Split

3 files
  1. doc/filters.texi +18 −0
  2. libavfilter/f_ebur128.c +30 −12
  3. libavfilter/version.h +1 −1
doc/filters.texi+18−0
@@ -28726,6 +28726,24 @@ live mixing). · 28725 unmodified lines
2872628726 Sets the display scale for the loudness. Valid parameters are @code{absolute}
2872728727 (in LUFS) or @code{relative} (LU) relative to the target. This only affects the
2872828728 video output, not the summary or continuous log output.
28729+
28730+@item integrated
28731+Read-only exported value for measured integrated loudness, in LUFS.
28732+
28733+@item range
28734+Read-only exported value for measured loudness range, in LU.
28735+
28736+@item lra_low
28737+Read-only exported value for measured LRA low, in LUFS.
28738+
28739+@item lra_high
28740+Read-only exported value for measured LRA high, in LUFS.
28741+
28742+@item sample_peak
28743+Read-only exported value for measured sample peak, in dBFS.
28744+
28745+@item true_peak
28746+Read-only exported value for measured true peak, in dBFS.
2872928747 @end table
2873028748
2873128749 @subsection Examples
libavfilter/f_ebur128.c+30−12
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 * @todo implement start/stop/reset through filter command injection
2727 */
2828
29+#include <float.h>
2930 #include <math.h>
3031
3132 #include "libavutil/avassert.h"
@@ -80,7 +81,9 @@ typedef struct EBUR128Context { · 48 unmodified lines
8081
8182 /* peak metering */
8283 int peak_mode; ///< enabled peak modes
84+ double true_peak; ///< global true peak
8385 double *true_peaks; ///< true peaks per channel
86+ double sample_peak; ///< global sample peak
8487 double *sample_peaks; ///< sample peaks per channel
8588 double *true_peaks_per_frame; ///< true peaks in a frame per channel
8689 #if CONFIG_SWRESAMPLE
@@ -159,6 +162,8 @@ enum { · 72 unmodified lines
159162 #define A AV_OPT_FLAG_AUDIO_PARAM
160163 #define V AV_OPT_FLAG_VIDEO_PARAM
161164 #define F AV_OPT_FLAG_FILTERING_PARAM
165+#define X AV_OPT_FLAG_EXPORT
166+#define R AV_OPT_FLAG_READONLY
162167 static const AVOption ebur128_options[] = {
163168 { "video", "set video output", OFFSET(do_video), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, V|F },
164169 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x480"}, 0, 0, V|F },
@@ -185,6 +190,12 @@ static const AVOption ebur128_options[] = { · 20 unmodified lines
185190 { "LUFS", "display absolute values (LUFS)", 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_TYPE_ABSOLUTE}, INT_MIN, INT_MAX, V|F, "scaletype" },
186191 { "relative", "display values relative to target (LU)", 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_TYPE_RELATIVE}, INT_MIN, INT_MAX, V|F, "scaletype" },
187192 { "LU", "display values relative to target (LU)", 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_TYPE_RELATIVE}, INT_MIN, INT_MAX, V|F, "scaletype" },
193+ { "integrated", "integrated loudness (LUFS)", OFFSET(integrated_loudness), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
194+ { "range", "loudness range (LU)", OFFSET(loudness_range), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
195+ { "lra_low", "LRA low (LUFS)", OFFSET(lra_low), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
196+ { "lra_high", "LRA high (LUFS)", OFFSET(lra_high), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
197+ { "sample_peak", "sample peak (dBFS)", OFFSET(sample_peak), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
198+ { "true_peak", "true peak (dBFS)", OFFSET(true_peak), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
188199 { NULL },
189200 };
190201
@@ -701,6 +712,20 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) · 510 unmodified lines
701712 ebur128->i3000.cache[ch][bin_id_3000] = bin;
702713 }
703714
715+#define FIND_PEAK(global, sp, ptype) do { \
716+ int ch; \
717+ double maxpeak; \
718+ maxpeak = 0.0; \
719+ if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
720+ for (ch = 0; ch < ebur128->nb_channels; ch++) \
721+ maxpeak = FFMAX(maxpeak, sp[ch]); \
722+ global = DBFS(maxpeak); \
723+ } \
724+} while (0)
725+
726+ FIND_PEAK(ebur128->sample_peak, ebur128->sample_peaks, SAMPLES);
727+ FIND_PEAK(ebur128->true_peak, ebur128->true_peaks, TRUE);
728+
704729 /* For integrated loudness, gating blocks are 400ms long with 75%
705730 * overlap (see BS.1770-2 p5), so a re-computation is needed each 100ms
706731 * (4800 samples at 48kHz). */
@@ -1023,7 +1048,6 @@ static int query_formats(AVFilterContext *ctx) · 316 unmodified lines
10231048
10241049 static av_cold void uninit(AVFilterContext *ctx)
10251050 {
1026− int i;
10271051 EBUR128Context *ebur128 = ctx->priv;
10281052
10291053 /* dual-mono correction */
@@ -1047,21 +1071,15 @@ static av_cold void uninit(AVFilterContext *ctx) · 17 unmodified lines
10471071 ebur128->loudness_range, ebur128->i3000.rel_threshold,
10481072 ebur128->lra_low, ebur128->lra_high);
10491073
1050−#define PRINT_PEAK_SUMMARY(str, sp, ptype) do { \
1051− int ch; \
1052− double maxpeak; \
1053− maxpeak = 0.0; \
1074+#define PRINT_PEAK_SUMMARY(str, value, ptype) do { \
10541075 if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
1055− for (ch = 0; ch < ebur128->nb_channels; ch++) \
1056− maxpeak = FFMAX(maxpeak, sp[ch]); \
10571076 av_log(ctx, AV_LOG_INFO, "\n\n " str " peak:\n" \
1058− " Peak: %5.1f dBFS", \
1059− DBFS(maxpeak)); \
1077+ " Peak: %5.1f dBFS", value); \
10601078 } \
10611079 } while (0)
10621080
1063− PRINT_PEAK_SUMMARY("Sample", ebur128->sample_peaks, SAMPLES);
1064− PRINT_PEAK_SUMMARY("True", ebur128->true_peaks, TRUE);
1081+ PRINT_PEAK_SUMMARY("Sample", ebur128->sample_peak, SAMPLES);
1082+ PRINT_PEAK_SUMMARY("True", ebur128->true_peak, TRUE);
10651083 av_log(ctx, AV_LOG_INFO, "\n");
10661084
10671085 av_freep(&ebur128->y_line_ref);
@@ -1076,7 +1094,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 8 unmodified lines
10761094 av_freep(&ebur128->i3000.sum);
10771095 av_freep(&ebur128->i400.histogram);
10781096 av_freep(&ebur128->i3000.histogram);
1079− for (i = 0; i < ebur128->nb_channels; i++) {
1097+ for (int i = 0; i < ebur128->nb_channels; i++) {
10801098 if (ebur128->i400.cache)
10811099 av_freep(&ebur128->i400.cache[i]);
10821100 if (ebur128->i3000.cache)
libavfilter/version.h+1−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 #include "version_major.h"
3333
3434 #define LIBAVFILTER_VERSION_MINOR 7
35−#define LIBAVFILTER_VERSION_MICRO 100
35+#define LIBAVFILTER_VERSION_MICRO 101
3636
3737
3838 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t