FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
af_loudnorm.c File Reference
#include "libavutil/opt.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "internal.h"
#include "audio.h"
#include "ebur128.h"

Go to the source code of this file.

Data Structures

struct  LoudNormContext
 

Macros

#define OFFSET(x)   offsetof(LoudNormContext, x)
 
#define FLAGS   AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Enumerations

enum  FrameType {
  ACTIVE_FRAME, SID_FRAME, UNTRANSMITTED_FRAME, INTRA_FRAME = 0,
  INTER_FRAME, SKIP_FRAME, FIRST_FRAME, INNER_FRAME,
  FINAL_FRAME, LINEAR_MODE, FRAME_NB
}
 
enum  LimiterState {
  OUT, ATTACK, SUSTAIN, RELEASE,
  STATE_NB
}
 
enum  PrintFormat { NONE, JSON, SUMMARY, PF_NB }
 

Functions

 AVFILTER_DEFINE_CLASS (loudnorm)
 
static int frame_size (int sample_rate, int frame_len_msec)
 
static void init_gaussian_filter (LoudNormContext *s)
 
static double gaussian_filter (LoudNormContext *s, int index)
 
static void detect_peak (LoudNormContext *s, int offset, int nb_samples, int channels, int *peak_delta, double *peak_value)
 
static void true_peak_limiter (LoudNormContext *s, double *out, int nb_samples, int channels)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int flush_frame (AVFilterLink *outlink)
 
static int activate (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 
static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption loudnorm_options []
 
static const AVFilterPad avfilter_af_loudnorm_inputs []
 
const AVFilter ff_af_loudnorm
 

Macro Definition Documentation

◆ OFFSET

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

Definition at line 100 of file af_loudnorm.c.

◆ FLAGS

Definition at line 101 of file af_loudnorm.c.

Enumeration Type Documentation

◆ FrameType

enum FrameType
Enumerator
ACTIVE_FRAME 

Active speech.

SID_FRAME 

Silence Insertion Descriptor frame.

UNTRANSMITTED_FRAME 
INTRA_FRAME 
INTER_FRAME 
SKIP_FRAME 
FIRST_FRAME 
INNER_FRAME 
FINAL_FRAME 
LINEAR_MODE 
FRAME_NB 

Definition at line 31 of file af_loudnorm.c.

◆ LimiterState

Enumerator
OUT 
ATTACK 
SUSTAIN 
RELEASE 
STATE_NB 

Definition at line 39 of file af_loudnorm.c.

◆ PrintFormat

Enumerator
NONE 
JSON 
SUMMARY 
PF_NB 

Definition at line 47 of file af_loudnorm.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( loudnorm  )

◆ frame_size()

static int frame_size ( int  sample_rate,
int  frame_len_msec 
)
inlinestatic

Definition at line 129 of file af_loudnorm.c.

Referenced by activate(), config_input(), filter_frame(), and flush_frame().

◆ init_gaussian_filter()

static void init_gaussian_filter ( LoudNormContext s)
static

Definition at line 135 of file af_loudnorm.c.

Referenced by config_input().

◆ gaussian_filter()

static double gaussian_filter ( LoudNormContext s,
int  index 
)
static

Definition at line 157 of file af_loudnorm.c.

Referenced by filter_frame().

◆ detect_peak()

static void detect_peak ( LoudNormContext s,
int  offset,
int  nb_samples,
int  channels,
int peak_delta,
double peak_value 
)
static

Definition at line 169 of file af_loudnorm.c.

Referenced by true_peak_limiter().

◆ true_peak_limiter()

static void true_peak_limiter ( LoudNormContext s,
double out,
int  nb_samples,
int  channels 
)
static

Definition at line 232 of file af_loudnorm.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 411 of file af_loudnorm.c.

Referenced by activate(), and flush_frame().

◆ flush_frame()

static int flush_frame ( AVFilterLink outlink)
static

Definition at line 634 of file af_loudnorm.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 678 of file af_loudnorm.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 731 of file af_loudnorm.c.

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 754 of file af_loudnorm.c.

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 802 of file af_loudnorm.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 823 of file af_loudnorm.c.

Variable Documentation

◆ loudnorm_options

const AVOption loudnorm_options[]
static
Initial value:
= {
{ "I", "set integrated loudness target", OFFSET(target_i), AV_OPT_TYPE_DOUBLE, {.dbl = -24.}, -70., -5., FLAGS },
{ "i", "set integrated loudness target", OFFSET(target_i), AV_OPT_TYPE_DOUBLE, {.dbl = -24.}, -70., -5., FLAGS },
{ "LRA", "set loudness range target", OFFSET(target_lra), AV_OPT_TYPE_DOUBLE, {.dbl = 7.}, 1., 50., FLAGS },
{ "lra", "set loudness range target", OFFSET(target_lra), AV_OPT_TYPE_DOUBLE, {.dbl = 7.}, 1., 50., FLAGS },
{ "TP", "set maximum true peak", OFFSET(target_tp), AV_OPT_TYPE_DOUBLE, {.dbl = -2.}, -9., 0., FLAGS },
{ "tp", "set maximum true peak", OFFSET(target_tp), AV_OPT_TYPE_DOUBLE, {.dbl = -2.}, -9., 0., FLAGS },
{ "measured_I", "measured IL of input file", OFFSET(measured_i), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, -99., 0., FLAGS },
{ "measured_i", "measured IL of input file", OFFSET(measured_i), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, -99., 0., FLAGS },
{ "measured_LRA", "measured LRA of input file", OFFSET(measured_lra), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, 0., 99., FLAGS },
{ "measured_lra", "measured LRA of input file", OFFSET(measured_lra), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, 0., 99., FLAGS },
{ "measured_TP", "measured true peak of input file", OFFSET(measured_tp), AV_OPT_TYPE_DOUBLE, {.dbl = 99.}, -99., 99., FLAGS },
{ "measured_tp", "measured true peak of input file", OFFSET(measured_tp), AV_OPT_TYPE_DOUBLE, {.dbl = 99.}, -99., 99., FLAGS },
{ "measured_thresh", "measured threshold of input file", OFFSET(measured_thresh), AV_OPT_TYPE_DOUBLE, {.dbl = -70.}, -99., 0., FLAGS },
{ "offset", "set offset gain", OFFSET(offset), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, -99., 99., FLAGS },
{ "linear", "normalize linearly if possible", OFFSET(linear), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
{ "dual_mono", "treat mono input as dual-mono", OFFSET(dual_mono), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
{ "print_format", "set print format for stats", OFFSET(print_format), AV_OPT_TYPE_INT, {.i64 = NONE}, NONE, PF_NB -1, FLAGS, .unit = "print_format" },
{ "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = NONE}, 0, 0, FLAGS, .unit = "print_format" },
{ "json", 0, 0, AV_OPT_TYPE_CONST, {.i64 = JSON}, 0, 0, FLAGS, .unit = "print_format" },
{ "summary", 0, 0, AV_OPT_TYPE_CONST, {.i64 = SUMMARY}, 0, 0, FLAGS, .unit = "print_format" },
{ NULL }
}

Definition at line 103 of file af_loudnorm.c.

◆ avfilter_af_loudnorm_inputs

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

Definition at line 922 of file af_loudnorm.c.

◆ ff_af_loudnorm

const AVFilter ff_af_loudnorm
Initial value:
= {
.name = "loudnorm",
.description = NULL_IF_CONFIG_SMALL("EBU R128 loudness normalization"),
.priv_size = sizeof(LoudNormContext),
.priv_class = &loudnorm_class,
.init = init,
}

Definition at line 930 of file af_loudnorm.c.

init
static av_cold int init(AVFilterContext *ctx)
Definition: af_loudnorm.c:802
NONE
@ NONE
Definition: af_loudnorm.c:48
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_loudnorm.c:823
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:159
linear
static int linear(InterplayACMContext *s, unsigned ind, unsigned col)
Definition: interplayacm.c:134
JSON
@ JSON
Definition: af_loudnorm.c:49
FLAGS
#define FLAGS
Definition: af_loudnorm.c:101
SUMMARY
@ SUMMARY
Definition: af_loudnorm.c:50
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:237
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
NULL
#define NULL
Definition: coverity.c:32
ff_audio_default_filterpad
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
Definition: audio.c:33
activate
static int activate(AVFilterContext *ctx)
Definition: af_loudnorm.c:678
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_loudnorm.c:731
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:106
offset
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 offset
Definition: writing_filters.txt:86
LoudNormContext
Definition: af_loudnorm.c:54
avfilter_af_loudnorm_inputs
static const AVFilterPad avfilter_af_loudnorm_inputs[]
Definition: af_loudnorm.c:922
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_loudnorm.c:754
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
PF_NB
@ PF_NB
Definition: af_loudnorm.c:51
OFFSET
#define OFFSET(x)
Definition: af_loudnorm.c:100
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244