FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
af_silenceremove.c File Reference
#include <float.h>
#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "audio.h"
#include "filters.h"
#include "avfilter.h"
#include "silenceremove_template.c"

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
 
#define AFR   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 
#define DEPTH   32
 
#define DEPTH   64
 

Enumerations

enum  SilenceDetect {
  D_AVG, D_RMS, D_PEAK, D_MEDIAN,
  D_PTP, D_DEV, D_NB
}
 
enum  TimestampMode { TS_WRITE, TS_COPY, TS_NB }
 
enum  ThresholdMode { T_ANY, T_ALL }
 

Functions

 AVFILTER_DEFINE_CLASS (silenceremove)
 
static av_cold int init (AVFilterContext *ctx)
 
static void clear_windows (SilenceRemoveContext *s)
 
static int config_input (AVFilterLink *inlink)
 
static int config_output (AVFilterLink *outlink)
 
static int filter_frame (AVFilterLink *outlink, AVFrame *in)
 
static int activate (AVFilterContext *ctx)
 
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 125 of file af_silenceremove.c.

◆ AF

Definition at line 126 of file af_silenceremove.c.

◆ AFR

Definition at line 127 of file af_silenceremove.c.

◆ DEPTH [1/2]

#define DEPTH   32

Definition at line 162 of file af_silenceremove.c.

◆ DEPTH [2/2]

#define DEPTH   64

Definition at line 162 of file af_silenceremove.c.

Enumeration Type Documentation

◆ SilenceDetect

Enumerator
D_AVG 
D_RMS 
D_PEAK 
D_MEDIAN 
D_PTP 
D_DEV 
D_NB 

Definition at line 33 of file af_silenceremove.c.

◆ TimestampMode

Enumerator
TS_WRITE 
TS_COPY 
TS_NB 

Definition at line 43 of file af_silenceremove.c.

◆ ThresholdMode

Enumerator
T_ANY 
T_ALL 

Definition at line 49 of file af_silenceremove.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( silenceremove  )

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 165 of file af_silenceremove.c.

◆ clear_windows()

static void clear_windows ( SilenceRemoveContext s)
static

Definition at line 177 of file af_silenceremove.c.

Referenced by config_output().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 198 of file af_silenceremove.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 223 of file af_silenceremove.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink outlink,
AVFrame in 
)
static

Definition at line 294 of file af_silenceremove.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 416 of file af_silenceremove.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 448 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, AFR },
{ "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, AFR, .unit = "mode" },
{ "any", 0, 0, AV_OPT_TYPE_CONST, {.i64=T_ANY}, 0, 0, AFR, .unit = "mode" },
{ "all", 0, 0, AV_OPT_TYPE_CONST, {.i64=T_ALL}, 0, 0, AFR, .unit = "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 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, AFR },
{ "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_ALL}, T_ANY, T_ALL, AFR, .unit = "mode" },
{ "detection", "set how silence is detected", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=D_RMS}, 0, D_NB-1, AF, .unit = "detection" },
{ "avg", "use mean absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_AVG}, 0, 0, AF, .unit = "detection" },
{ "rms", "use root mean squared values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_RMS}, 0, 0, AF, .unit = "detection" },
{ "peak", "use max absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, .unit = "detection" },
{ "median", "use median of absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_MEDIAN},0, 0, AF, .unit = "detection" },
{ "ptp", "use absolute of max peak to min peak difference", 0, AV_OPT_TYPE_CONST, {.i64=D_PTP}, 0, 0, AF, .unit = "detection" },
{ "dev", "use standard deviation from values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_DEV}, 0, 0, AF, .unit = "detection" },
{ "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF },
{ "timestamp", "set how every output frame timestamp is processed", OFFSET(timestamp_mode), AV_OPT_TYPE_INT, {.i64=TS_WRITE}, 0, TS_NB-1, AF, .unit = "timestamp" },
{ "write", "full timestamps rewrite, keep only the start time", 0, AV_OPT_TYPE_CONST, {.i64=TS_WRITE}, 0, 0, AF, .unit = "timestamp" },
{ "copy", "non-dropped frames are left with same timestamp", 0, AV_OPT_TYPE_CONST, {.i64=TS_COPY}, 0, 0, AF, .unit = "timestamp" },
{ NULL }
}

Definition at line 129 of file af_silenceremove.c.

◆ silenceremove_inputs

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

Definition at line 465 of file af_silenceremove.c.

◆ silenceremove_outputs

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

Definition at line 473 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,
.process_command = ff_filter_process_command,
}

Definition at line 481 of file af_silenceremove.c.

init
static av_cold int init(AVFilterContext *ctx)
Definition: af_silenceremove.c:165
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
TS_COPY
@ TS_COPY
Definition: af_silenceremove.c:45
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
Definition: opt.h:319
silenceremove_inputs
static const AVFilterPad silenceremove_inputs[]
Definition: af_silenceremove.c:465
AFR
#define AFR
Definition: af_silenceremove.c:127
D_DEV
@ D_DEV
Definition: af_silenceremove.c:39
FILTER_SAMPLEFMTS
#define FILTER_SAMPLEFMTS(...)
Definition: filters.h:250
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_silenceremove.c:223
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
NULL
#define NULL
Definition: coverity.c:32
SilenceRemoveContext
Definition: af_silenceremove.c:54
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_silenceremove.c:448
TS_NB
@ TS_NB
Definition: af_silenceremove.c:46
AF
#define AF
Definition: af_silenceremove.c:126
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
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_silenceremove.c:198
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:901
D_NB
@ D_NB
Definition: af_silenceremove.c:40
TS_WRITE
@ TS_WRITE
Definition: af_silenceremove.c:44
D_PEAK
@ D_PEAK
Definition: af_silenceremove.c:36
OFFSET
#define OFFSET(x)
Definition: af_silenceremove.c:125
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
activate
static int activate(AVFilterContext *ctx)
Definition: af_silenceremove.c:416
D_MEDIAN
@ D_MEDIAN
Definition: af_silenceremove.c:37
D_AVG
@ D_AVG
Definition: af_silenceremove.c:34
silenceremove_outputs
static const AVFilterPad silenceremove_outputs[]
Definition: af_silenceremove.c:473
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:190
T_ALL
@ T_ALL
Definition: af_silenceremove.c:51
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:61
D_RMS
@ D_RMS
Definition: af_silenceremove.c:35
D_PTP
@ D_PTP
Definition: af_silenceremove.c:38
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
T_ANY
@ T_ANY
Definition: af_silenceremove.c:50