FFmpeg
Data Structures | Macros | Functions | Variables
af_silencedetect.c File Reference
#include <float.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  SilenceDetectContext
 

Macros

#define MAX_DURATION   (24*3600*1000000LL)
 
#define OFFSET(x)   offsetof(SilenceDetectContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
 
#define SILENCE_DETECT(name, type)
 

Functions

 AVFILTER_DEFINE_CLASS (silencedetect)
 
static void set_meta (AVFrame *insamples, int channel, const char *key, char *value)
 
static av_always_inline void update (SilenceDetectContext *s, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
 
static int config_input (AVFilterLink *inlink)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *insamples)
 
static int query_formats (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption silencedetect_options []
 
static const AVFilterPad silencedetect_inputs []
 
static const AVFilterPad silencedetect_outputs []
 
const AVFilter ff_af_silencedetect
 

Detailed Description

Audio silence detector

Definition in file af_silencedetect.c.

Macro Definition Documentation

◆ MAX_DURATION

#define MAX_DURATION   (24*3600*1000000LL)

Definition at line 53 of file af_silencedetect.c.

◆ OFFSET

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

Definition at line 54 of file af_silencedetect.c.

◆ FLAGS

Definition at line 55 of file af_silencedetect.c.

◆ SILENCE_DETECT

#define SILENCE_DETECT (   name,
  type 
)
Value:
static void silencedetect_##name(SilenceDetectContext *s, AVFrame *insamples, \
int nb_samples, int64_t nb_samples_notify, \
AVRational time_base) \
{ \
const type *p = (const type *)insamples->data[0]; \
const type noise = s->noise; \
int i; \
\
for (i = 0; i < nb_samples; i++, p++) \
update(s, insamples, *p < noise && *p > -noise, i, \
nb_samples_notify, time_base); \
}

Definition at line 120 of file af_silencedetect.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( silencedetect  )

◆ set_meta()

static void set_meta ( AVFrame insamples,
int  channel,
const char *  key,
char *  value 
)
static

Definition at line 68 of file af_silencedetect.c.

Referenced by update().

◆ update()

static av_always_inline void update ( SilenceDetectContext s,
AVFrame insamples,
int  is_silence,
int  current_sample,
int64_t  nb_samples_notify,
AVRational  time_base 
)
static

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 139 of file af_silencedetect.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame insamples 
)
static

Definition at line 173 of file af_silencedetect.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 198 of file af_silencedetect.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 231 of file af_silencedetect.c.

Variable Documentation

◆ silencedetect_options

const AVOption silencedetect_options[]
static
Initial value:
= {
{ "n", "set noise tolerance", OFFSET(noise), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0, DBL_MAX, FLAGS },
{ "noise", "set noise tolerance", OFFSET(noise), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0, DBL_MAX, FLAGS },
{ "d", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=2000000}, 0, MAX_DURATION,FLAGS },
{ "duration", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=2000000}, 0, MAX_DURATION,FLAGS },
{ "mono", "check each channel separately", OFFSET(mono), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
{ "m", "check each channel separately", OFFSET(mono), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
{ NULL }
}

Definition at line 56 of file af_silencedetect.c.

◆ silencedetect_inputs

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

Definition at line 243 of file af_silencedetect.c.

◆ silencedetect_outputs

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

Definition at line 253 of file af_silencedetect.c.

◆ ff_af_silencedetect

const AVFilter ff_af_silencedetect
Initial value:
= {
.name = "silencedetect",
.description = NULL_IF_CONFIG_SMALL("Detect silence."),
.priv_size = sizeof(SilenceDetectContext),
.priv_class = &silencedetect_class,
}

Definition at line 261 of file af_silencedetect.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
silencedetect_outputs
static const AVFilterPad silencedetect_outputs[]
Definition: af_silencedetect.c:253
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
Definition: af_silencedetect.c:173
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
silencedetect_inputs
static const AVFilterPad silencedetect_inputs[]
Definition: af_silencedetect.c:243
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:238
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_silencedetect.c:231
type
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 type
Definition: writing_filters.txt:86
update
static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
Definition: af_silencedetect.c:78
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
duration
int64_t duration
Definition: movenc.c:64
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:226
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
MAX_DURATION
#define MAX_DURATION
Definition: af_silencedetect.c:53
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_silencedetect.c:198
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
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:116
OFFSET
#define OFFSET(x)
Definition: af_silencedetect.c:54
i
int i
Definition: input.c:406
FLAGS
#define FLAGS
Definition: af_silencedetect.c:55
SilenceDetectContext
Definition: af_silencedetect.c:35
noise
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition: noise_bsf.c:121
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_silencedetect.c:139
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241