FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
af_loudnorm.c File Reference
#include "libavutil/opt.h"
#include "avfilter.h"
#include "filters.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 []
 
static const AVFilterPad avfilter_af_loudnorm_outputs []
 
const AVFilter ff_af_loudnorm
 

Macro Definition Documentation

◆ OFFSET

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

Definition at line 99 of file af_loudnorm.c.

◆ FLAGS

Definition at line 100 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 30 of file af_loudnorm.c.

◆ LimiterState

Enumerator
OUT 
ATTACK 
SUSTAIN 
RELEASE 
STATE_NB 

Definition at line 38 of file af_loudnorm.c.

◆ PrintFormat

Enumerator
NONE 
JSON 
SUMMARY 
PF_NB 

Definition at line 46 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 128 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 134 of file af_loudnorm.c.

Referenced by config_input().

◆ gaussian_filter()

static double gaussian_filter ( LoudNormContext s,
int  index 
)
static

Definition at line 156 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 168 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 231 of file af_loudnorm.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 410 of file af_loudnorm.c.

Referenced by activate(), and flush_frame().

◆ flush_frame()

static int flush_frame ( AVFilterLink outlink)
static

Definition at line 633 of file af_loudnorm.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 677 of file af_loudnorm.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 730 of file af_loudnorm.c.

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 755 of file af_loudnorm.c.

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 803 of file af_loudnorm.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 824 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, "print_format" },
{ "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = NONE}, 0, 0, FLAGS, "print_format" },
{ "json", 0, 0, AV_OPT_TYPE_CONST, {.i64 = JSON}, 0, 0, FLAGS, "print_format" },
{ "summary", 0, 0, AV_OPT_TYPE_CONST, {.i64 = SUMMARY}, 0, 0, FLAGS, "print_format" },
{ NULL }
}

Definition at line 102 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 923 of file af_loudnorm.c.

◆ avfilter_af_loudnorm_outputs

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

Definition at line 931 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 938 of file af_loudnorm.c.

init
static av_cold int init(AVFilterContext *ctx)
Definition: af_loudnorm.c:803
NONE
@ NONE
Definition: af_loudnorm.c:47
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_loudnorm.c:824
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:171
linear
static int linear(InterplayACMContext *s, unsigned ind, unsigned col)
Definition: interplayacm.c:132
print_format
static char * print_format
Definition: ffprobe.c:137
avfilter_af_loudnorm_outputs
static const AVFilterPad avfilter_af_loudnorm_outputs[]
Definition: af_loudnorm.c:931
JSON
@ JSON
Definition: af_loudnorm.c:48
FLAGS
#define FLAGS
Definition: af_loudnorm.c:100
SUMMARY
@ SUMMARY
Definition: af_loudnorm.c:49
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:194
NULL
#define NULL
Definition: coverity.c:32
activate
static int activate(AVFilterContext *ctx)
Definition: af_loudnorm.c:677
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_loudnorm.c:730
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:115
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:53
avfilter_af_loudnorm_inputs
static const AVFilterPad avfilter_af_loudnorm_inputs[]
Definition: af_loudnorm.c:923
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_loudnorm.c:755
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
PF_NB
@ PF_NB
Definition: af_loudnorm.c:50
OFFSET
#define OFFSET(x)
Definition: af_loudnorm.c:99
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:195
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234