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 "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)
 
#define SILENCE_DETECT_PLANAR(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 av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption silencedetect_options []
 
static const AVFilterPad silencedetect_inputs []
 
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 52 of file af_silencedetect.c.

◆ 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.

◆ SILENCE_DETECT_PLANAR

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

Definition at line 133 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 162 of file af_silencedetect.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame insamples 
)
static

Definition at line 209 of file af_silencedetect.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 234 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 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,
},
}

Definition at line 246 of file af_silencedetect.c.

◆ ff_af_silencedetect

const AVFilter ff_af_silencedetect
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
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
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
Definition: af_silencedetect.c:209
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
silencedetect_inputs
static const AVFilterPad silencedetect_inputs[]
Definition: af_silencedetect.c:246
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:239
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_silencedetect.c:234
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:64
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
channels
channels
Definition: aptx.h:31
MAX_DURATION
#define MAX_DURATION
Definition: af_silencedetect.c:52
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:192
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ff_audio_default_filterpad
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
Definition: audio.c:32
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:106
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
OFFSET
#define OFFSET(x)
Definition: af_silencedetect.c:53
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
FLAGS
#define FLAGS
Definition: af_silencedetect.c:54
SilenceDetectContext
Definition: af_silencedetect.c:34
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
noise
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition: noise_bsf.c:126
AVFILTER_FLAG_METADATA_ONLY
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition: avfilter.h:133
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:67
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_silencedetect.c:162
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:61
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
FILTER_SAMPLEFMTS
#define FILTER_SAMPLEFMTS(...)
Definition: internal.h:180