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)
 
#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 []
 
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.

◆ 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 134 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 163 of file af_silencedetect.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame insamples 
)
static

Definition at line 210 of file af_silencedetect.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

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

Definition at line 247 of file af_silencedetect.c.

◆ silencedetect_outputs

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

Definition at line 256 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
silencedetect_outputs
static const AVFilterPad silencedetect_outputs[]
Definition: af_silencedetect.c:256
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
Definition: af_silencedetect.c:210
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
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:247
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:239
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_silencedetect.c:235
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
duration
int64_t duration
Definition: movenc.c:64
s
#define s(width, name)
Definition: cbs_vp9.c:256
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:53
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
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
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
OFFSET
#define OFFSET(x)
Definition: af_silencedetect.c:54
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:269
FLAGS
#define FLAGS
Definition: af_silencedetect.c:55
SilenceDetectContext
Definition: af_silencedetect.c:35
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:120
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:143
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:163
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
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:178