49 int nb_samples,
int64_t nb_samples_notify,
53#define MAX_DURATION (24*3600*1000000LL)
54#define OFFSET(x) offsetof(SilenceDetectContext, x)
55#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
79 int is_silence,
int current_sample,
int64_t nb_samples_notify,
83 int channel = current_sample %
s->independent_channels;
85 if (
s->start[
channel] == INT64_MIN) {
87 if (
s->nb_null_samples[
channel] >= nb_samples_notify) {
88 s->start[
channel] = insamples->
pts +
av_rescale_q(current_sample /
s->channels + 1 - nb_samples_notify *
s->independent_channels /
s->channels,
89 (
AVRational){ 1, s->last_sample_rate }, time_base);
101 (
AVRational){ 1, s->last_sample_rate }, time_base)
121#define SILENCE_DETECT(name, type) \
122static void silencedetect_##name(AVFilterContext *ctx, AVFrame *insamples, \
123 int nb_samples, int64_t nb_samples_notify, \
124 AVRational time_base) \
126 SilenceDetectContext *s = ctx->priv; \
127 const type *p = (const type *)insamples->data[0]; \
128 const type noise = s->noise; \
131 for (i = 0; i < nb_samples; i++, p++) \
132 update(ctx, insamples, *p < noise && *p > -noise, i, \
133 nb_samples_notify, time_base); \
136#define SILENCE_DETECT_PLANAR(name, type) \
137static void silencedetect_##name(AVFilterContext *ctx, AVFrame *insamples, \
138 int nb_samples, int64_t nb_samples_notify, \
139 AVRational time_base) \
141 SilenceDetectContext *s = ctx->priv; \
142 const int channels = insamples->ch_layout.nb_channels; \
143 const type noise = s->noise; \
145 nb_samples /= channels; \
146 for (int i = 0; i < nb_samples; i++) { \
147 for (int ch = 0; ch < insamples->ch_layout.nb_channels; ch++) { \
148 const type *p = (const type *)insamples->extended_data[ch]; \
149 update(ctx, insamples, p[i] < noise && p[i] > -noise, \
151 nb_samples_notify, time_base); \
172 s->channels = inlink->ch_layout.nb_channels;
174 s->independent_channels =
s->mono ?
s->channels : 1;
175 s->nb_null_samples =
av_calloc(
s->independent_channels,
176 sizeof(*
s->nb_null_samples));
177 if (!
s->nb_null_samples)
182 for (
c = 0;
c <
s->independent_channels;
c++)
183 s->start[
c] = INT64_MIN;
185 switch (inlink->format) {
189 s->noise *= INT32_MAX;
190 s->silencedetect = silencedetect_s32;
193 s->noise *= INT16_MAX;
194 s->silencedetect = silencedetect_s16;
199 s->noise *= INT32_MAX;
200 s->silencedetect = silencedetect_s32p;
203 s->noise *= INT16_MAX;
204 s->silencedetect = silencedetect_s16p;
219 const int nb_samples = insamples->
nb_samples * nb_channels;
220 const int64_t nb_samples_notify =
s->duration * (
s->mono ? 1 : nb_channels);
224 if (
s->last_sample_rate &&
s->last_sample_rate != srate)
225 for (
c = 0;
c <
s->independent_channels;
c++) {
226 s->nb_null_samples[
c] = srate *
s->nb_null_samples[
c] /
s->last_sample_rate;
228 s->last_sample_rate = srate;
233 s->silencedetect(
ctx, insamples, nb_samples, nb_samples_notify,
244 for (
c = 0;
c <
s->independent_channels;
c++)
245 if (
s->start[
c] > INT64_MIN)
261 .p.name =
"silencedetect",
263 .p.priv_class = &silencedetect_class,
static int config_input(AVFilterLink *inlink)
const FFFilter ff_af_silencedetect
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
static av_always_inline void update(AVFilterContext *ctx, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
#define SILENCE_DETECT_PLANAR(name, type)
static void set_meta(AVFrame *insamples, int channel, const char *key, char *value)
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption silencedetect_options[]
#define SILENCE_DETECT(name, type)
static const AVFilterPad silencedetect_inputs[]
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
channel
Use these values when setting the channel map with ebur128_set_channel().
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AV_LOG_INFO
Standard information.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_SAMPLE_FMT_FLTP
float, planar
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_DBLP
double, planar
@ AV_SAMPLE_FMT_DBL
double
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define AV_TIME_BASE
Internal time base represented as integer.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_SAMPLEFMTS(...)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static int noise(AVBSFContext *ctx, AVPacket *pkt)
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int sample_rate
samples per second
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVDictionary * metadata
metadata.
Rational number (pair of numerator and denominator).
int64_t duration
minimum duration of silence until notification
AVRational time_base
time_base
int channels
number of channels
int64_t frame_end
pts of the end of the current frame (used to compute duration of silence at EOS)
int64_t * start
(array) if silence is detected, this value contains the time of the first zero sample (default/unset ...
int mono
mono mode : check each channel separately (default = check when ALL channels are silent)
int last_sample_rate
last sample rate to check for sample rate changes
void(* silencedetect)(AVFilterContext *ctx, AVFrame *insamples, int nb_samples, int64_t nb_samples_notify, AVRational time_base)
int64_t * nb_null_samples
(array) current number of continuous zero samples
double noise
noise amplitude ratio
int independent_channels
number of entries in following arrays (always 1 in mono mode)
#define av_malloc_array(a, b)
static AVFormatContext * ctx
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...