FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
af_silenceremove.c File Reference
#include <float.h>
#include "libavutil/audio_fifo.h"
#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include "libavutil/timestamp.h"
#include "audio.h"
#include "formats.h"
#include "avfilter.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  SilenceRemoveContext
 

Macros

#define OFFSET(x)   offsetof(SilenceRemoveContext, x)
 
#define AF   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
 

Enumerations

enum  SilenceDetect { D_PEAK, D_RMS }
 
enum  ThresholdMode { T_ANY, T_ALL }
 
enum  SilenceMode {
  SILENCE_TRIM, SILENCE_TRIM_FLUSH, SILENCE_COPY, SILENCE_COPY_FLUSH,
  SILENCE_STOP
}
 

Functions

 AVFILTER_DEFINE_CLASS (silenceremove)
 
static void copy_double (SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
 
static void copy_doublep (SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
 
static void copy_float (SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
 
static void copy_floatp (SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
 
static double compute_peak_double (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static void update_peak_double (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static double compute_peak_float (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static void update_peak_float (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static double compute_rms_double (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static void update_rms_double (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static double compute_rms_float (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static void update_rms_float (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static double compute_peak_doublep (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static void update_peak_doublep (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static double compute_peak_floatp (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static void update_peak_floatp (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static double compute_rms_doublep (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static void update_rms_doublep (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static double compute_rms_floatp (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static void update_rms_floatp (SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 
static av_cold int init (AVFilterContext *ctx)
 
static void clear_window (SilenceRemoveContext *s)
 
static int config_input (AVFilterLink *inlink)
 
static void flush (SilenceRemoveContext *s, AVFrame *out, AVFilterLink *outlink, int *nb_samples_written, int flush_silence)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int request_frame (AVFilterLink *outlink)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption silenceremove_options []
 
static const AVFilterPad silenceremove_inputs []
 
static const AVFilterPad silenceremove_outputs []
 
const AVFilter ff_af_silenceremove
 

Macro Definition Documentation

◆ OFFSET

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

Definition at line 110 of file af_silenceremove.c.

◆ AF

Definition at line 111 of file af_silenceremove.c.

Enumeration Type Documentation

◆ SilenceDetect

Enumerator
D_PEAK 
D_RMS 

Definition at line 35 of file af_silenceremove.c.

◆ ThresholdMode

Enumerator
T_ANY 
T_ALL 

Definition at line 40 of file af_silenceremove.c.

◆ SilenceMode

Enumerator
SILENCE_TRIM 
SILENCE_TRIM_FLUSH 
SILENCE_COPY 
SILENCE_COPY_FLUSH 
SILENCE_STOP 

Definition at line 45 of file af_silenceremove.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( silenceremove  )

◆ copy_double()

static void copy_double ( SilenceRemoveContext s,
AVFrame out,
AVFrame in,
int  ch,
int  out_offset,
int  in_offset 
)
static

Definition at line 135 of file af_silenceremove.c.

Referenced by config_input(), and swri_rematrix_init().

◆ copy_doublep()

static void copy_doublep ( SilenceRemoveContext s,
AVFrame out,
AVFrame in,
int  ch,
int  out_offset,
int  in_offset 
)
static

Definition at line 145 of file af_silenceremove.c.

Referenced by config_input().

◆ copy_float()

static void copy_float ( SilenceRemoveContext s,
AVFrame out,
AVFrame in,
int  ch,
int  out_offset,
int  in_offset 
)
static

Definition at line 155 of file af_silenceremove.c.

Referenced by config_input(), and swri_rematrix_init().

◆ copy_floatp()

static void copy_floatp ( SilenceRemoveContext s,
AVFrame out,
AVFrame in,
int  ch,
int  out_offset,
int  in_offset 
)
static

Definition at line 165 of file af_silenceremove.c.

Referenced by config_input().

◆ compute_peak_double()

static double compute_peak_double ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 175 of file af_silenceremove.c.

Referenced by config_input().

◆ update_peak_double()

static void update_peak_double ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 191 of file af_silenceremove.c.

Referenced by config_input().

◆ compute_peak_float()

static double compute_peak_float ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 204 of file af_silenceremove.c.

Referenced by config_input().

◆ update_peak_float()

static void update_peak_float ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 220 of file af_silenceremove.c.

Referenced by config_input().

◆ compute_rms_double()

static double compute_rms_double ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 233 of file af_silenceremove.c.

Referenced by config_input().

◆ update_rms_double()

static void update_rms_double ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 250 of file af_silenceremove.c.

Referenced by config_input().

◆ compute_rms_float()

static double compute_rms_float ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 263 of file af_silenceremove.c.

Referenced by config_input().

◆ update_rms_float()

static void update_rms_float ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 280 of file af_silenceremove.c.

Referenced by config_input().

◆ compute_peak_doublep()

static double compute_peak_doublep ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 293 of file af_silenceremove.c.

Referenced by config_input().

◆ update_peak_doublep()

static void update_peak_doublep ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 309 of file af_silenceremove.c.

Referenced by config_input().

◆ compute_peak_floatp()

static double compute_peak_floatp ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 322 of file af_silenceremove.c.

Referenced by config_input().

◆ update_peak_floatp()

static void update_peak_floatp ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 338 of file af_silenceremove.c.

Referenced by config_input().

◆ compute_rms_doublep()

static double compute_rms_doublep ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 351 of file af_silenceremove.c.

Referenced by config_input().

◆ update_rms_doublep()

static void update_rms_doublep ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 368 of file af_silenceremove.c.

Referenced by config_input().

◆ compute_rms_floatp()

static double compute_rms_floatp ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 381 of file af_silenceremove.c.

Referenced by config_input().

◆ update_rms_floatp()

static void update_rms_floatp ( SilenceRemoveContext s,
AVFrame frame,
int  ch,
int  offset 
)
static

Definition at line 398 of file af_silenceremove.c.

Referenced by config_input().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 411 of file af_silenceremove.c.

◆ clear_window()

static void clear_window ( SilenceRemoveContext s)
static

Definition at line 423 of file af_silenceremove.c.

Referenced by config_input(), and filter_frame().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 432 of file af_silenceremove.c.

◆ flush()

static void flush ( SilenceRemoveContext s,
AVFrame out,
AVFilterLink outlink,
int nb_samples_written,
int  flush_silence 
)
static

Definition at line 555 of file af_silenceremove.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 598 of file af_silenceremove.c.

◆ request_frame()

static int request_frame ( AVFilterLink outlink)
static

Definition at line 895 of file af_silenceremove.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 928 of file af_silenceremove.c.

Variable Documentation

◆ silenceremove_options

const AVOption silenceremove_options[]
static
Initial value:
= {
{ "start_periods", "set periods of silence parts to skip from start", OFFSET(start_periods), AV_OPT_TYPE_INT, {.i64=0}, 0, 9000, AF },
{ "start_duration", "set start duration of non-silence part", OFFSET(start_duration_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
{ "start_threshold", "set threshold for start silence detection", OFFSET(start_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, AF },
{ "start_silence", "set start duration of silence part to keep", OFFSET(start_silence_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
{ "start_mode", "set which channel will trigger trimming from start", OFFSET(start_mode), AV_OPT_TYPE_INT, {.i64=T_ANY}, T_ANY, T_ALL, AF, "mode" },
{ "any", 0, 0, AV_OPT_TYPE_CONST, {.i64=T_ANY}, 0, 0, AF, "mode" },
{ "all", 0, 0, AV_OPT_TYPE_CONST, {.i64=T_ALL}, 0, 0, AF, "mode" },
{ "stop_periods", "set periods of silence parts to skip from end", OFFSET(stop_periods), AV_OPT_TYPE_INT, {.i64=0}, -9000, 9000, AF },
{ "stop_duration", "set stop duration of non-silence part", OFFSET(stop_duration_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
{ "stop_threshold", "set threshold for stop silence detection", OFFSET(stop_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, AF },
{ "stop_silence", "set stop duration of silence part to keep", OFFSET(stop_silence_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
{ "stop_mode", "set which channel will trigger trimming from end", OFFSET(stop_mode), AV_OPT_TYPE_INT, {.i64=T_ANY}, T_ANY, T_ALL, AF, "mode" },
{ "detection", "set how silence is detected", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=D_RMS}, D_PEAK,D_RMS, AF, "detection" },
{ "peak", "use absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" },
{ "rms", "use squared values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_RMS}, 0, 0, AF, "detection" },
{ "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF },
{ NULL }
}

Definition at line 113 of file af_silenceremove.c.

◆ silenceremove_inputs

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

Definition at line 942 of file af_silenceremove.c.

◆ silenceremove_outputs

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

Definition at line 951 of file af_silenceremove.c.

◆ ff_af_silenceremove

const AVFilter ff_af_silenceremove
Initial value:
= {
.name = "silenceremove",
.description = NULL_IF_CONFIG_SMALL("Remove silence."),
.priv_size = sizeof(SilenceRemoveContext),
.priv_class = &silenceremove_class,
.init = init,
}

Definition at line 959 of file af_silenceremove.c.

AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
init
static av_cold int init(AVFilterContext *ctx)
Definition: af_silenceremove.c:411
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_silenceremove.c:895
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:239
silenceremove_inputs
static const AVFilterPad silenceremove_inputs[]
Definition: af_silenceremove.c:942
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_silenceremove.c:598
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:194
NULL
#define NULL
Definition: coverity.c:32
SilenceRemoveContext
Definition: af_silenceremove.c:53
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_silenceremove.c:928
AF
#define AF
Definition: af_silenceremove.c:111
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
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_silenceremove.c:432
D_PEAK
@ D_PEAK
Definition: af_silenceremove.c:36
OFFSET
#define OFFSET(x)
Definition: af_silenceremove.c:110
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:67
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:195
silenceremove_outputs
static const AVFilterPad silenceremove_outputs[]
Definition: af_silenceremove.c:951
T_ALL
@ T_ALL
Definition: af_silenceremove.c:42
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:61
D_RMS
@ D_RMS
Definition: af_silenceremove.c:37
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
T_ANY
@ T_ANY
Definition: af_silenceremove.c:41
FILTER_SAMPLEFMTS
#define FILTER_SAMPLEFMTS(...)
Definition: internal.h:182