FFmpeg
f_ebur128.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Clément Bœsch
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * EBU R.128 implementation
24  * @see http://tech.ebu.ch/loudness
25  * @see https://www.youtube.com/watch?v=iuEtQqC-Sqo "EBU R128 Introduction - Florian Camerer"
26  * @todo implement start/stop/reset through filter command injection
27  */
28 
29 #include <float.h>
30 #include <math.h>
31 
32 #include "libavutil/avassert.h"
34 #include "libavutil/dict.h"
35 #include "libavutil/ffmath.h"
36 #include "libavutil/mem.h"
38 #include "libavutil/opt.h"
39 #include "libavutil/timestamp.h"
41 #include "avfilter.h"
42 #include "filters.h"
43 #include "formats.h"
44 #include "video.h"
45 
46 #include "f_ebur128.h"
47 
48 #define ABS_THRES -70 ///< silence gate: we discard anything below this absolute (LUFS) threshold
49 #define ABS_UP_THRES 10 ///< upper loud limit to consider (ABS_THRES being the minimum)
50 #define HIST_GRAIN 100 ///< defines histogram precision
51 #define HIST_SIZE ((ABS_UP_THRES - ABS_THRES) * HIST_GRAIN + 1)
52 
53 /**
54  * A histogram is an array of HIST_SIZE hist_entry storing all the energies
55  * recorded (with an accuracy of 1/HIST_GRAIN) of the loudnesses from ABS_THRES
56  * (at 0) to ABS_UP_THRES (at HIST_SIZE-1).
57  * This fixed-size system avoids the need of a list of energies growing
58  * infinitely over the time and is thus more scalable.
59  */
60 struct hist_entry {
61  unsigned count; ///< how many times the corresponding value occurred
62  double energy; ///< E = 10^((L + 0.691) / 10)
63  double loudness; ///< L = -0.691 + 10 * log10(E)
64 };
65 
66 struct integrator {
67  double *cache; ///< window of filtered samples (N ms)
68  int cache_pos; ///< focus on the last added bin in the cache array
70  double *sum; ///< sum of the last N ms filtered samples (cache content)
71  int filled; ///< 1 if the cache is completely filled, 0 otherwise
72  double rel_threshold; ///< relative threshold
73  double sum_kept_powers; ///< sum of the powers (weighted sums) above absolute threshold
74  int nb_kept_powers; ///< number of sum above absolute threshold
75  struct hist_entry *histogram; ///< histogram of the powers, used to compute LRA and I
76 };
77 
78 struct rect { int x, y, w, h; };
79 
80 typedef struct EBUR128Context {
81  const AVClass *class; ///< AVClass context for log and options purpose
83 
84  /* peak metering */
85  int peak_mode; ///< enabled peak modes
86  double true_peak; ///< global true peak
87  double *true_peaks; ///< true peaks per channel
88  double sample_peak; ///< global sample peak
89  double *sample_peaks; ///< sample peaks per channel
90  double *true_peaks_per_frame; ///< true peaks in a frame per channel
91 #if CONFIG_SWRESAMPLE
92  SwrContext *swr_ctx; ///< over-sampling context for true peak metering
93  double *swr_buf; ///< resampled audio data for true peak metering
94  int swr_linesize;
95 #endif
96 
97  /* video */
98  int do_video; ///< 1 if video output enabled, 0 otherwise
99  int w, h; ///< size of the video output
100  struct rect text; ///< rectangle for the LU legend on the left
101  struct rect graph; ///< rectangle for the main graph in the center
102  struct rect gauge; ///< rectangle for the gauge on the right
103  AVFrame *outpicref; ///< output picture reference, updated regularly
104  int meter; ///< select a EBU mode between +9 and +18
105  int scale_range; ///< the range of LU values according to the meter
106  int y_zero_lu; ///< the y value (pixel position) for 0 LU
107  int y_opt_max; ///< the y value (pixel position) for 1 LU
108  int y_opt_min; ///< the y value (pixel position) for -1 LU
109  int *y_line_ref; ///< y reference values for drawing the LU lines in the graph and the gauge
110 
111  /* audio */
112  int nb_channels; ///< number of channels in the input
113  double *ch_weighting; ///< channel weighting mapping
114  int sample_count; ///< sample count used for refresh frequency, reset at refresh
115  int nb_samples; ///< number of samples to consume per single input frame
116  int idx_insample; ///< current sample position of processed samples in single input frame
117  AVFrame *insamples; ///< input samples reference, updated regularly
118 
119  struct integrator i400; ///< 400ms integrator, used for Momentary loudness (M), and Integrated loudness (I)
120  struct integrator i3000; ///< 3s integrator, used for Short term loudness (S), and Loudness Range (LRA)
121 
122  /* I and LRA specific */
123  double integrated_loudness; ///< integrated loudness in LUFS (I)
124  double loudness_range; ///< loudness range in LU (LRA)
125  double lra_low, lra_high; ///< low and high LRA values
126 
127  /* misc */
128  int loglevel; ///< log level for frame logging
129  int metadata; ///< whether or not to inject loudness results in frames
130  int dual_mono; ///< whether or not to treat single channel input files as dual-mono
131  double pan_law; ///< pan law value used to calculate dual-mono measurements
132  int target; ///< target level in LUFS used to set relative zero LU in visualization
133  int gauge_type; ///< whether gauge shows momentary or short
134  int scale; ///< display scale type of statistics
136 
137 enum {
141 };
142 
143 enum {
146 };
147 
148 enum {
151 };
152 
153 #define OFFSET(x) offsetof(EBUR128Context, x)
154 #define A AV_OPT_FLAG_AUDIO_PARAM
155 #define V AV_OPT_FLAG_VIDEO_PARAM
156 #define F AV_OPT_FLAG_FILTERING_PARAM
157 #define X AV_OPT_FLAG_EXPORT
158 #define R AV_OPT_FLAG_READONLY
159 static const AVOption ebur128_options[] = {
160  { "video", "set video output", OFFSET(do_video), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, V|F },
161  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x480"}, 0, 0, V|F },
162  { "meter", "set scale meter (+9 to +18)", OFFSET(meter), AV_OPT_TYPE_INT, {.i64 = 9}, 9, 18, V|F },
163  { "framelog", "force frame logging level", OFFSET(loglevel), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, A|V|F, .unit = "level" },
164  { "quiet", "logging disabled", 0, AV_OPT_TYPE_CONST, {.i64 = AV_LOG_QUIET}, INT_MIN, INT_MAX, A|V|F, .unit = "level" },
165  { "info", "information logging level", 0, AV_OPT_TYPE_CONST, {.i64 = AV_LOG_INFO}, INT_MIN, INT_MAX, A|V|F, .unit = "level" },
166  { "verbose", "verbose logging level", 0, AV_OPT_TYPE_CONST, {.i64 = AV_LOG_VERBOSE}, INT_MIN, INT_MAX, A|V|F, .unit = "level" },
167  { "metadata", "inject metadata in the filtergraph", OFFSET(metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A|V|F },
168  { "peak", "set peak mode", OFFSET(peak_mode), AV_OPT_TYPE_FLAGS, {.i64 = PEAK_MODE_NONE}, 0, INT_MAX, A|F, .unit = "mode" },
169  { "none", "disable any peak mode", 0, AV_OPT_TYPE_CONST, {.i64 = PEAK_MODE_NONE}, INT_MIN, INT_MAX, A|F, .unit = "mode" },
170  { "sample", "enable peak-sample mode", 0, AV_OPT_TYPE_CONST, {.i64 = PEAK_MODE_SAMPLES_PEAKS}, INT_MIN, INT_MAX, A|F, .unit = "mode" },
171  { "true", "enable true-peak mode", 0, AV_OPT_TYPE_CONST, {.i64 = PEAK_MODE_TRUE_PEAKS}, INT_MIN, INT_MAX, A|F, .unit = "mode" },
172  { "dualmono", "treat mono input files as dual-mono", OFFSET(dual_mono), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A|F },
173  { "panlaw", "set a specific pan law for dual-mono files", OFFSET(pan_law), AV_OPT_TYPE_DOUBLE, {.dbl = -3.01029995663978}, -10.0, 0.0, A|F },
174  { "target", "set a specific target level in LUFS (-23 to 0)", OFFSET(target), AV_OPT_TYPE_INT, {.i64 = -23}, -23, 0, V|F },
175  { "gauge", "set gauge display type", OFFSET(gauge_type), AV_OPT_TYPE_INT, {.i64 = 0 }, GAUGE_TYPE_MOMENTARY, GAUGE_TYPE_SHORTTERM, V|F, .unit = "gaugetype" },
176  { "momentary", "display momentary value", 0, AV_OPT_TYPE_CONST, {.i64 = GAUGE_TYPE_MOMENTARY}, INT_MIN, INT_MAX, V|F, .unit = "gaugetype" },
177  { "m", "display momentary value", 0, AV_OPT_TYPE_CONST, {.i64 = GAUGE_TYPE_MOMENTARY}, INT_MIN, INT_MAX, V|F, .unit = "gaugetype" },
178  { "shortterm", "display short-term value", 0, AV_OPT_TYPE_CONST, {.i64 = GAUGE_TYPE_SHORTTERM}, INT_MIN, INT_MAX, V|F, .unit = "gaugetype" },
179  { "s", "display short-term value", 0, AV_OPT_TYPE_CONST, {.i64 = GAUGE_TYPE_SHORTTERM}, INT_MIN, INT_MAX, V|F, .unit = "gaugetype" },
180  { "scale", "sets display method for the stats", OFFSET(scale), AV_OPT_TYPE_INT, {.i64 = 0}, SCALE_TYPE_ABSOLUTE, SCALE_TYPE_RELATIVE, V|F, .unit = "scaletype" },
181  { "absolute", "display absolute values (LUFS)", 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_TYPE_ABSOLUTE}, INT_MIN, INT_MAX, V|F, .unit = "scaletype" },
182  { "LUFS", "display absolute values (LUFS)", 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_TYPE_ABSOLUTE}, INT_MIN, INT_MAX, V|F, .unit = "scaletype" },
183  { "relative", "display values relative to target (LU)", 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_TYPE_RELATIVE}, INT_MIN, INT_MAX, V|F, .unit = "scaletype" },
184  { "LU", "display values relative to target (LU)", 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_TYPE_RELATIVE}, INT_MIN, INT_MAX, V|F, .unit = "scaletype" },
185  { "integrated", "integrated loudness (LUFS)", OFFSET(integrated_loudness), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
186  { "range", "loudness range (LU)", OFFSET(loudness_range), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
187  { "lra_low", "LRA low (LUFS)", OFFSET(lra_low), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
188  { "lra_high", "LRA high (LUFS)", OFFSET(lra_high), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
189  { "sample_peak", "sample peak (dBFS)", OFFSET(sample_peak), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
190  { "true_peak", "true peak (dBFS)", OFFSET(true_peak), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -DBL_MAX, DBL_MAX, A|F|X|R },
191  { NULL },
192 };
193 
194 AVFILTER_DEFINE_CLASS(ebur128);
195 
196 static const uint8_t graph_colors[] = {
197  0xdd, 0x66, 0x66, // value above 1LU non reached below -1LU (impossible)
198  0x66, 0x66, 0xdd, // value below 1LU non reached below -1LU
199  0x96, 0x33, 0x33, // value above 1LU reached below -1LU (impossible)
200  0x33, 0x33, 0x96, // value below 1LU reached below -1LU
201  0xdd, 0x96, 0x96, // value above 1LU line non reached below -1LU (impossible)
202  0x96, 0x96, 0xdd, // value below 1LU line non reached below -1LU
203  0xdd, 0x33, 0x33, // value above 1LU line reached below -1LU (impossible)
204  0x33, 0x33, 0xdd, // value below 1LU line reached below -1LU
205  0xdd, 0x66, 0x66, // value above 1LU non reached above -1LU
206  0x66, 0xdd, 0x66, // value below 1LU non reached above -1LU
207  0x96, 0x33, 0x33, // value above 1LU reached above -1LU
208  0x33, 0x96, 0x33, // value below 1LU reached above -1LU
209  0xdd, 0x96, 0x96, // value above 1LU line non reached above -1LU
210  0x96, 0xdd, 0x96, // value below 1LU line non reached above -1LU
211  0xdd, 0x33, 0x33, // value above 1LU line reached above -1LU
212  0x33, 0xdd, 0x33, // value below 1LU line reached above -1LU
213 };
214 
215 static const uint8_t *get_graph_color(const EBUR128Context *ebur128, int v, int y)
216 {
217  const int above_opt_max = y > ebur128->y_opt_max;
218  const int below_opt_min = y < ebur128->y_opt_min;
219  const int reached = y >= v;
220  const int line = ebur128->y_line_ref[y] || y == ebur128->y_zero_lu;
221  const int colorid = 8*below_opt_min+ 4*line + 2*reached + above_opt_max;
222  return graph_colors + 3*colorid;
223 }
224 
225 static inline int lu_to_y(const EBUR128Context *ebur128, double v)
226 {
227  v += 2 * ebur128->meter; // make it in range [0;...]
228  v = av_clipf(v, 0, ebur128->scale_range); // make sure it's in the graph scale
229  v = ebur128->scale_range - v; // invert value (y=0 is on top)
230  return v * ebur128->graph.h / ebur128->scale_range; // rescale from scale range to px height
231 }
232 
233 #define FONT8 0
234 #define FONT16 1
235 
236 static const uint8_t font_colors[] = {
237  0xdd, 0xdd, 0x00,
238  0x00, 0x96, 0x96,
239 };
240 
241 static void drawtext(AVFrame *pic, int x, int y, int ftid, const uint8_t *color, const char *fmt, ...)
242 {
243  int i;
244  char buf[128] = {0};
245  const uint8_t *font;
246  int font_height;
247  va_list vl;
248 
249  if (ftid == FONT16) font = avpriv_vga16_font, font_height = 16;
250  else if (ftid == FONT8) font = avpriv_cga_font, font_height = 8;
251  else return;
252 
253  va_start(vl, fmt);
254  vsnprintf(buf, sizeof(buf), fmt, vl);
255  va_end(vl);
256 
257  for (i = 0; buf[i]; i++) {
258  int char_y, mask;
259  uint8_t *p = pic->data[0] + y*pic->linesize[0] + (x + i*8)*3;
260 
261  for (char_y = 0; char_y < font_height; char_y++) {
262  for (mask = 0x80; mask; mask >>= 1) {
263  if (font[buf[i] * font_height + char_y] & mask)
264  memcpy(p, color, 3);
265  else
266  memcpy(p, "\x00\x00\x00", 3);
267  p += 3;
268  }
269  p += pic->linesize[0] - 8*3;
270  }
271  }
272 }
273 
274 static void drawline(AVFrame *pic, int x, int y, int len, int step)
275 {
276  int i;
277  uint8_t *p = pic->data[0] + y*pic->linesize[0] + x*3;
278 
279  for (i = 0; i < len; i++) {
280  memcpy(p, "\x00\xff\x00", 3);
281  p += step;
282  }
283 }
284 
285 static int config_video_output(AVFilterLink *outlink)
286 {
287  int i, x, y;
288  uint8_t *p;
289  FilterLink *l = ff_filter_link(outlink);
290  AVFilterContext *ctx = outlink->src;
291  EBUR128Context *ebur128 = ctx->priv;
292  AVFrame *outpicref;
293 
294  /* check if there is enough space to represent everything decently */
295  if (ebur128->w < 640 || ebur128->h < 480) {
296  av_log(ctx, AV_LOG_ERROR, "Video size %dx%d is too small, "
297  "minimum size is 640x480\n", ebur128->w, ebur128->h);
298  return AVERROR(EINVAL);
299  }
300  outlink->w = ebur128->w;
301  outlink->h = ebur128->h;
302  outlink->sample_aspect_ratio = (AVRational){1,1};
303  l->frame_rate = av_make_q(10, 1);
304  outlink->time_base = av_inv_q(l->frame_rate);
305 
306 #define PAD 8
307 
308  /* configure text area position and size */
309  ebur128->text.x = PAD;
310  ebur128->text.y = 40;
311  ebur128->text.w = 3 * 8; // 3 characters
312  ebur128->text.h = ebur128->h - PAD - ebur128->text.y;
313 
314  /* configure gauge position and size */
315  ebur128->gauge.w = 20;
316  ebur128->gauge.h = ebur128->text.h;
317  ebur128->gauge.x = ebur128->w - PAD - ebur128->gauge.w;
318  ebur128->gauge.y = ebur128->text.y;
319 
320  /* configure graph position and size */
321  ebur128->graph.x = ebur128->text.x + ebur128->text.w + PAD;
322  ebur128->graph.y = ebur128->gauge.y;
323  ebur128->graph.w = ebur128->gauge.x - ebur128->graph.x - PAD;
324  ebur128->graph.h = ebur128->gauge.h;
325 
326  /* graph and gauge share the LU-to-pixel code */
327  av_assert0(ebur128->graph.h == ebur128->gauge.h);
328 
329  /* prepare the initial picref buffer */
330  av_frame_free(&ebur128->outpicref);
331  ebur128->outpicref = outpicref =
332  ff_get_video_buffer(outlink, outlink->w, outlink->h);
333  if (!outpicref)
334  return AVERROR(ENOMEM);
335  outpicref->sample_aspect_ratio = (AVRational){1,1};
336 
337  /* init y references values (to draw LU lines) */
338  ebur128->y_line_ref = av_calloc(ebur128->graph.h + 1, sizeof(*ebur128->y_line_ref));
339  if (!ebur128->y_line_ref)
340  return AVERROR(ENOMEM);
341 
342  /* black background */
343  for (int y = 0; y < ebur128->h; y++)
344  memset(outpicref->data[0] + y * outpicref->linesize[0], 0, ebur128->w * 3);
345 
346  /* draw LU legends */
347  drawtext(outpicref, PAD, PAD+16, FONT8, font_colors+3, " LU");
348  for (i = ebur128->meter; i >= -ebur128->meter * 2; i--) {
349  y = lu_to_y(ebur128, i);
350  x = PAD + (i < 10 && i > -10) * 8;
351  ebur128->y_line_ref[y] = i;
352  y -= 4; // -4 to center vertically
353  drawtext(outpicref, x, y + ebur128->graph.y, FONT8, font_colors+3,
354  "%c%d", i < 0 ? '-' : i > 0 ? '+' : ' ', FFABS(i));
355  }
356 
357  /* draw graph */
358  ebur128->y_zero_lu = lu_to_y(ebur128, 0);
359  ebur128->y_opt_max = lu_to_y(ebur128, 1);
360  ebur128->y_opt_min = lu_to_y(ebur128, -1);
361  p = outpicref->data[0] + ebur128->graph.y * outpicref->linesize[0]
362  + ebur128->graph.x * 3;
363  for (y = 0; y < ebur128->graph.h; y++) {
364  const uint8_t *c = get_graph_color(ebur128, INT_MAX, y);
365 
366  for (x = 0; x < ebur128->graph.w; x++)
367  memcpy(p + x*3, c, 3);
368  p += outpicref->linesize[0];
369  }
370 
371  /* draw fancy rectangles around the graph and the gauge */
372 #define DRAW_RECT(r) do { \
373  drawline(outpicref, r.x, r.y - 1, r.w, 3); \
374  drawline(outpicref, r.x, r.y + r.h, r.w, 3); \
375  drawline(outpicref, r.x - 1, r.y, r.h, outpicref->linesize[0]); \
376  drawline(outpicref, r.x + r.w, r.y, r.h, outpicref->linesize[0]); \
377 } while (0)
378  DRAW_RECT(ebur128->graph);
379  DRAW_RECT(ebur128->gauge);
380 
381  return 0;
382 }
383 
385 {
386  AVFilterContext *ctx = inlink->dst;
387  EBUR128Context *ebur128 = ctx->priv;
388 
389  /* Unofficial reversed parametrization of PRE
390  * and RLB from 48kHz */
391 
392  double f0 = 1681.974450955533;
393  double G = 3.999843853973347;
394  double Q = 0.7071752369554196;
395 
396  double K = tan(M_PI * f0 / (double)inlink->sample_rate);
397  double Vh = pow(10.0, G / 20.0);
398  double Vb = pow(Vh, 0.4996667741545416);
399 
400  double a0 = 1.0 + K / Q + K * K;
401 
402  ebur128->dsp.pre.b0 = (Vh + Vb * K / Q + K * K) / a0;
403  ebur128->dsp.pre.b1 = 2.0 * (K * K - Vh) / a0;
404  ebur128->dsp.pre.b2 = (Vh - Vb * K / Q + K * K) / a0;
405  ebur128->dsp.pre.a1 = 2.0 * (K * K - 1.0) / a0;
406  ebur128->dsp.pre.a2 = (1.0 - K / Q + K * K) / a0;
407 
408  f0 = 38.13547087602444;
409  Q = 0.5003270373238773;
410  K = tan(M_PI * f0 / (double)inlink->sample_rate);
411 
412  ebur128->dsp.rlb.b0 = 1.0;
413  ebur128->dsp.rlb.b1 = -2.0;
414  ebur128->dsp.rlb.b2 = 1.0;
415  ebur128->dsp.rlb.a1 = 2.0 * (K * K - 1.0) / (1.0 + K / Q + K * K);
416  ebur128->dsp.rlb.a2 = (1.0 - K / Q + K * K) / (1.0 + K / Q + K * K);
417 
418  /* Force 100ms framing in case of metadata injection: the frames must have
419  * a granularity of the window overlap to be accurately exploited.
420  * As for the true peaks mode, it just simplifies the resampling buffer
421  * allocation and the lookup in it (since sample buffers differ in size, it
422  * can be more complex to integrate in the one-sample loop of
423  * filter_frame()). */
424  if (ebur128->metadata || (ebur128->peak_mode & PEAK_MODE_TRUE_PEAKS))
425  ebur128->nb_samples = FFMAX(inlink->sample_rate / 10, 1);
426  return 0;
427 }
428 
429 static int config_audio_output(AVFilterLink *outlink)
430 {
431  int i;
432  AVFilterContext *ctx = outlink->src;
433  EBUR128Context *ebur128 = ctx->priv;
434  const int nb_channels = outlink->ch_layout.nb_channels;
435 
436 #define BACK_MASK (AV_CH_BACK_LEFT |AV_CH_BACK_CENTER |AV_CH_BACK_RIGHT| \
437  AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT| \
438  AV_CH_SIDE_LEFT |AV_CH_SIDE_RIGHT| \
439  AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT)
440 
441  ebur128->nb_channels = nb_channels;
442  ebur128->dsp.y = av_calloc(nb_channels, 3 * sizeof(*ebur128->dsp.y));
443  ebur128->dsp.z = av_calloc(nb_channels, 3 * sizeof(*ebur128->dsp.z));
444  ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting));
445  if (!ebur128->ch_weighting || !ebur128->dsp.y || !ebur128->dsp.z)
446  return AVERROR(ENOMEM);
447 
448 #define I400_BINS(x) ((x) * 4 / 10)
449 #define I3000_BINS(x) ((x) * 3)
450 
451  ebur128->i400.cache_size = I400_BINS(outlink->sample_rate);
452  ebur128->i3000.cache_size = I3000_BINS(outlink->sample_rate);
453  ebur128->i400.sum = av_calloc(nb_channels, sizeof(*ebur128->i400.sum));
454  ebur128->i3000.sum = av_calloc(nb_channels, sizeof(*ebur128->i3000.sum));
455  ebur128->i400.cache = av_calloc(nb_channels * ebur128->i400.cache_size, sizeof(*ebur128->i400.cache));
456  ebur128->i3000.cache = av_calloc(nb_channels * ebur128->i3000.cache_size, sizeof(*ebur128->i3000.cache));
457  if (!ebur128->i400.sum || !ebur128->i3000.sum ||
458  !ebur128->i400.cache || !ebur128->i3000.cache)
459  return AVERROR(ENOMEM);
460 
461  for (i = 0; i < nb_channels; i++) {
462  /* channel weighting */
463  const enum AVChannel chl = av_channel_layout_channel_from_index(&outlink->ch_layout, i);
464  if (chl == AV_CHAN_LOW_FREQUENCY || chl == AV_CHAN_LOW_FREQUENCY_2) {
465  ebur128->ch_weighting[i] = 0;
466  } else if (chl < 64 && (1ULL << chl) & BACK_MASK) {
467  ebur128->ch_weighting[i] = 1.41;
468  } else {
469  ebur128->ch_weighting[i] = 1.0;
470  }
471  }
472 
473 #if CONFIG_SWRESAMPLE
474  if (ebur128->peak_mode & PEAK_MODE_TRUE_PEAKS) {
475  int ret;
476 
477  ebur128->swr_buf = av_malloc_array(nb_channels, 19200 * sizeof(double));
478  ebur128->true_peaks = av_calloc(nb_channels, sizeof(*ebur128->true_peaks));
479  ebur128->true_peaks_per_frame = av_calloc(nb_channels, sizeof(*ebur128->true_peaks_per_frame));
480  ebur128->swr_ctx = swr_alloc();
481  if (!ebur128->swr_buf || !ebur128->true_peaks ||
482  !ebur128->true_peaks_per_frame || !ebur128->swr_ctx)
483  return AVERROR(ENOMEM);
484 
485  av_opt_set_chlayout(ebur128->swr_ctx, "in_chlayout", &outlink->ch_layout, 0);
486  av_opt_set_int(ebur128->swr_ctx, "in_sample_rate", outlink->sample_rate, 0);
487  av_opt_set_sample_fmt(ebur128->swr_ctx, "in_sample_fmt", outlink->format, 0);
488 
489  av_opt_set_chlayout(ebur128->swr_ctx, "out_chlayout", &outlink->ch_layout, 0);
490  av_opt_set_int(ebur128->swr_ctx, "out_sample_rate", 192000, 0);
491  av_opt_set_sample_fmt(ebur128->swr_ctx, "out_sample_fmt", outlink->format, 0);
492 
493  ret = swr_init(ebur128->swr_ctx);
494  if (ret < 0)
495  return ret;
496  }
497 #endif
498 
499  if (ebur128->peak_mode & PEAK_MODE_SAMPLES_PEAKS) {
500  ebur128->sample_peaks = av_calloc(nb_channels, sizeof(*ebur128->sample_peaks));
501  if (!ebur128->sample_peaks)
502  return AVERROR(ENOMEM);
503  }
504 
505 #if ARCH_X86
506  ff_ebur128_init_x86(&ebur128->dsp, nb_channels);
507 #endif
508  return 0;
509 }
510 
511 #define ENERGY(loudness) (ff_exp10(((loudness) + 0.691) / 10.))
512 #define LOUDNESS(energy) (-0.691 + 10 * log10(energy))
513 #define DBFS(energy) (20 * log10(energy))
514 
515 static struct hist_entry *get_histogram(void)
516 {
517  int i;
518  struct hist_entry *h = av_calloc(HIST_SIZE, sizeof(*h));
519 
520  if (!h)
521  return NULL;
522  for (i = 0; i < HIST_SIZE; i++) {
523  h[i].loudness = i / (double)HIST_GRAIN + ABS_THRES;
524  h[i].energy = ENERGY(h[i].loudness);
525  }
526  return h;
527 }
528 
530 {
531  EBUR128Context *ebur128 = ctx->priv;
532  AVFilterPad pad;
533  int ret;
534 
535  if (ebur128->loglevel != AV_LOG_INFO &&
536  ebur128->loglevel != AV_LOG_QUIET &&
537  ebur128->loglevel != AV_LOG_VERBOSE) {
538  if (ebur128->do_video || ebur128->metadata)
539  ebur128->loglevel = AV_LOG_VERBOSE;
540  else
541  ebur128->loglevel = AV_LOG_INFO;
542  }
543 
544  if (!CONFIG_SWRESAMPLE && (ebur128->peak_mode & PEAK_MODE_TRUE_PEAKS)) {
546  "True-peak mode requires libswresample to be performed\n");
547  return AVERROR(EINVAL);
548  }
549 
550  // if meter is +9 scale, scale range is from -18 LU to +9 LU (or 3*9)
551  // if meter is +18 scale, scale range is from -36 LU to +18 LU (or 3*18)
552  ebur128->scale_range = 3 * ebur128->meter;
553 
554  ebur128->i400.histogram = get_histogram();
555  ebur128->i3000.histogram = get_histogram();
556  if (!ebur128->i400.histogram || !ebur128->i3000.histogram)
557  return AVERROR(ENOMEM);
558 
559  ebur128->integrated_loudness = ABS_THRES;
560  ebur128->loudness_range = 0;
561 
562  /* insert output pads */
563  if (ebur128->do_video) {
564  pad = (AVFilterPad){
565  .name = "out0",
566  .type = AVMEDIA_TYPE_VIDEO,
567  .config_props = config_video_output,
568  };
569  ret = ff_append_outpad(ctx, &pad);
570  if (ret < 0)
571  return ret;
572  }
573  pad = (AVFilterPad){
574  .name = ebur128->do_video ? "out1" : "out0",
575  .type = AVMEDIA_TYPE_AUDIO,
576  .config_props = config_audio_output,
577  };
578  ret = ff_append_outpad(ctx, &pad);
579  if (ret < 0)
580  return ret;
581 
582  /* summary */
583  av_log(ctx, AV_LOG_VERBOSE, "EBU +%d scale\n", ebur128->meter);
584 
587  return 0;
588 }
589 
590 #define HIST_POS(power) (int)(((power) - ABS_THRES) * HIST_GRAIN)
591 
592 /* loudness and power should be set such as loudness = -0.691 +
593  * 10*log10(power), we just avoid doing that calculus two times */
594 static int gate_update(struct integrator *integ, double power,
595  double loudness, int gate_thres)
596 {
597  int ipower;
598  double relative_threshold;
599  int gate_hist_pos;
600 
601  /* update powers histograms by incrementing current power count */
602  ipower = av_clip(HIST_POS(loudness), 0, HIST_SIZE - 1);
603  integ->histogram[ipower].count++;
604 
605  /* compute relative threshold and get its position in the histogram */
606  integ->sum_kept_powers += power;
607  integ->nb_kept_powers++;
608  relative_threshold = integ->sum_kept_powers / integ->nb_kept_powers;
609  if (!relative_threshold)
610  relative_threshold = 1e-12;
611  integ->rel_threshold = LOUDNESS(relative_threshold) + gate_thres;
612  gate_hist_pos = av_clip(HIST_POS(integ->rel_threshold), 0, HIST_SIZE - 1);
613 
614  return gate_hist_pos;
615 }
616 
618  const double *restrict samples,
619  double *restrict cache_400,
620  double *restrict cache_3000,
621  double *restrict sum_400,
622  double *restrict sum_3000,
623  const int nb_channels)
624 {
625  const EBUR128Biquad pre = dsp->pre;
626  const EBUR128Biquad rlb = dsp->rlb;
627 
628  for (int ch = 0; ch < nb_channels; ch++) {
629  /* Y[i] = X[i]*b0 + X[i-1]*b1 + X[i-2]*b2 - Y[i-1]*a1 - Y[i-2]*a2 */
630 #define FILTER(DST, SRC, FILT) do { \
631  const double tmp = DST[0] = FILT.b0 * SRC + DST[1]; \
632  DST[1] = FILT.b1 * SRC + DST[2] - FILT.a1 * tmp; \
633  DST[2] = FILT.b2 * SRC - FILT.a2 * tmp; \
634 } while (0)
635 
636  const double x = samples[ch];
637  double *restrict y = &dsp->y[3 * ch];
638  double *restrict z = &dsp->z[3 * ch];
639 
640  // TODO: merge both filters in one?
641  FILTER(y, x, pre); // apply pre-filter
642  FILTER(z, *y, rlb); // apply RLB-filter
643 
644  /* add the new value, and limit the sum to the cache size (400ms or 3s)
645  * by removing the oldest one */
646  const double bin = *z * *z;
647  sum_400 [ch] += bin - cache_400[ch];
648  sum_3000[ch] += bin - cache_3000[ch];
649  cache_400[ch] = cache_3000[ch] = bin;
650  }
651 }
652 
653 double ff_ebur128_find_peak_c(double *restrict ch_peaks, const int nb_channels,
654  const double *samples, const int nb_samples)
655 {
656  double maxpeak = 0.0;
657  for (int ch = 0; ch < nb_channels; ch++) {
658  double ch_peak = ch_peaks[ch];
659  for (int i = 0; i < nb_samples; i++) {
660  const double sample = fabs(samples[i * nb_channels]);
661  ch_peak = FFMAX(ch_peak, sample);
662  }
663  maxpeak = FFMAX(maxpeak, ch_peak);
664  ch_peaks[ch] = ch_peak;
665  }
666 
667  return maxpeak;
668 }
669 
670 static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
671 {
672  int ret;
673  AVFilterContext *ctx = inlink->dst;
674  EBUR128Context *ebur128 = ctx->priv;
675  const EBUR128DSPContext *dsp = &ebur128->dsp;
676  const int nb_channels = ebur128->nb_channels;
677  const int nb_samples = insamples->nb_samples;
678  const double *samples = (double *)insamples->data[0];
679  AVFrame *pic;
680 
681 #if CONFIG_SWRESAMPLE
682  if (ebur128->peak_mode & PEAK_MODE_TRUE_PEAKS && ebur128->idx_insample == 0) {
683  const double *swr_samples = ebur128->swr_buf;
684  int ret = swr_convert(ebur128->swr_ctx, (uint8_t**)&ebur128->swr_buf, 19200,
685  (const uint8_t **)insamples->data, nb_samples);
686  if (ret < 0)
687  return ret;
688 
689  memset(ebur128->true_peaks_per_frame, 0,
690  nb_channels * sizeof(*ebur128->true_peaks_per_frame));
691 
692  double peak = dsp->find_peak(ebur128->true_peaks_per_frame, nb_channels,
693  swr_samples, ret);
694 
695  for (int ch = 0; ch < nb_channels; ch++) {
696  peak = FFMAX(peak, ebur128->true_peaks[ch]);
697  ebur128->true_peaks[ch] = FFMAX(ebur128->true_peaks[ch],
698  ebur128->true_peaks_per_frame[ch]);
699  }
700 
701  ebur128->true_peak = DBFS(peak);
702  }
703 #endif
704 
705  if (ebur128->peak_mode & PEAK_MODE_SAMPLES_PEAKS) {
706  double peak = dsp->find_peak(ebur128->sample_peaks, nb_channels,
707  samples, nb_samples);
708  ebur128->sample_peak = DBFS(peak);
709  }
710 
711  for (int idx_insample = ebur128->idx_insample; idx_insample < nb_samples; idx_insample++) {
712  const int bin_id_400 = ebur128->i400.cache_pos++;
713  const int bin_id_3000 = ebur128->i3000.cache_pos++;
714 
715  if (ebur128->i400.cache_pos == ebur128->i400.cache_size) {
716  ebur128->i400.filled = 1;
717  ebur128->i400.cache_pos = 0;
718  }
719 
720  if (ebur128->i3000.cache_pos == ebur128->i3000.cache_size) {
721  ebur128->i3000.filled = 1;
722  ebur128->i3000.cache_pos = 0;
723  }
724 
725  dsp->filter_channels(dsp, &samples[idx_insample * nb_channels],
726  &ebur128->i400.cache[bin_id_400 * nb_channels],
727  &ebur128->i3000.cache[bin_id_3000 * nb_channels],
728  ebur128->i400.sum, ebur128->i3000.sum,
729  nb_channels);
730 
731  /* For integrated loudness, gating blocks are 400ms long with 75%
732  * overlap (see BS.1770-2 p5), so a re-computation is needed each 100ms
733  * (4800 samples at 48kHz). */
734  if (++ebur128->sample_count == inlink->sample_rate / 10) {
735  double loudness_400, loudness_3000;
736  double power_400 = 1e-12, power_3000 = 1e-12;
737  AVFilterLink *outlink = ctx->outputs[0];
738  const int64_t pts = insamples->pts +
739  av_rescale_q(idx_insample, (AVRational){ 1, inlink->sample_rate },
740  ctx->outputs[ebur128->do_video]->time_base);
741 
742  ebur128->sample_count = 0;
743 
744 #define COMPUTE_LOUDNESS(m, time) do { \
745  if (ebur128->i##time.filled) { \
746  /* weighting sum of the last <time> ms */ \
747  for (int ch = 0; ch < nb_channels; ch++) \
748  power_##time += ebur128->ch_weighting[ch] * ebur128->i##time.sum[ch]; \
749  power_##time /= I##time##_BINS(inlink->sample_rate); \
750  } \
751  loudness_##time = LOUDNESS(power_##time); \
752 } while (0)
753 
754  COMPUTE_LOUDNESS(M, 400);
755  COMPUTE_LOUDNESS(S, 3000);
756 
757  /* Integrated loudness */
758 #define I_GATE_THRES -10 // initially defined to -8 LU in the first EBU standard
759 
760  if (loudness_400 >= ABS_THRES) {
761  double integrated_sum = 0.0;
762  uint64_t nb_integrated = 0;
763  int gate_hist_pos = gate_update(&ebur128->i400, power_400,
764  loudness_400, I_GATE_THRES);
765 
766  /* compute integrated loudness by summing the histogram values
767  * above the relative threshold */
768  for (int i = gate_hist_pos; i < HIST_SIZE; i++) {
769  const unsigned nb_v = ebur128->i400.histogram[i].count;
770  nb_integrated += nb_v;
771  integrated_sum += nb_v * ebur128->i400.histogram[i].energy;
772  }
773  if (nb_integrated) {
774  ebur128->integrated_loudness = LOUDNESS(integrated_sum / nb_integrated);
775  /* dual-mono correction */
776  if (nb_channels == 1 && ebur128->dual_mono) {
777  ebur128->integrated_loudness -= ebur128->pan_law;
778  }
779  }
780  }
781 
782  /* LRA */
783 #define LRA_GATE_THRES -20
784 #define LRA_LOWER_PRC 10
785 #define LRA_HIGHER_PRC 95
786 
787  /* XXX: example code in EBU 3342 is ">=" but formula in BS.1770
788  * specs is ">" */
789  if (loudness_3000 >= ABS_THRES) {
790  uint64_t nb_powers = 0;
791  int gate_hist_pos = gate_update(&ebur128->i3000, power_3000,
792  loudness_3000, LRA_GATE_THRES);
793 
794  for (int i = gate_hist_pos; i < HIST_SIZE; i++)
795  nb_powers += ebur128->i3000.histogram[i].count;
796  if (nb_powers) {
797  uint64_t n, nb_pow;
798 
799  /* get lower loudness to consider */
800  n = 0;
801  nb_pow = LRA_LOWER_PRC * nb_powers * 0.01 + 0.5;
802  for (int i = gate_hist_pos; i < HIST_SIZE; i++) {
803  n += ebur128->i3000.histogram[i].count;
804  if (n >= nb_pow) {
805  ebur128->lra_low = ebur128->i3000.histogram[i].loudness;
806  break;
807  }
808  }
809 
810  /* get higher loudness to consider */
811  n = nb_powers;
812  nb_pow = LRA_HIGHER_PRC * nb_powers * 0.01 + 0.5;
813  for (int i = HIST_SIZE - 1; i >= 0; i--) {
814  n -= FFMIN(n, ebur128->i3000.histogram[i].count);
815  if (n < nb_pow) {
816  ebur128->lra_high = ebur128->i3000.histogram[i].loudness;
817  break;
818  }
819  }
820 
821  // XXX: show low & high on the graph?
822  ebur128->loudness_range = ebur128->lra_high - ebur128->lra_low;
823  }
824  }
825 
826  /* dual-mono correction */
827  if (nb_channels == 1 && ebur128->dual_mono) {
828  loudness_400 -= ebur128->pan_law;
829  loudness_3000 -= ebur128->pan_law;
830  }
831 
832 #define LOG_FMT "TARGET:%d LUFS M:%6.1f S:%6.1f I:%6.1f %s LRA:%6.1f LU"
833 
834  /* push one video frame */
835  if (ebur128->do_video) {
836  AVFrame *clone;
837  int x, y;
838  uint8_t *p;
839  double gauge_value;
840  int y_loudness_lu_graph, y_loudness_lu_gauge;
841 
842  if (ebur128->gauge_type == GAUGE_TYPE_MOMENTARY) {
843  gauge_value = loudness_400 - ebur128->target;
844  } else {
845  gauge_value = loudness_3000 - ebur128->target;
846  }
847 
848  y_loudness_lu_graph = lu_to_y(ebur128, loudness_3000 - ebur128->target);
849  y_loudness_lu_gauge = lu_to_y(ebur128, gauge_value);
850 
851  ret = ff_inlink_make_frame_writable(outlink, &ebur128->outpicref);
852  if (ret < 0) {
853  av_frame_free(&insamples);
854  ebur128->insamples = NULL;
855  return ret;
856  }
857  pic = ebur128->outpicref;
858  /* draw the graph using the short-term loudness */
859  p = pic->data[0] + ebur128->graph.y*pic->linesize[0] + ebur128->graph.x*3;
860  for (y = 0; y < ebur128->graph.h; y++) {
861  const uint8_t *c = get_graph_color(ebur128, y_loudness_lu_graph, y);
862 
863  memmove(p, p + 3, (ebur128->graph.w - 1) * 3);
864  memcpy(p + (ebur128->graph.w - 1) * 3, c, 3);
865  p += pic->linesize[0];
866  }
867 
868  /* draw the gauge using either momentary or short-term loudness */
869  p = pic->data[0] + ebur128->gauge.y*pic->linesize[0] + ebur128->gauge.x*3;
870  for (y = 0; y < ebur128->gauge.h; y++) {
871  const uint8_t *c = get_graph_color(ebur128, y_loudness_lu_gauge, y);
872 
873  for (x = 0; x < ebur128->gauge.w; x++)
874  memcpy(p + x*3, c, 3);
875  p += pic->linesize[0];
876  }
877 
878  /* draw textual info */
879  if (ebur128->scale == SCALE_TYPE_ABSOLUTE) {
880  drawtext(pic, PAD, PAD - PAD/2, FONT16, font_colors,
881  LOG_FMT " ", // padding to erase trailing characters
882  ebur128->target, loudness_400, loudness_3000,
883  ebur128->integrated_loudness, "LUFS", ebur128->loudness_range);
884  } else {
885  drawtext(pic, PAD, PAD - PAD/2, FONT16, font_colors,
886  LOG_FMT " ", // padding to erase trailing characters
887  ebur128->target, loudness_400-ebur128->target, loudness_3000-ebur128->target,
888  ebur128->integrated_loudness-ebur128->target, "LU", ebur128->loudness_range);
889  }
890 
891  /* set pts and push frame */
892  pic->pts = av_rescale_q(pts, inlink->time_base, outlink->time_base);
893  pic->duration = 1;
894  clone = av_frame_clone(pic);
895  if (!clone)
896  return AVERROR(ENOMEM);
897  ebur128->idx_insample = idx_insample + 1;
898  ff_filter_set_ready(ctx, 100);
899  return ff_filter_frame(outlink, clone);
900  }
901 
902  if (ebur128->metadata) { /* happens only once per filter_frame call */
903  char metabuf[128];
904 #define META_PREFIX "lavfi.r128."
905 
906 #define SET_META(name, var) do { \
907  snprintf(metabuf, sizeof(metabuf), "%.3f", var); \
908  av_dict_set(&insamples->metadata, name, metabuf, 0); \
909 } while (0)
910 
911 #define SET_META_PEAK(name, ptype) do { \
912  if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
913  double max_peak = 0.0; \
914  char key[64]; \
915  for (int ch = 0; ch < nb_channels; ch++) { \
916  snprintf(key, sizeof(key), \
917  META_PREFIX AV_STRINGIFY(name) "_peaks_ch%d", ch); \
918  max_peak = fmax(max_peak, ebur128->name##_peaks[ch]); \
919  SET_META(key, ebur128->name##_peaks[ch]); \
920  } \
921  snprintf(key, sizeof(key), \
922  META_PREFIX AV_STRINGIFY(name) "_peak"); \
923  SET_META(key, max_peak); \
924  } \
925 } while (0)
926 
927  SET_META(META_PREFIX "M", loudness_400);
928  SET_META(META_PREFIX "S", loudness_3000);
930  SET_META(META_PREFIX "LRA", ebur128->loudness_range);
931  SET_META(META_PREFIX "LRA.low", ebur128->lra_low);
932  SET_META(META_PREFIX "LRA.high", ebur128->lra_high);
933 
935  SET_META_PEAK(true, TRUE);
936  }
937 
938  if (ebur128->loglevel != AV_LOG_QUIET) {
939  if (ebur128->scale == SCALE_TYPE_ABSOLUTE) {
940  av_log(ctx, ebur128->loglevel, "t: %-10s " LOG_FMT,
941  av_ts2timestr(pts, &outlink->time_base),
942  ebur128->target, loudness_400, loudness_3000,
943  ebur128->integrated_loudness, "LUFS", ebur128->loudness_range);
944  } else {
945  av_log(ctx, ebur128->loglevel, "t: %-10s " LOG_FMT,
946  av_ts2timestr(pts, &outlink->time_base),
947  ebur128->target, loudness_400-ebur128->target, loudness_3000-ebur128->target,
948  ebur128->integrated_loudness-ebur128->target, "LU", ebur128->loudness_range);
949  }
950 
951 #define PRINT_PEAKS(str, sp, ptype) do { \
952  if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
953  av_log(ctx, ebur128->loglevel, " " str ":"); \
954  for (int ch = 0; ch < nb_channels; ch++) \
955  av_log(ctx, ebur128->loglevel, " %5.1f", DBFS(sp[ch])); \
956  av_log(ctx, ebur128->loglevel, " dBFS"); \
957  } \
958 } while (0)
959 
960  PRINT_PEAKS("SPK", ebur128->sample_peaks, SAMPLES);
961  PRINT_PEAKS("FTPK", ebur128->true_peaks_per_frame, TRUE);
962  PRINT_PEAKS("TPK", ebur128->true_peaks, TRUE);
963  av_log(ctx, ebur128->loglevel, "\n");
964  }
965  }
966  }
967 
968  ebur128->idx_insample = 0;
969  ebur128->insamples = NULL;
970 
971  return ff_filter_frame(ctx->outputs[ebur128->do_video], insamples);
972 }
973 
975 {
976  AVFilterLink *inlink = ctx->inputs[0];
977  EBUR128Context *ebur128 = ctx->priv;
978  AVFilterLink *voutlink = ctx->outputs[0];
979  AVFilterLink *outlink = ctx->outputs[ebur128->do_video];
980  int ret;
981 
983  if (ebur128->do_video)
985 
986  if (!ebur128->insamples) {
987  AVFrame *in;
988 
989  if (ebur128->nb_samples > 0) {
990  ret = ff_inlink_consume_samples(inlink, ebur128->nb_samples, ebur128->nb_samples, &in);
991  } else {
993  }
994  if (ret < 0)
995  return ret;
996  if (ret > 0)
997  ebur128->insamples = in;
998  }
999 
1000  if (ebur128->insamples)
1001  ret = filter_frame(inlink, ebur128->insamples);
1002 
1004  FF_FILTER_FORWARD_WANTED(outlink, inlink);
1005  if (ebur128->do_video)
1006  FF_FILTER_FORWARD_WANTED(voutlink, inlink);
1007 
1008  return ret;
1009 }
1010 
1012  AVFilterFormatsConfig **cfg_in,
1013  AVFilterFormatsConfig **cfg_out)
1014 {
1015  const EBUR128Context *ebur128 = ctx->priv;
1017  int out_idx = 0;
1018  int ret;
1019 
1021  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE };
1022 
1023  /* set optional output video format */
1024  if (ebur128->do_video) {
1026  if ((ret = ff_formats_ref(formats, &cfg_out[0]->formats)) < 0)
1027  return ret;
1028  out_idx = 1;
1029  }
1030 
1031  /* set input and output audio formats
1032  * Note: ff_set_common_* functions are not used because they affect all the
1033  * links, and thus break the video format negotiation */
1035  if ((ret = ff_formats_ref(formats, &cfg_in[0]->formats)) < 0 ||
1036  (ret = ff_formats_ref(formats, &cfg_out[out_idx]->formats)) < 0)
1037  return ret;
1038 
1039  return 0;
1040 }
1041 
1043 {
1044  EBUR128Context *ebur128 = ctx->priv;
1045 
1046  /* dual-mono correction */
1047  if (ebur128->nb_channels == 1 && ebur128->dual_mono) {
1048  ebur128->i400.rel_threshold -= ebur128->pan_law;
1049  ebur128->i3000.rel_threshold -= ebur128->pan_law;
1050  ebur128->lra_low -= ebur128->pan_law;
1051  ebur128->lra_high -= ebur128->pan_law;
1052  }
1053 
1054  if (ebur128->nb_channels > 0) {
1055  av_log(ctx, AV_LOG_INFO, "Summary:\n\n"
1056  " Integrated loudness:\n"
1057  " I: %5.1f LUFS\n"
1058  " Threshold: %5.1f LUFS\n\n"
1059  " Loudness range:\n"
1060  " LRA: %5.1f LU\n"
1061  " Threshold: %5.1f LUFS\n"
1062  " LRA low: %5.1f LUFS\n"
1063  " LRA high: %5.1f LUFS",
1064  ebur128->integrated_loudness, ebur128->i400.rel_threshold,
1065  ebur128->loudness_range, ebur128->i3000.rel_threshold,
1066  ebur128->lra_low, ebur128->lra_high);
1067 
1068 #define PRINT_PEAK_SUMMARY(str, value, ptype) do { \
1069  if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
1070  av_log(ctx, AV_LOG_INFO, "\n\n " str " peak:\n" \
1071  " Peak: %5.1f dBFS", value); \
1072  } \
1073 } while (0)
1074 
1075  PRINT_PEAK_SUMMARY("Sample", ebur128->sample_peak, SAMPLES);
1076  PRINT_PEAK_SUMMARY("True", ebur128->true_peak, TRUE);
1077  av_log(ctx, AV_LOG_INFO, "\n");
1078  }
1079 
1080  av_freep(&ebur128->y_line_ref);
1081  av_freep(&ebur128->dsp.y);
1082  av_freep(&ebur128->dsp.z);
1083  av_freep(&ebur128->ch_weighting);
1084  av_freep(&ebur128->true_peaks);
1085  av_freep(&ebur128->sample_peaks);
1086  av_freep(&ebur128->true_peaks_per_frame);
1087  av_freep(&ebur128->i400.sum);
1088  av_freep(&ebur128->i3000.sum);
1089  av_freep(&ebur128->i400.histogram);
1090  av_freep(&ebur128->i3000.histogram);
1091  av_freep(&ebur128->i400.cache);
1092  av_freep(&ebur128->i3000.cache);
1093  av_frame_free(&ebur128->outpicref);
1094 #if CONFIG_SWRESAMPLE
1095  av_freep(&ebur128->swr_buf);
1096  swr_free(&ebur128->swr_ctx);
1097 #endif
1098 }
1099 
1100 static const AVFilterPad ebur128_inputs[] = {
1101  {
1102  .name = "default",
1103  .type = AVMEDIA_TYPE_AUDIO,
1104  .config_props = config_audio_input,
1105  },
1106 };
1107 
1109  .p.name = "ebur128",
1110  .p.description = NULL_IF_CONFIG_SMALL("EBU R128 scanner."),
1111  .p.outputs = NULL,
1112  .p.priv_class = &ebur128_class,
1113  .p.flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
1114  .priv_size = sizeof(EBUR128Context),
1115  .init = init,
1116  .uninit = uninit,
1117  .activate = activate,
1120 };
M
#define M(a, b)
Definition: vp3dsp.c:48
formats
formats
Definition: signature.h:47
rect::w
int w
Definition: f_ebur128.c:78
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:116
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
EBUR128Context::dual_mono
int dual_mono
whether or not to treat single channel input files as dual-mono
Definition: f_ebur128.c:130
av_clip
#define av_clip
Definition: common.h:100
V
#define V
Definition: f_ebur128.c:155
EBUR128Context::ch_weighting
double * ch_weighting
channel weighting mapping
Definition: f_ebur128.c:113
EBUR128Context::y_opt_min
int y_opt_min
the y value (pixel position) for -1 LU
Definition: f_ebur128.c:108
EBUR128DSPContext::z
double * z
Definition: f_ebur128.h:40
ff_af_ebur128
const FFFilter ff_af_ebur128
Definition: f_ebur128.c:1108
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
integrator::filled
int filled
1 if the cache is completely filled, 0 otherwise
Definition: f_ebur128.c:71
integrator
Definition: f_ebur128.c:66
EBUR128Context::gauge_type
int gauge_type
whether gauge shows momentary or short
Definition: f_ebur128.c:133
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:435
EBUR128Context::y_opt_max
int y_opt_max
the y value (pixel position) for 1 LU
Definition: f_ebur128.c:107
SET_META_PEAK
#define SET_META_PEAK(name, ptype)
integrator::cache
double * cache
window of filtered samples (N ms)
Definition: f_ebur128.c:67
PRINT_PEAKS
#define PRINT_PEAKS(str, sp, ptype)
get_graph_color
static const uint8_t * get_graph_color(const EBUR128Context *ebur128, int v, int y)
Definition: f_ebur128.c:215
A
#define A
Definition: f_ebur128.c:154
color
Definition: vf_paletteuse.c:513
AV_LOG_QUIET
#define AV_LOG_QUIET
Print no output.
Definition: log.h:192
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
SCALE_TYPE_ABSOLUTE
@ SCALE_TYPE_ABSOLUTE
Definition: f_ebur128.c:149
EBUR128Context::do_video
int do_video
1 if video output enabled, 0 otherwise
Definition: f_ebur128.c:98
rect
Definition: f_ebur128.c:78
HIST_SIZE
#define HIST_SIZE
Definition: f_ebur128.c:51
int64_t
long long int64_t
Definition: coverity.c:34
EBUR128Context::sample_count
int sample_count
sample count used for refresh frequency, reset at refresh
Definition: f_ebur128.c:114
metadata
Stream codec metadata
Definition: ogg-flac-chained-meta.txt:2
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
EBUR128Context::dsp
EBUR128DSPContext dsp
Definition: f_ebur128.c:82
rect::y
int y
Definition: f_ebur128.c:78
EBUR128Biquad::b2
double b2
Definition: f_ebur128.h:29
mask
int mask
Definition: mediacodecdec_common.c:154
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:63
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:421
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:523
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
w
uint8_t w
Definition: llviddspenc.c:38
av_channel_layout_channel_from_index
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
Definition: channel_layout.c:673
AVOption
AVOption.
Definition: opt.h:429
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(ebur128)
I_GATE_THRES
#define I_GATE_THRES
ebur128_options
static const AVOption ebur128_options[]
Definition: f_ebur128.c:159
F
#define F
Definition: f_ebur128.c:156
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
float.h
init
static av_cold int init(AVFilterContext *ctx)
Definition: f_ebur128.c:529
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:215
config_audio_output
static int config_audio_output(AVFilterLink *outlink)
Definition: f_ebur128.c:429
integrator::sum_kept_powers
double sum_kept_powers
sum of the powers (weighted sums) above absolute threshold
Definition: f_ebur128.c:73
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
video.h
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:637
LRA_HIGHER_PRC
#define LRA_HIGHER_PRC
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:442
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
S
#define S(s, c, i)
Definition: flacdsp_template.c:46
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: f_ebur128.c:1042
FONT8
#define FONT8
Definition: f_ebur128.c:233
EBUR128Context::pan_law
double pan_law
pan law value used to calculate dual-mono measurements
Definition: f_ebur128.c:131
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1492
drawline
static void drawline(AVFrame *pic, int x, int y, int len, int step)
Definition: f_ebur128.c:274
get_histogram
static struct hist_entry * get_histogram(void)
Definition: f_ebur128.c:515
R
#define R
Definition: f_ebur128.c:158
EBUR128Context::scale
int scale
display scale type of statistics
Definition: f_ebur128.c:134
LRA_GATE_THRES
#define LRA_GATE_THRES
pts
static int64_t pts
Definition: transcode_aac.c:644
integrator::cache_pos
int cache_pos
focus on the last added bin in the cache array
Definition: f_ebur128.c:68
EBUR128Context::nb_samples
int nb_samples
number of samples to consume per single input frame
Definition: f_ebur128.c:115
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
swr_convert
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *const *out_arg, int out_count, const uint8_t *const *in_arg, int in_count)
Convert audio.
Definition: swresample.c:719
font_colors
static const uint8_t font_colors[]
Definition: f_ebur128.c:236
Q
#define Q(q)
avassert.h
EBUR128Context::metadata
int metadata
whether or not to inject loudness results in frames
Definition: f_ebur128.c:129
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
av_cold
#define av_cold
Definition: attributes.h:90
EBUR128Context::graph
struct rect graph
rectangle for the main graph in the center
Definition: f_ebur128.c:101
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
Definition: f_ebur128.c:670
OFFSET
#define OFFSET(x)
Definition: f_ebur128.c:153
swr_init
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
Definition: swresample.c:140
FFFilter
Definition: filters.h:265
config_video_output
static int config_video_output(AVFilterLink *outlink)
Definition: f_ebur128.c:285
EBUR128Context::integrated_loudness
double integrated_loudness
integrated loudness in LUFS (I)
Definition: f_ebur128.c:123
EBUR128Context::w
int w
Definition: f_ebur128.c:99
FONT16
#define FONT16
Definition: f_ebur128.c:234
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:678
EBUR128Context::target
int target
target level in LUFS used to set relative zero LU in visualization
Definition: f_ebur128.c:132
swr_alloc
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
Definition: options.c:148
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:298
f_ebur128.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:481
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
drawtext
static void drawtext(AVFrame *pic, int x, int y, int ftid, const uint8_t *color, const char *fmt,...)
Definition: f_ebur128.c:241
X
#define X
Definition: f_ebur128.c:157
SwrContext
The libswresample context.
Definition: swresample_internal.h:95
hist_entry::loudness
double loudness
L = -0.691 + 10 * log10(E)
Definition: f_ebur128.c:63
ff_inlink_make_frame_writable
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Definition: avfilter.c:1539
EBUR128Context::true_peaks_per_frame
double * true_peaks_per_frame
true peaks in a frame per channel
Definition: f_ebur128.c:90
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
if
if(ret)
Definition: filter_design.txt:179
EBUR128Context::sample_peaks
double * sample_peaks
sample peaks per channel
Definition: f_ebur128.c:89
HIST_GRAIN
#define HIST_GRAIN
defines histogram precision
Definition: f_ebur128.c:50
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: f_ebur128.c:1011
I400_BINS
#define I400_BINS(x)
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
ff_inlink_consume_samples
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1512
NULL
#define NULL
Definition: coverity.c:32
EBUR128Context::peak_mode
int peak_mode
enabled peak modes
Definition: f_ebur128.c:85
HIST_POS
#define HIST_POS(power)
Definition: f_ebur128.c:590
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
EBUR128Biquad::a1
double a1
Definition: f_ebur128.h:30
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition: opt.h:303
LOG_FMT
#define LOG_FMT
GAUGE_TYPE_MOMENTARY
@ GAUGE_TYPE_MOMENTARY
Definition: f_ebur128.c:144
EBUR128Context::gauge
struct rect gauge
rectangle for the gauge on the right
Definition: f_ebur128.c:102
double
double
Definition: af_crystalizer.c:132
av_clipf
av_clipf
Definition: af_crystalizer.c:122
ff_ebur128_init_x86
void ff_ebur128_init_x86(EBUR128DSPContext *dsp, int nb_channels)
Definition: f_ebur128_init.c:31
swresample.h
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:121
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:880
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
ff_ebur128_filter_channels_c
void ff_ebur128_filter_channels_c(const EBUR128DSPContext *dsp, const double *restrict samples, double *restrict cache_400, double *restrict cache_3000, double *restrict sum_400, double *restrict sum_3000, const int nb_channels)
Definition: f_ebur128.c:617
EBUR128Context
Definition: f_ebur128.c:80
PEAK_MODE_TRUE_PEAKS
@ PEAK_MODE_TRUE_PEAKS
Definition: f_ebur128.c:140
AVFILTER_FLAG_DYNAMIC_OUTPUTS
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:157
hist_entry::count
unsigned count
how many times the corresponding value occurred
Definition: f_ebur128.c:61
EBUR128Context::y_zero_lu
int y_zero_lu
the y value (pixel position) for 0 LU
Definition: f_ebur128.c:106
EBUR128Context::i3000
struct integrator i3000
3s integrator, used for Short term loudness (S), and Loudness Range (LRA)
Definition: f_ebur128.c:120
ENERGY
#define ENERGY(loudness)
Definition: f_ebur128.c:511
activate
static int activate(AVFilterContext *ctx)
Definition: f_ebur128.c:974
EBUR128DSPContext
Definition: f_ebur128.h:33
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:83
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
EBUR128Biquad::b1
double b1
Definition: f_ebur128.h:29
av_opt_set_chlayout
int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *channel_layout, int search_flags)
Definition: opt.c:1000
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
sample
#define sample
Definition: flacdsp_template.c:44
AV_CHAN_LOW_FREQUENCY
@ AV_CHAN_LOW_FREQUENCY
Definition: channel_layout.h:53
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
rect::h
int h
Definition: f_ebur128.c:78
swr_free
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
Definition: swresample.c:121
EBUR128Context::true_peak
double true_peak
global true peak
Definition: f_ebur128.c:86
PEAK_MODE_NONE
@ PEAK_MODE_NONE
Definition: f_ebur128.c:138
a0
static double a0(void *priv, double x, double y)
Definition: vf_xfade.c:2028
EBUR128Context::sample_peak
double sample_peak
global sample peak
Definition: f_ebur128.c:88
EBUR128Context::outpicref
AVFrame * outpicref
output picture reference, updated regularly
Definition: f_ebur128.c:103
line
Definition: graph2dot.c:48
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
EBUR128DSPContext::rlb
EBUR128Biquad rlb
Definition: f_ebur128.h:36
xga_font_data.h
rect::x
int x
Definition: f_ebur128.c:78
EBUR128Context::h
int h
size of the video output
Definition: f_ebur128.c:99
M_PI
#define M_PI
Definition: mathematics.h:67
I3000_BINS
#define I3000_BINS(x)
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
AVChannel
AVChannel
Definition: channel_layout.h:47
EBUR128Biquad::a2
double a2
Definition: f_ebur128.h:30
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:501
SCALE_TYPE_RELATIVE
@ SCALE_TYPE_RELATIVE
Definition: f_ebur128.c:150
avpriv_vga16_font
const uint8_t avpriv_vga16_font[4096]
Definition: xga_font_data.c:160
PEAK_MODE_SAMPLES_PEAKS
@ PEAK_MODE_SAMPLES_PEAKS
Definition: f_ebur128.c:139
EBUR128Biquad::b0
double b0
Definition: f_ebur128.h:29
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
EBUR128Context::text
struct rect text
rectangle for the LU legend on the left
Definition: f_ebur128.c:100
EBUR128Context::y_line_ref
int * y_line_ref
y reference values for drawing the LU lines in the graph and the gauge
Definition: f_ebur128.c:109
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
vsnprintf
#define vsnprintf
Definition: snprintf.h:36
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FILTER
#define FILTER(DST, SRC, FILT)
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
integrator::rel_threshold
double rel_threshold
relative threshold
Definition: f_ebur128.c:72
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
ABS_THRES
#define ABS_THRES
silence gate: we discard anything below this absolute (LUFS) threshold
Definition: f_ebur128.c:48
len
int len
Definition: vorbis_enc_data.h:426
ff_ebur128_find_peak_c
double ff_ebur128_find_peak_c(double *restrict ch_peaks, const int nb_channels, const double *samples, const int nb_samples)
Definition: f_ebur128.c:653
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
integrator::nb_kept_powers
int nb_kept_powers
number of sum above absolute threshold
Definition: f_ebur128.c:74
EBUR128Context::true_peaks
double * true_peaks
true peaks per channel
Definition: f_ebur128.c:87
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
EBUR128Context::loudness_range
double loudness_range
loudness range in LU (LRA)
Definition: f_ebur128.c:124
hist_entry::energy
double energy
E = 10^((L + 0.691) / 10)
Definition: f_ebur128.c:62
graph_colors
static const uint8_t graph_colors[]
Definition: f_ebur128.c:196
ret
ret
Definition: filter_design.txt:187
EBUR128Context::lra_low
double lra_low
Definition: f_ebur128.c:125
LRA_LOWER_PRC
#define LRA_LOWER_PRC
dict.h
integrator::sum
double * sum
sum of the last N ms filtered samples (cache content)
Definition: f_ebur128.c:70
EBUR128Context::lra_high
double lra_high
low and high LRA values
Definition: f_ebur128.c:125
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:518
EBUR128Context::scale_range
int scale_range
the range of LU values according to the meter
Definition: f_ebur128.c:105
META_PREFIX
#define META_PREFIX
power
static float power(float r, float g, float b, float max)
Definition: preserve_color.h:45
SET_META
#define SET_META(name, var)
channel_layout.h
AV_CHAN_LOW_FREQUENCY_2
@ AV_CHAN_LOW_FREQUENCY_2
Definition: channel_layout.h:76
SAMPLES
#define SAMPLES
LOUDNESS
#define LOUDNESS(energy)
Definition: f_ebur128.c:512
EBUR128Context::meter
int meter
select a EBU mode between +9 and +18
Definition: f_ebur128.c:104
PAD
#define PAD
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
EBUR128DSPContext::filter_channels
void(* filter_channels)(const struct EBUR128DSPContext *dsp, const double *samples, double *cache_400, double *cache_3000, double *sum_400, double *sum_3000, int nb_channels)
Definition: f_ebur128.h:43
avfilter.h
EBUR128Context::insamples
AVFrame * insamples
input samples reference, updated regularly
Definition: f_ebur128.c:117
EBUR128Biquad
Definition: f_ebur128.h:28
GAUGE_TYPE_SHORTTERM
@ GAUGE_TYPE_SHORTTERM
Definition: f_ebur128.c:145
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
DBFS
#define DBFS(energy)
Definition: f_ebur128.c:513
ffmath.h
G
#define G
Definition: huffyuv.h:43
AVFilterContext
An instance of a filter.
Definition: avfilter.h:269
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:269
mem.h
ebur128_inputs
static const AVFilterPad ebur128_inputs[]
Definition: f_ebur128.c:1100
ff_append_outpad
int ff_append_outpad(AVFilterContext *f, AVFilterPad *p)
Definition: avfilter.c:138
avpriv_cga_font
const uint8_t avpriv_cga_font[2048]
Definition: xga_font_data.c:29
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:273
DRAW_RECT
#define DRAW_RECT(r)
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
EBUR128Context::nb_channels
int nb_channels
number of channels in the input
Definition: f_ebur128.c:112
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
EBUR128Context::idx_insample
int idx_insample
current sample position of processed samples in single input frame
Definition: f_ebur128.c:116
FF_FILTER_FORWARD_STATUS_ALL
#define FF_FILTER_FORWARD_STATUS_ALL(inlink, filter)
Acknowledge the status on an input link and forward it to an output link.
Definition: filters.h:677
EBUR128Context::i400
struct integrator i400
400ms integrator, used for Momentary loudness (M), and Integrated loudness (I)
Definition: f_ebur128.c:119
K
#define K
Definition: palette.c:25
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition: opt.h:255
timestamp.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:466
config_audio_input
static int config_audio_input(AVFilterLink *inlink)
Definition: f_ebur128.c:384
integrator::histogram
struct hist_entry * histogram
histogram of the powers, used to compute LRA and I
Definition: f_ebur128.c:75
integrator::cache_size
int cache_size
Definition: f_ebur128.c:69
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
PRINT_PEAK_SUMMARY
#define PRINT_PEAK_SUMMARY(str, value, ptype)
h
h
Definition: vp9dsp_template.c:2070
BACK_MASK
#define BACK_MASK
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:61
EBUR128DSPContext::pre
EBUR128Biquad pre
Definition: f_ebur128.h:35
lu_to_y
static int lu_to_y(const EBUR128Context *ebur128, double v)
Definition: f_ebur128.c:225
EBUR128DSPContext::y
double * y
Definition: f_ebur128.h:39
av_opt_set_sample_fmt
int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
Definition: opt.c:979
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
EBUR128Context::loglevel
int loglevel
log level for frame logging
Definition: f_ebur128.c:128
gate_update
static int gate_update(struct integrator *integ, double power, double loudness, int gate_thres)
Definition: f_ebur128.c:594
COMPUTE_LOUDNESS
#define COMPUTE_LOUDNESS(m, time)
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:229
EBUR128DSPContext::find_peak
double(* find_peak)(double *ch_peaks, int nb_channels, const double *samples, int nb_samples)
Definition: f_ebur128.h:50
hist_entry
A histogram is an array of HIST_SIZE hist_entry storing all the energies recorded (with an accuracy o...
Definition: f_ebur128.c:60