FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
f_ebur128.c File Reference
#include <float.h>
#include <math.h>
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/dict.h"
#include "libavutil/ffmath.h"
#include "libavutil/mem.h"
#include "libavutil/xga_font_data.h"
#include "libavutil/opt.h"
#include "libavutil/timestamp.h"
#include "libswresample/swresample.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "video.h"
#include "f_ebur128.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 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 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 X   AV_OPT_FLAG_EXPORT
 
#define R   AV_OPT_FLAG_READONLY
 
#define FONT8   0
 
#define FONT16   1
 
#define PAD   8
 
#define DRAW_RECT(r)
 
#define BACK_MASK
 
#define I400_BINS(x)   ((x) * 4 / 10)
 
#define I3000_BINS(x)   ((x) * 3)
 
#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 FILTER(DST, SRC, FILT)
 
#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   "TARGET:%d LUFS M:%6.1f S:%6.1f I:%6.1f %s 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, value, ptype)
 

Enumerations

enum  { PEAK_MODE_NONE = 0, PEAK_MODE_SAMPLES_PEAKS = 1<<1, PEAK_MODE_TRUE_PEAKS = 1<<2 }
 
enum  { GAUGE_TYPE_MOMENTARY = 0, GAUGE_TYPE_SHORTTERM = 1 }
 
enum  { SCALE_TYPE_ABSOLUTE = 0, SCALE_TYPE_RELATIVE = 1 }
 

Functions

 AVFILTER_DEFINE_CLASS (ebur128)
 
static const uint8_t * get_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)
 
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)
 
double ff_ebur128_find_peak_c (double *restrict ch_peaks, const int nb_channels, const double *samples, const int nb_samples)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *insamples)
 
static int activate (AVFilterContext *ctx)
 
static int query_formats (const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
 
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 []
 
const FFFilter 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

Definition in file f_ebur128.c.

Macro Definition Documentation

◆ ABS_THRES

#define ABS_THRES   -70

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

Definition at line 48 of file f_ebur128.c.

◆ ABS_UP_THRES

#define ABS_UP_THRES   10

upper loud limit to consider (ABS_THRES being the minimum)

Definition at line 49 of file f_ebur128.c.

◆ HIST_GRAIN

#define HIST_GRAIN   100

defines histogram precision

Definition at line 50 of file f_ebur128.c.

◆ HIST_SIZE

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

Definition at line 51 of file f_ebur128.c.

◆ OFFSET

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

Definition at line 153 of file f_ebur128.c.

◆ A

#define A   AV_OPT_FLAG_AUDIO_PARAM

Definition at line 154 of file f_ebur128.c.

◆ V

#define V   AV_OPT_FLAG_VIDEO_PARAM

Definition at line 155 of file f_ebur128.c.

◆ F

Definition at line 156 of file f_ebur128.c.

◆ X

#define X   AV_OPT_FLAG_EXPORT

Definition at line 157 of file f_ebur128.c.

◆ R

#define R   AV_OPT_FLAG_READONLY

Definition at line 158 of file f_ebur128.c.

◆ FONT8

#define FONT8   0

Definition at line 233 of file f_ebur128.c.

◆ FONT16

#define FONT16   1

Definition at line 234 of file f_ebur128.c.

◆ PAD

#define PAD   8

◆ DRAW_RECT

#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)

◆ BACK_MASK

#define BACK_MASK
Value:

◆ I400_BINS

#define I400_BINS (   x)    ((x) * 4 / 10)

◆ I3000_BINS

#define I3000_BINS (   x)    ((x) * 3)

◆ ENERGY

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

Definition at line 511 of file f_ebur128.c.

◆ LOUDNESS

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

Definition at line 512 of file f_ebur128.c.

◆ DBFS

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

Definition at line 513 of file f_ebur128.c.

◆ HIST_POS

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

Definition at line 590 of file f_ebur128.c.

◆ FILTER

#define FILTER (   DST,
  SRC,
  FILT 
)
Value:
do { \
const double tmp = DST[0] = FILT.b0 * SRC + DST[1]; \
DST[1] = FILT.b1 * SRC + DST[2] - FILT.a1 * tmp; \
DST[2] = FILT.b2 * SRC - FILT.a2 * tmp; \
} while (0)

◆ COMPUTE_LOUDNESS

#define COMPUTE_LOUDNESS (   m,
  time 
)
Value:
do { \
if (ebur128->i##time.filled) { \
/* weighting sum of the last <time> ms */ \
for (int ch = 0; ch < nb_channels; ch++) \
power_##time += ebur128->ch_weighting[ch] * ebur128->i##time.sum[ch]; \
power_##time /= I##time##_BINS(inlink->sample_rate); \
} \
loudness_##time = LOUDNESS(power_##time); \
} while (0)

◆ I_GATE_THRES

#define I_GATE_THRES   -10

◆ LRA_GATE_THRES

#define LRA_GATE_THRES   -20

◆ LRA_LOWER_PRC

#define LRA_LOWER_PRC   10

◆ LRA_HIGHER_PRC

#define LRA_HIGHER_PRC   95

◆ LOG_FMT

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

◆ META_PREFIX

#define META_PREFIX   "lavfi.r128."

◆ SET_META

#define SET_META (   name,
  var 
)
Value:
do { \
snprintf(metabuf, sizeof(metabuf), "%.3f", var); \
av_dict_set(&insamples->metadata, name, metabuf, 0); \
} while (0)

◆ SET_META_PEAK

#define SET_META_PEAK (   name,
  ptype 
)
Value:
do { \
if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
double max_peak = 0.0; \
char key[64]; \
for (int ch = 0; ch < nb_channels; ch++) { \
snprintf(key, sizeof(key), \
META_PREFIX AV_STRINGIFY(name) "_peaks_ch%d", ch); \
max_peak = fmax(max_peak, ebur128->name##_peaks[ch]); \
SET_META(key, ebur128->name##_peaks[ch]); \
} \
snprintf(key, sizeof(key), \
SET_META(key, max_peak); \
} \
} while (0)

◆ PRINT_PEAKS

#define PRINT_PEAKS (   str,
  sp,
  ptype 
)
Value:
do { \
if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
av_log(ctx, ebur128->loglevel, " " str ":"); \
for (int ch = 0; ch < nb_channels; ch++) \
av_log(ctx, ebur128->loglevel, " %5.1f", DBFS(sp[ch])); \
av_log(ctx, ebur128->loglevel, " dBFS"); \
} \
} while (0)

◆ PRINT_PEAK_SUMMARY

#define PRINT_PEAK_SUMMARY (   str,
  value,
  ptype 
)
Value:
do { \
if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \
av_log(ctx, AV_LOG_INFO, "\n\n " str " peak:\n" \
" Peak: %5.1f dBFS", value); \
} \
} while (0)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PEAK_MODE_NONE 
PEAK_MODE_SAMPLES_PEAKS 
PEAK_MODE_TRUE_PEAKS 

Definition at line 137 of file f_ebur128.c.

◆ anonymous enum

anonymous enum
Enumerator
GAUGE_TYPE_MOMENTARY 
GAUGE_TYPE_SHORTTERM 

Definition at line 143 of file f_ebur128.c.

◆ anonymous enum

anonymous enum
Enumerator
SCALE_TYPE_ABSOLUTE 
SCALE_TYPE_RELATIVE 

Definition at line 148 of file f_ebur128.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( ebur128  )

◆ get_graph_color()

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

Definition at line 215 of file f_ebur128.c.

Referenced by config_video_output(), and filter_frame().

◆ lu_to_y()

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

Definition at line 225 of file f_ebur128.c.

Referenced by config_video_output(), and filter_frame().

◆ drawtext()

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

Definition at line 241 of file f_ebur128.c.

Referenced by config_video_output(), and filter_frame().

◆ drawline()

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

Definition at line 274 of file f_ebur128.c.

◆ config_video_output()

static int config_video_output ( AVFilterLink outlink)
static

Definition at line 285 of file f_ebur128.c.

Referenced by init().

◆ config_audio_input()

static int config_audio_input ( AVFilterLink inlink)
static

Definition at line 384 of file f_ebur128.c.

◆ config_audio_output()

static int config_audio_output ( AVFilterLink outlink)
static

Definition at line 429 of file f_ebur128.c.

Referenced by init().

◆ get_histogram()

static struct hist_entry* get_histogram ( void  )
static

Definition at line 515 of file f_ebur128.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 529 of file f_ebur128.c.

◆ gate_update()

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

Definition at line 594 of file f_ebur128.c.

Referenced by filter_frame().

◆ 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 at line 617 of file f_ebur128.c.

Referenced by init().

◆ 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 at line 653 of file f_ebur128.c.

Referenced by init().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame insamples 
)
static

Definition at line 670 of file f_ebur128.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 974 of file f_ebur128.c.

◆ query_formats()

static int query_formats ( const AVFilterContext ctx,
AVFilterFormatsConfig **  cfg_in,
AVFilterFormatsConfig **  cfg_out 
)
static

Definition at line 1011 of file f_ebur128.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 1042 of file f_ebur128.c.

Variable Documentation

◆ ebur128_options

const AVOption ebur128_options[]
static

Definition at line 159 of file f_ebur128.c.

◆ graph_colors

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,
0xdd, 0x66, 0x66,
0x66, 0xdd, 0x66,
0x96, 0x33, 0x33,
0x33, 0x96, 0x33,
0xdd, 0x96, 0x96,
0x96, 0xdd, 0x96,
0xdd, 0x33, 0x33,
0x33, 0xdd, 0x33,
}

Definition at line 196 of file f_ebur128.c.

Referenced by get_graph_color().

◆ font_colors

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

Definition at line 236 of file f_ebur128.c.

Referenced by config_video_output(), and filter_frame().

◆ ebur128_inputs

const AVFilterPad ebur128_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_audio_input,
},
}

Definition at line 1100 of file f_ebur128.c.

◆ ff_af_ebur128

const FFFilter ff_af_ebur128
Initial value:
= {
.p.name = "ebur128",
.p.description = NULL_IF_CONFIG_SMALL("EBU R128 scanner."),
.p.outputs = NULL,
.p.priv_class = &ebur128_class,
.priv_size = sizeof(EBUR128Context),
.init = init,
}

Definition at line 1108 of file f_ebur128.c.

name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
r
const char * r
Definition: vf_curves.c:127
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
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
init
static av_cold int init(AVFilterContext *ctx)
Definition: f_ebur128.c:529
AV_CH_SURROUND_DIRECT_RIGHT
#define AV_CH_SURROUND_DIRECT_RIGHT
Definition: channel_layout.h:198
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: f_ebur128.c:1042
AV_CH_TOP_BACK_CENTER
#define AV_CH_TOP_BACK_CENTER
Definition: channel_layout.h:191
AV_CH_BACK_LEFT
#define AV_CH_BACK_LEFT
Definition: channel_layout.h:179
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:49
key
const char * key
Definition: hwcontext_opencl.c:189
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: f_ebur128.c:1011
NULL
#define NULL
Definition: coverity.c:32
tmp
static uint8_t tmp[20]
Definition: aes_ctr.c:47
EBUR128Context
Definition: f_ebur128.c:80
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
activate
static int activate(AVFilterContext *ctx)
Definition: f_ebur128.c:974
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
AV_CH_TOP_BACK_RIGHT
#define AV_CH_TOP_BACK_RIGHT
Definition: channel_layout.h:192
SRC
#define SRC(x, y)
Definition: h264pred_template.c:822
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
AV_CH_BACK_CENTER
#define AV_CH_BACK_CENTER
Definition: channel_layout.h:183
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AV_STRINGIFY
#define AV_STRINGIFY(s)
Definition: macros.h:66
AV_CH_SIDE_RIGHT
#define AV_CH_SIDE_RIGHT
Definition: channel_layout.h:185
fmax
double fmax(double, double)
META_PREFIX
#define META_PREFIX
LOUDNESS
#define LOUDNESS(energy)
Definition: f_ebur128.c:512
DBFS
#define DBFS(energy)
Definition: f_ebur128.c:513
ebur128_inputs
static const AVFilterPad ebur128_inputs[]
Definition: f_ebur128.c:1100
DST
#define DST(x, y)
Definition: vp9dsp_template.c:813
config_audio_input
static int config_audio_input(AVFilterLink *inlink)
Definition: f_ebur128.c:384
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_CH_BACK_RIGHT
#define AV_CH_BACK_RIGHT
Definition: channel_layout.h:180