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 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 []
 
AVFilter ff_af_silencedetect
 

Detailed Description

Audio silence detector

Definition in file af_silencedetect.c.

Macro Definition Documentation

◆ OFFSET

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

Definition at line 53 of file af_silencedetect.c.

◆ FLAGS

Definition at line 54 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 119 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 67 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 138 of file af_silencedetect.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame insamples 
)
static

Definition at line 171 of file af_silencedetect.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 197 of file af_silencedetect.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 230 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_DOUBLE, {.dbl=2.}, 0, 24*60*60, FLAGS },
{ "duration", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DOUBLE, {.dbl=2.}, 0, 24*60*60, 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 55 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 242 of file af_silencedetect.c.

◆ silencedetect_outputs

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

Definition at line 252 of file af_silencedetect.c.

◆ ff_af_silencedetect

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 260 of file af_silencedetect.c.

silencedetect_outputs
static const AVFilterPad silencedetect_outputs[]
Definition: af_silencedetect.c:252
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
Definition: af_silencedetect.c:171
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
name
const char * name
Definition: avisynth_c.h:867
silencedetect_inputs
static const AVFilterPad silencedetect_inputs[]
Definition: af_silencedetect.c:242
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_silencedetect.c:230
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:77
duration
int64_t duration
Definition: movenc.c:63
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:225
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_silencedetect.c:197
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
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
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:188
OFFSET
#define OFFSET(x)
Definition: af_silencedetect.c:53
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
FLAGS
#define FLAGS
Definition: af_silencedetect.c:54
SilenceDetectContext
Definition: af_silencedetect.c:35
noise
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition: noise_bsf.c:38
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_silencedetect.c:138
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240