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,
82 int channel = current_sample %
s->independent_channels;
84 if (
s->start[
channel] == INT64_MIN) {
86 if (
s->nb_null_samples[
channel] >= nb_samples_notify) {
87 s->start[
channel] = insamples->
pts +
av_rescale_q(current_sample /
s->channels + 1 - nb_samples_notify *
s->independent_channels /
s->channels,
120 #define SILENCE_DETECT(name, type) \
121 static void silencedetect_##name(SilenceDetectContext *s, AVFrame *insamples, \
122 int nb_samples, int64_t nb_samples_notify, \
123 AVRational time_base) \
125 const type *p = (const type *)insamples->data[0]; \
126 const type noise = s->noise; \
129 for (i = 0; i < nb_samples; i++, p++) \
130 update(s, insamples, *p < noise && *p > -noise, i, \
131 nb_samples_notify, time_base); \
145 s->channels = inlink->channels;
147 s->independent_channels =
s->mono ?
s->channels : 1;
148 s->nb_null_samples =
av_mallocz_array(
sizeof(*
s->nb_null_samples),
s->independent_channels);
149 if (!
s->nb_null_samples)
154 for (
c = 0;
c <
s->independent_channels;
c++)
155 s->start[
c] = INT64_MIN;
157 switch (inlink->format) {
161 s->noise *= INT32_MAX;
162 s->silencedetect = silencedetect_s32;
165 s->noise *= INT16_MAX;
166 s->silencedetect = silencedetect_s16;
183 if (
s->last_sample_rate &&
s->last_sample_rate != srate)
184 for (
c = 0;
c <
s->independent_channels;
c++) {
185 s->nb_null_samples[
c] = srate *
s->nb_null_samples[
c] /
s->last_sample_rate;
187 s->last_sample_rate = srate;
192 s->silencedetect(
s, insamples, nb_samples, nb_samples_notify,
236 for (
c = 0;
c <
s->independent_channels;
c++)
237 if (
s->start[
c] > INT64_MIN)
262 .
name =
"silencedetect",
269 .priv_class = &silencedetect_class,
static enum AVSampleFormat sample_fmts[]
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
AVFILTER_DEFINE_CLASS(silencedetect)
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
static int query_formats(AVFilterContext *ctx)
static void set_meta(AVFrame *insamples, int channel, const char *key, char *value)
static int config_input(AVFilterLink *inlink)
static const AVFilterPad silencedetect_outputs[]
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption silencedetect_options[]
#define SILENCE_DETECT(name, type)
static const AVFilterPad silencedetect_inputs[]
static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
AVFilter ff_af_silencedetect
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
channel
Use these values when setting the channel map with ebur128_set_channel().
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 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.
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_DBL
double
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define AV_TIME_BASE
Internal time base represented as integer.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
enum MovChannelLayoutTag * layouts
static int noise(AVBSFContext *ctx, AVPacket *pkt)
typedef void(RENAME(mix_any_func_type))
Describe the class of an AVClass context structure.
A list of supported channel layouts.
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int channels
Number of channels.
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
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
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)
void(* silencedetect)(struct SilenceDetectContext *s, AVFrame *insamples, int nb_samples, int64_t nb_samples_notify, AVRational time_base)
int last_sample_rate
last sample rate to check for sample rate changes
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)
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...