49 int nb_samples, int64_t nb_samples_notify,
53 #define OFFSET(x) offsetof(SilenceDetectContext, x) 54 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM 71 snprintf(key2,
sizeof(key2),
"lavfi.%s.%d", key, channel);
73 snprintf(key2,
sizeof(key2),
"lavfi.%s", key);
77 int is_silence,
int current_sample, int64_t nb_samples_notify,
82 if (s->
start[channel] == INT64_MIN) {
86 (
AVRational){ 1, s->last_sample_rate }, time_base);
87 set_meta(insamples, s->
mono ? channel + 1 : 0,
"silence_start",
96 if (s->
start[channel] > INT64_MIN) {
98 (
AVRational){ 1, s->last_sample_rate }, time_base)
102 set_meta(insamples, s->
mono ? channel + 1 : 0,
"silence_end",
104 set_meta(insamples, s->
mono ? channel + 1 : 0,
"silence_duration",
118 #define SILENCE_DETECT(name, type) \ 119 static void silencedetect_##name(SilenceDetectContext *s, AVFrame *insamples, \ 120 int nb_samples, int64_t nb_samples_notify, \ 121 AVRational time_base) \ 123 const type *p = (const type *)insamples->data[0]; \ 124 const type noise = s->noise; \ 127 for (i = 0; i < nb_samples; i++, p++) \ 128 update(s, insamples, *p < noise && *p > -noise, i, \ 129 nb_samples_notify, time_base); \ 152 s->
start[c] = INT64_MIN;
154 switch (inlink->format) {
158 s->
noise *= INT32_MAX;
162 s->
noise *= INT16_MAX;
190 s->
silencedetect(s, insamples, nb_samples, nb_samples_notify,
235 if (s->
start[c] > INT64_MIN)
260 .
name =
"silencedetect",
265 .
inputs = silencedetect_inputs,
266 .
outputs = silencedetect_outputs,
267 .priv_class = &silencedetect_class,
This structure describes decoded (raw) audio or video data.
Main libavfilter public API header.
int64_t frame_end
pts of the end of the current frame (used to compute duration of silence at EOS)
#define SILENCE_DETECT(name, type)
AVFilter ff_af_silencedetect
const char * name
Pad name.
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
timestamp utils, mostly useful for debugging/logging purposes
static const AVFilterPad silencedetect_inputs[]
double duration
minimum duration of silence until notification
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVDictionary * metadata
metadata.
A filter pad used for either input or output.
AVRational time_base
time_base
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
int sample_rate
samples per second
static const AVFilterPad silencedetect_outputs[]
static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational 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. ...
void * priv
private data for use by the filter
int independant_channels
number of entries in following arrays (always 1 in mono mode)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
double noise
noise amplitude ratio
static int config_input(AVFilterLink *inlink)
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
A list of supported channel layouts.
int channels
number of channels
void(* silencedetect)(struct SilenceDetectContext *s, AVFrame *insamples, int nb_samples, int64_t nb_samples_notify, AVRational time_base)
#define AV_LOG_INFO
Standard information.
int64_t * nb_null_samples
(array) current number of continuous zero samples
AVSampleFormat
Audio sample formats.
typedef void(RENAME(mix_any_func_type))
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
AVFILTER_DEFINE_CLASS(silencedetect)
int mono
mono mode : check each channel separately (default = check when ALL channels are silent) ...
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
static int query_formats(AVFilterContext *ctx)
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
channel
Use these values when setting the channel map with ebur128_set_channel().
int channels
Number of channels.
static const AVOption silencedetect_options[]
AVFilterContext * dst
dest filter
static av_cold void uninit(AVFilterContext *ctx)
static enum AVSampleFormat sample_fmts[]
static void set_meta(AVFrame *insamples, int channel, const char *key, char *value)
#define av_malloc_array(a, b)
int last_sample_rate
last sample rate to check for sample rate changes
int nb_samples
number of audio samples (per channel) described by this frame
int64_t * start
(array) if silence is detected, this value contains the time of the first zero sample (default/unset ...
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().