Go to the documentation of this file.
48 int nb_samples, int64_t nb_samples_notify,
52 #define MAX_DURATION (24*3600*1000000LL)
53 #define OFFSET(x) offsetof(SilenceDetectContext, x)
54 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
78 int is_silence,
int current_sample, int64_t nb_samples_notify,
81 int channel = current_sample %
s->independent_channels;
83 if (
s->start[
channel] == INT64_MIN) {
85 if (
s->nb_null_samples[
channel] >= nb_samples_notify) {
86 s->start[
channel] = insamples->
pts +
av_rescale_q(current_sample /
s->channels + 1 - nb_samples_notify *
s->independent_channels /
s->channels,
98 int64_t end_pts = insamples ? insamples->
pts +
av_rescale_q(current_sample /
s->channels,
101 int64_t duration_ts = end_pts -
s->start[
channel];
119 #define SILENCE_DETECT(name, type) \
120 static void silencedetect_##name(SilenceDetectContext *s, AVFrame *insamples, \
121 int nb_samples, int64_t nb_samples_notify, \
122 AVRational time_base) \
124 const type *p = (const type *)insamples->data[0]; \
125 const type noise = s->noise; \
128 for (i = 0; i < nb_samples; i++, p++) \
129 update(s, insamples, *p < noise && *p > -noise, i, \
130 nb_samples_notify, time_base); \
133 #define SILENCE_DETECT_PLANAR(name, type) \
134 static void silencedetect_##name(SilenceDetectContext *s, AVFrame *insamples, \
135 int nb_samples, int64_t nb_samples_notify, \
136 AVRational time_base) \
138 const int channels = insamples->ch_layout.nb_channels; \
139 const type noise = s->noise; \
141 nb_samples /= channels; \
142 for (int i = 0; i < nb_samples; i++) { \
143 for (int ch = 0; ch < insamples->ch_layout.nb_channels; ch++) { \
144 const type *p = (const type *)insamples->extended_data[ch]; \
145 update(s, insamples, p[i] < noise && p[i] > -noise, \
147 nb_samples_notify, time_base); \
168 s->channels =
inlink->ch_layout.nb_channels;
170 s->independent_channels =
s->mono ?
s->channels : 1;
171 s->nb_null_samples =
av_calloc(
s->independent_channels,
172 sizeof(*
s->nb_null_samples));
173 if (!
s->nb_null_samples)
178 for (
c = 0;
c <
s->independent_channels;
c++)
179 s->start[
c] = INT64_MIN;
185 s->noise *= INT32_MAX;
186 s->silencedetect = silencedetect_s32;
189 s->noise *= INT16_MAX;
190 s->silencedetect = silencedetect_s16;
195 s->noise *= INT32_MAX;
196 s->silencedetect = silencedetect_s32p;
199 s->noise *= INT16_MAX;
200 s->silencedetect = silencedetect_s16p;
212 const int nb_channels =
inlink->ch_layout.nb_channels;
213 const int srate =
inlink->sample_rate;
214 const int nb_samples = insamples->
nb_samples * nb_channels;
215 const int64_t nb_samples_notify =
s->duration * (
s->mono ? 1 : nb_channels);
219 if (
s->last_sample_rate &&
s->last_sample_rate != srate)
220 for (
c = 0;
c <
s->independent_channels;
c++) {
221 s->nb_null_samples[
c] = srate *
s->nb_null_samples[
c] /
s->last_sample_rate;
223 s->last_sample_rate = srate;
224 s->time_base =
inlink->time_base;
228 s->silencedetect(
s, insamples, nb_samples, nb_samples_notify,
239 for (
c = 0;
c <
s->independent_channels;
c++)
240 if (
s->start[
c] > INT64_MIN)
256 .
name =
"silencedetect",
266 .priv_class = &silencedetect_class,
@ AV_SAMPLE_FMT_FLTP
float, planar
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define SILENCE_DETECT(name, type)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
double noise
noise amplitude ratio
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int64_t frame_end
pts of the end of the current frame (used to compute duration of silence at EOS)
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
static const AVFilterPad silencedetect_inputs[]
const char * name
Filter name.
A link between two filters.
static av_cold void uninit(AVFilterContext *ctx)
static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int mono
mono mode : check each channel separately (default = check when ALL channels are silent)
#define FILTER_INPUTS(array)
int channels
number of channels
Describe the class of an AVClass context structure.
int64_t * start
(array) if silence is detected, this value contains the time of the first zero sample (default/unset ...
Rational number (pair of numerator and denominator).
const AVFilter ff_af_silencedetect
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
#define SILENCE_DETECT_PLANAR(name, type)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
AVRational time_base
time_base
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static void set_meta(AVFrame *insamples, int channel, const char *key, char *value)
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
#define AV_LOG_INFO
Standard information.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_TIME_BASE
Internal time base represented as integer.
#define av_malloc_array(a, b)
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 value
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Pad name.
static const AVOption silencedetect_options[]
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void * av_calloc(size_t nmemb, size_t size)
int64_t duration
minimum duration of silence until notification
int independent_channels
number of entries in following arrays (always 1 in mono mode)
AVFILTER_DEFINE_CLASS(silencedetect)
static int noise(AVBSFContext *ctx, AVPacket *pkt)
AVDictionary * metadata
metadata.
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
@ AV_SAMPLE_FMT_DBLP
double, planar
static int config_input(AVFilterLink *inlink)
void(* silencedetect)(struct SilenceDetectContext *s, AVFrame *insamples, int nb_samples, int64_t nb_samples_notify, AVRational time_base)
#define FILTER_OUTPUTS(array)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int64_t * nb_null_samples
(array) current number of continuous zero samples
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int last_sample_rate
last sample rate to check for sample rate changes
@ AV_SAMPLE_FMT_DBL
double
@ AV_SAMPLE_FMT_S32
signed 32 bits
#define FILTER_SAMPLEFMTS(...)