FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
f_ebur128.c File Reference

EBU R.128 implementation. More...

#include <math.h>
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/dict.h"
#include "libavutil/xga_font_data.h"
#include "libavutil/opt.h"
#include "libavutil/timestamp.h"
#include "libswresample/swresample.h"
#include "audio.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  hist_entry
 A histogram is an array of HIST_SIZE hist_entry storing all the energies recorded (with an accuracy of 1/HIST_GRAIN) of the loudnesses from ABS_THRES (at 0) to ABS_UP_THRES (at HIST_SIZE-1). More...
 
struct  integrator
 
struct  rect
 
struct  EBUR128Context
 

Macros

#define MAX_CHANNELS   63
 
#define PRE_B0   1.53512485958697
 
#define PRE_B1   -2.69169618940638
 
#define PRE_B2   1.19839281085285
 
#define PRE_A1   -1.69065929318241
 
#define PRE_A2   0.73248077421585
 
#define RLB_B0   1.0
 
#define RLB_B1   -2.0
 
#define RLB_B2   1.0
 
#define RLB_A1   -1.99004745483398
 
#define RLB_A2   0.99007225036621
 
#define ABS_THRES   -70
 silence gate: we discard anything below this absolute (LUFS) threshold More...
 
#define ABS_UP_THRES   10
 upper loud limit to consider (ABS_THRES being the minimum) More...
 
#define HIST_GRAIN   100
 defines histogram precision More...
 
#define HIST_SIZE   ((ABS_UP_THRES - ABS_THRES) * HIST_GRAIN + 1)
 
#define I400_BINS   (48000 * 4 / 10)
 
#define I3000_BINS   (48000 * 3)
 
#define OFFSET(x)   offsetof(EBUR128Context, x)
 
#define A   AV_OPT_FLAG_AUDIO_PARAM
 
#define V   AV_OPT_FLAG_VIDEO_PARAM
 
#define F   AV_OPT_FLAG_FILTERING_PARAM
 
#define FONT8   0
 
#define FONT16   1
 
#define PAD   8
 
#define DRAW_RECT(r)
 
#define BACK_MASK
 
#define ENERGY(loudness)   (ff_exp10(((loudness) + 0.691) / 10.))
 
#define LOUDNESS(energy)   (-0.691 + 10 * log10(energy))
 
#define DBFS(energy)   (20 * log10(energy))
 
#define HIST_POS(power)   (int)(((power) - ABS_THRES) * HIST_GRAIN)
 
#define MOVE_TO_NEXT_CACHED_ENTRY(time)
 
#define FILTER(Y, X, name)
 
#define COMPUTE_LOUDNESS(m, time)
 
#define I_GATE_THRES   -10
 
#define LRA_GATE_THRES   -20
 
#define LRA_LOWER_PRC   10
 
#define LRA_HIGHER_PRC   95
 
#define LOG_FMT   "M:%6.1f S:%6.1f I:%6.1f LUFS LRA:%6.1f LU"
 
#define META_PREFIX   "lavfi.r128."
 
#define SET_META(name, var)
 
#define SET_META_PEAK(name, ptype)
 
#define PRINT_PEAKS(str, sp, ptype)
 
#define PRINT_PEAK_SUMMARY(str, sp, ptype)
 

Enumerations

enum  { PEAK_MODE_NONE = 0, PEAK_MODE_SAMPLES_PEAKS = 1<<1, PEAK_MODE_TRUE_PEAKS = 1<<2 }
 

Functions

 AVFILTER_DEFINE_CLASS (ebur128)
 
static const uint8_tget_graph_color (const EBUR128Context *ebur128, int v, int y)
 
static int lu_to_y (const EBUR128Context *ebur128, double v)
 
static void drawtext (AVFrame *pic, int x, int y, int ftid, const uint8_t *color, const char *fmt,...)
 
static void drawline (AVFrame *pic, int x, int y, int len, int step)
 
static int config_video_output (AVFilterLink *outlink)
 
static int config_audio_input (AVFilterLink *inlink)
 
static int config_audio_output (AVFilterLink *outlink)
 
static struct hist_entryget_histogram (void)
 
static av_cold int init (AVFilterContext *ctx)
 
static int gate_update (struct integrator *integ, double power, double loudness, int gate_thres)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *insamples)
 
static int query_formats (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption ebur128_options []
 
static const uint8_t graph_colors []
 
static const uint8_t font_colors []
 
static const AVFilterPad ebur128_inputs []
 
AVFilter ff_af_ebur128
 

Detailed Description

EBU R.128 implementation.

See Also
http://tech.ebu.ch/loudness
https://www.youtube.com/watch?v=iuEtQqC-Sqo "EBU R128 Introduction - Florian Camerer"
Todo:

implement start/stop/reset through filter command injection

support other frequencies to avoid resampling

Definition in file f_ebur128.c.

Macro Definition Documentation

#define MAX_CHANNELS   63

Definition at line 45 of file f_ebur128.c.

#define PRE_B0   1.53512485958697

Definition at line 48 of file f_ebur128.c.

#define PRE_B1   -2.69169618940638

Definition at line 49 of file f_ebur128.c.

#define PRE_B2   1.19839281085285

Definition at line 50 of file f_ebur128.c.

#define PRE_A1   -1.69065929318241

Definition at line 51 of file f_ebur128.c.

#define PRE_A2   0.73248077421585

Definition at line 52 of file f_ebur128.c.

#define RLB_B0   1.0

Definition at line 55 of file f_ebur128.c.

#define RLB_B1   -2.0

Definition at line 56 of file f_ebur128.c.

#define RLB_B2   1.0

Definition at line 57 of file f_ebur128.c.

#define RLB_A1   -1.99004745483398

Definition at line 58 of file f_ebur128.c.

#define RLB_A2   0.99007225036621

Definition at line 59 of file f_ebur128.c.

#define ABS_THRES   -70

silence gate: we discard anything below this absolute (LUFS) threshold

Definition at line 61 of file f_ebur128.c.

Referenced by filter_frame(), get_histogram(), and init().

#define ABS_UP_THRES   10

upper loud limit to consider (ABS_THRES being the minimum)

Definition at line 62 of file f_ebur128.c.

#define HIST_GRAIN   100

defines histogram precision

Definition at line 63 of file f_ebur128.c.

Referenced by get_histogram().

#define HIST_SIZE   ((ABS_UP_THRES - ABS_THRES) * HIST_GRAIN + 1)

Definition at line 64 of file f_ebur128.c.

Referenced by filter(), filter_frame(), gate_update(), get_histogram(), and init().

#define I400_BINS   (48000 * 4 / 10)

Definition at line 129 of file f_ebur128.c.

Referenced by config_audio_output().

#define I3000_BINS   (48000 * 3)

Definition at line 130 of file f_ebur128.c.

Referenced by config_audio_output().

#define OFFSET (   x)    offsetof(EBUR128Context, x)

Definition at line 152 of file f_ebur128.c.

#define A   AV_OPT_FLAG_AUDIO_PARAM

Definition at line 153 of file f_ebur128.c.

#define V   AV_OPT_FLAG_VIDEO_PARAM

Definition at line 154 of file f_ebur128.c.

Definition at line 155 of file f_ebur128.c.

#define FONT8   0

Definition at line 203 of file f_ebur128.c.

Referenced by config_video_output(), and drawtext().

#define FONT16   1

Definition at line 204 of file f_ebur128.c.

Referenced by drawtext(), and filter_frame().

#define PAD   8
#define DRAW_RECT (   r)
Value:
do { \
drawline(outpicref, r.x, r.y - 1, r.w, 3); \
drawline(outpicref, r.x, r.y + r.h, r.w, 3); \
drawline(outpicref, r.x - 1, r.y, r.h, outpicref->linesize[0]); \
drawline(outpicref, r.x + r.w, r.y, r.h, outpicref->linesize[0]); \
} while (0)
static void drawline(AVFrame *pic, int x, int y, int len, int step)
Definition: f_ebur128.c:244
const char * r
Definition: vf_curves.c:107

Referenced by config_video_output().

#define BACK_MASK
Value:
#define AV_CH_SURROUND_DIRECT_RIGHT
#define AV_CH_TOP_BACK_LEFT
#define AV_CH_TOP_BACK_CENTER
#define AV_CH_BACK_LEFT
#define AV_CH_TOP_BACK_RIGHT
#define AV_CH_BACK_CENTER
#define AV_CH_SIDE_RIGHT
#define AV_CH_SURROUND_DIRECT_LEFT
#define AV_CH_SIDE_LEFT
#define AV_CH_BACK_RIGHT

Referenced by config_audio_output().

#define ENERGY (   loudness)    (ff_exp10(((loudness) + 0.691) / 10.))

Definition at line 438 of file f_ebur128.c.

Referenced by get_histogram().

#define LOUDNESS (   energy)    (-0.691 + 10 * log10(energy))

Definition at line 439 of file f_ebur128.c.

Referenced by filter_frame(), and gate_update().

#define DBFS (   energy)    (20 * log10(energy))

Definition at line 440 of file f_ebur128.c.

#define HIST_POS (   power)    (int)(((power) - ABS_THRES) * HIST_GRAIN)

Definition at line 513 of file f_ebur128.c.

Referenced by gate_update().

#define MOVE_TO_NEXT_CACHED_ENTRY (   time)
Value:
do { \
ebur128->i##time.cache_pos++; \
if (ebur128->i##time.cache_pos == I##time##_BINS) { \
ebur128->i##time.filled = 1; \
ebur128->i##time.cache_pos = 0; \
} \
} while (0)
if(ret< 0)
Definition: vf_mcdeint.c:282

Referenced by filter_frame().

#define FILTER (   Y,
  X,
  name 
)
Value:
do { \
double *dst = ebur128->Y + ch*3; \
double *src = ebur128->X + ch*3; \
dst[2] = dst[1]; \
dst[1] = dst[0]; \
dst[0] = src[0]*name##_B0 + src[1]*name##_B1 + src[2]*name##_B2 \
- dst[1]*name##_A1 - dst[2]*name##_A2; \
} while (0)
#define src
Definition: vp9dsp.c:530
const char * name
Definition: opengl_enc.c:103

Referenced by filter_frame().

#define COMPUTE_LOUDNESS (   m,
  time 
)
Value:
do { \
if (ebur128->i##time.filled) { \
/* weighting sum of the last <time> ms */ \
for (ch = 0; ch < nb_channels; ch++) \
power_##time += ebur128->ch_weighting[ch] * ebur128->i##time.sum[ch]; \
power_##time /= I##time##_BINS; \
} \
loudness_##time = LOUDNESS(power_##time); \
} while (0)
#define LOUDNESS(energy)
Definition: f_ebur128.c:439
if(ret< 0)
Definition: vf_mcdeint.c:282
int nb_channels
for(j=16;j >0;--j)

Referenced by filter_frame().

#define I_GATE_THRES   -10

Referenced by filter_frame().

#define LRA_GATE_THRES   -20

Referenced by filter_frame().

#define LRA_LOWER_PRC   10

Referenced by filter_frame().

#define LRA_HIGHER_PRC   95

Referenced by filter_frame().

#define LOG_FMT   "M:%6.1f S:%6.1f I:%6.1f LUFS LRA:%6.1f LU"

Referenced by filter_frame().

#define META_PREFIX   "lavfi.r128."

Referenced by filter_frame().

#define SET_META (   name,
  var 
)
Value:
do { \
snprintf(metabuf, sizeof(metabuf), "%.3f", var); \
av_dict_set(&insamples->metadata, name, metabuf, 0); \
} while (0)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:69
#define snprintf
Definition: snprintf.h:34
const char * name
Definition: opengl_enc.c:103

Referenced by filter_frame().

#define SET_META_PEAK (   name,
  ptype 
)
Value:
do { \
if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
char key[64]; \
for (ch = 0; ch < nb_channels; ch++) { \
snprintf(key, sizeof(key), \
META_PREFIX AV_STRINGIFY(name) "_peaks_ch%d", ch); \
SET_META(key, ebur128->name##_peaks[ch]); \
} \
} \
} while (0)
#define AV_STRINGIFY(s)
Definition: macros.h:36
#define snprintf
Definition: snprintf.h:34
#define META_PREFIX
if(ret< 0)
Definition: vf_mcdeint.c:282
#define SET_META(name, var)
int nb_channels
for(j=16;j >0;--j)
const char * name
Definition: opengl_enc.c:103

Referenced by filter_frame().

#define PRINT_PEAKS (   str,
  sp,
  ptype 
)
Value:
do { \
if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
av_log(ctx, ebur128->loglevel, " " str ":"); \
for (ch = 0; ch < nb_channels; ch++) \
av_log(ctx, ebur128->loglevel, " %5.1f", DBFS(sp[ch])); \
av_log(ctx, ebur128->loglevel, " dBFS"); \
} \
} while (0)
AVFormatContext * ctx
Definition: movenc-test.c:48
#define sp
Definition: regdef.h:63
#define av_log(a,...)
#define DBFS(energy)
Definition: f_ebur128.c:440
if(ret< 0)
Definition: vf_mcdeint.c:282
int nb_channels
for(j=16;j >0;--j)

Referenced by filter_frame().

#define PRINT_PEAK_SUMMARY (   str,
  sp,
  ptype 
)
Value:
do { \
int ch; \
double maxpeak; \
maxpeak = 0.0; \
if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
for (ch = 0; ch < ebur128->nb_channels; ch++) \
maxpeak = FFMAX(maxpeak, sp[ch]); \
av_log(ctx, AV_LOG_INFO, "\n\n " str " peak:\n" \
" Peak: %5.1f dBFS", \
DBFS(maxpeak)); \
} \
} while (0)
AVFormatContext * ctx
Definition: movenc-test.c:48
#define sp
Definition: regdef.h:63
#define av_log(a,...)
#define FFMAX(a, b)
Definition: common.h:94
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
#define DBFS(energy)
Definition: f_ebur128.c:440
if(ret< 0)
Definition: vf_mcdeint.c:282
for(j=16;j >0;--j)

Referenced by uninit().

Enumeration Type Documentation

anonymous enum
Enumerator
PEAK_MODE_NONE 
PEAK_MODE_SAMPLES_PEAKS 
PEAK_MODE_TRUE_PEAKS 

Definition at line 146 of file f_ebur128.c.

Function Documentation

AVFILTER_DEFINE_CLASS ( ebur128  )
static const uint8_t* get_graph_color ( const EBUR128Context ebur128,
int  v,
int  y 
)
static

Definition at line 186 of file f_ebur128.c.

Referenced by config_video_output(), and filter_frame().

static int lu_to_y ( const EBUR128Context ebur128,
double  v 
)
inlinestatic

Definition at line 195 of file f_ebur128.c.

Referenced by config_video_output(), and filter_frame().

static void drawtext ( AVFrame pic,
int  x,
int  y,
int  ftid,
const uint8_t color,
const char *  fmt,
  ... 
)
static

Definition at line 211 of file f_ebur128.c.

Referenced by config_video_output(), and filter_frame().

static void drawline ( AVFrame pic,
int  x,
int  y,
int  len,
int  step 
)
static

Definition at line 244 of file f_ebur128.c.

static int config_video_output ( AVFilterLink outlink)
static

Definition at line 255 of file f_ebur128.c.

Referenced by init().

static int config_audio_input ( AVFilterLink inlink)
static

Definition at line 347 of file f_ebur128.c.

static int config_audio_output ( AVFilterLink outlink)
static

Definition at line 365 of file f_ebur128.c.

Referenced by init().

static struct hist_entry* get_histogram ( void  )
static

Definition at line 442 of file f_ebur128.c.

Referenced by init().

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 456 of file f_ebur128.c.

static int gate_update ( struct integrator integ,
double  power,
double  loudness,
int  gate_thres 
)
static

Definition at line 517 of file f_ebur128.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink inlink,
AVFrame insamples 
)
static

Definition at line 540 of file f_ebur128.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 823 of file f_ebur128.c.

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 865 of file f_ebur128.c.

Variable Documentation

const AVOption ebur128_options[]
static
Initial value:
= {
{ "video", "set video output", OFFSET(do_video), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, V|F },
{ "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x480"}, 0, 0, V|F },
{ "meter", "set scale meter (+9 to +18)", OFFSET(meter), AV_OPT_TYPE_INT, {.i64 = 9}, 9, 18, V|F },
{ "framelog", "force frame logging level", OFFSET(loglevel), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, A|V|F, "level" },
{ "info", "information logging level", 0, AV_OPT_TYPE_CONST, {.i64 = AV_LOG_INFO}, INT_MIN, INT_MAX, A|V|F, "level" },
{ "verbose", "verbose logging level", 0, AV_OPT_TYPE_CONST, {.i64 = AV_LOG_VERBOSE}, INT_MIN, INT_MAX, A|V|F, "level" },
{ "metadata", "inject metadata in the filtergraph", OFFSET(metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A|V|F },
{ "peak", "set peak mode", OFFSET(peak_mode), AV_OPT_TYPE_FLAGS, {.i64 = PEAK_MODE_NONE}, 0, INT_MAX, A|F, "mode" },
{ "none", "disable any peak mode", 0, AV_OPT_TYPE_CONST, {.i64 = PEAK_MODE_NONE}, INT_MIN, INT_MAX, A|F, "mode" },
{ "sample", "enable peak-sample mode", 0, AV_OPT_TYPE_CONST, {.i64 = PEAK_MODE_SAMPLES_PEAKS}, INT_MIN, INT_MAX, A|F, "mode" },
{ "true", "enable true-peak mode", 0, AV_OPT_TYPE_CONST, {.i64 = PEAK_MODE_TRUE_PEAKS}, INT_MIN, INT_MAX, A|F, "mode" },
{ "dualmono", "treat mono input files as dual-mono", OFFSET(dual_mono), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A|F },
{ "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 },
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define F
Definition: f_ebur128.c:155
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define OFFSET(x)
Definition: f_ebur128.c:152
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
offset must point to two consecutive integers
Definition: opt.h:232
#define A
Definition: f_ebur128.c:153
#define V
Definition: f_ebur128.c:154

Definition at line 156 of file f_ebur128.c.

const uint8_t graph_colors[]
static
Initial value:
= {
0xdd, 0x66, 0x66,
0x66, 0x66, 0xdd,
0x96, 0x33, 0x33,
0x33, 0x33, 0x96,
0xdd, 0x96, 0x96,
0x96, 0x96, 0xdd,
0xdd, 0x33, 0x33,
0x33, 0x33, 0xdd,
}

Definition at line 175 of file f_ebur128.c.

Referenced by get_graph_color().

const uint8_t font_colors[]
static
Initial value:
= {
0xdd, 0xdd, 0x00,
0x00, 0x96, 0x96,
}

Definition at line 206 of file f_ebur128.c.

Referenced by config_video_output(), and filter_frame().

const AVFilterPad ebur128_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_audio_input,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
Definition: f_ebur128.c:540
static int config_audio_input(AVFilterLink *inlink)
Definition: f_ebur128.c:347

Definition at line 928 of file f_ebur128.c.

AVFilter ff_af_ebur128
Initial value:
= {
.name = "ebur128",
.description = NULL_IF_CONFIG_SMALL("EBU R128 scanner."),
.priv_size = sizeof(EBUR128Context),
.init = init,
.priv_class = &ebur128_class,
}
#define NULL
Definition: coverity.c:32
static int query_formats(AVFilterContext *ctx)
Definition: f_ebur128.c:823
static av_cold int init(AVFilterContext *ctx)
Definition: f_ebur128.c:456
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:108
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
static av_cold void uninit(AVFilterContext *ctx)
Definition: f_ebur128.c:865
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:385
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:375
static int flags
Definition: cpu.c:47
static const AVFilterPad ebur128_inputs[]
Definition: f_ebur128.c:928

Definition at line 938 of file f_ebur128.c.