Go to the documentation of this file.
125 #define OFFSET(x) offsetof(SilenceRemoveContext, x)
126 #define AF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
127 #define AFR AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
130 {
"start_periods",
"set periods of silence parts to skip from start",
OFFSET(start_periods),
AV_OPT_TYPE_INT, {.i64=0}, 0, 9000,
AF },
131 {
"start_duration",
"set start duration of non-silence part",
OFFSET(start_duration_opt),
AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX,
AF },
132 {
"start_threshold",
"set threshold for start silence detection",
OFFSET(start_threshold),
AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX,
AFR },
133 {
"start_silence",
"set start duration of silence part to keep",
OFFSET(start_silence_opt),
AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX,
AF },
137 {
"stop_periods",
"set periods of silence parts to skip from end",
OFFSET(stop_periods),
AV_OPT_TYPE_INT, {.i64=0}, -9000, 9000,
AF },
139 {
"stop_threshold",
"set threshold for stop silence detection",
OFFSET(stop_threshold),
AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX,
AFR },
140 {
"stop_silence",
"set stop duration of silence part to keep",
OFFSET(stop_silence_opt),
AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX,
AF },
143 {
"avg",
"use mean absolute values of samples", 0,
AV_OPT_TYPE_CONST, {.i64=
D_AVG}, 0, 0,
AF, .unit =
"detection" },
144 {
"rms",
"use root mean squared values of samples", 0,
AV_OPT_TYPE_CONST, {.i64=
D_RMS}, 0, 0,
AF, .unit =
"detection" },
147 {
"ptp",
"use absolute of max peak to min peak difference", 0,
AV_OPT_TYPE_CONST, {.i64=
D_PTP}, 0, 0,
AF, .unit =
"detection" },
148 {
"dev",
"use standard deviation from values of samples", 0,
AV_OPT_TYPE_CONST, {.i64=
D_DEV}, 0, 0,
AF, .unit =
"detection" },
149 {
"window",
"set duration of window for silence detection",
OFFSET(window_duration_opt),
AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000,
AF },
151 {
"write",
"full timestamps rewrite, keep only the start time", 0,
AV_OPT_TYPE_CONST, {.i64=
TS_WRITE}, 0, 0,
AF, .unit =
"timestamp" },
152 {
"copy",
"non-dropped frames are left with same timestamp", 0,
AV_OPT_TYPE_CONST, {.i64=
TS_COPY}, 0, 0,
AF, .unit =
"timestamp" },
169 if (
s->stop_periods < 0) {
170 s->stop_periods = -
s->stop_periods;
180 s->start_window->nb_samples,
181 s->start_window->ch_layout.nb_channels,
182 s->start_window->format);
184 s->stop_window->nb_samples,
185 s->stop_window->ch_layout.nb_channels,
186 s->stop_window->format);
188 s->start_window_pos = 0;
189 s->start_window_size = 0;
190 s->stop_window_pos = 0;
191 s->stop_window_size = 0;
192 s->start_queue_pos = 0;
193 s->start_queue_size = 0;
194 s->stop_queue_pos = 0;
195 s->stop_queue_size = 0;
206 s->window_duration =
FFMAX(1,
s->window_duration);
217 s->start_found_periods = 0;
218 s->stop_found_periods = 0;
228 switch (
s->detection) {
239 s->cache_size =
s->window_duration;
247 if (!
s->start_window || !
s->stop_window || !
s->start_cache || !
s->stop_cache)
252 if (!
s->start_queuef || !
s->stop_queuef)
259 if (!
s->start_front || !
s->start_back || !
s->stop_front || !
s->stop_back)
264 switch (
s->detection) {
266 s->compute_flt = compute_avg_flt;
267 s->compute_dbl = compute_avg_dbl;
270 s->compute_flt = compute_dev_flt;
271 s->compute_dbl = compute_dev_dbl;
274 s->compute_flt = compute_ptp_flt;
275 s->compute_dbl = compute_ptp_dbl;
278 s->compute_flt = compute_median_flt;
279 s->compute_dbl = compute_median_dbl;
282 s->compute_flt = compute_peak_flt;
283 s->compute_dbl = compute_peak_dbl;
286 s->compute_flt = compute_rms_flt;
287 s->compute_dbl = compute_rms_dbl;
299 int max_out_nb_samples;
300 int out_nb_samples = 0;
309 s->next_pts = in->
pts;
315 if (max_out_nb_samples <= 0) {
328 out->pts =
s->next_pts;
332 switch (outlink->
format) {
334 srcf = (
const float *)in->
data[0];
335 dstf = (
float *)
out->data[0];
336 if (
s->start_periods > 0 &&
s->stop_periods > 0) {
337 const float *
src = srcf;
338 if (
s->start_found_periods >= 0) {
339 for (
int n = 0; n < in_nb_samples; n++) {
340 filter_start_flt(
ctx,
src + n * nb_channels,
341 dstf, &out_nb_samples,
344 in_nb_samples = out_nb_samples;
348 for (
int n = 0; n < in_nb_samples; n++) {
349 filter_stop_flt(
ctx,
src + n * nb_channels,
350 dstf, &out_nb_samples,
353 }
else if (
s->start_periods > 0) {
354 for (
int n = 0; n < in_nb_samples; n++) {
355 filter_start_flt(
ctx, srcf + n * nb_channels,
356 dstf, &out_nb_samples,
359 }
else if (
s->stop_periods > 0) {
360 for (
int n = 0; n < in_nb_samples; n++) {
361 filter_stop_flt(
ctx, srcf + n * nb_channels,
362 dstf, &out_nb_samples,
368 srcd = (
const double *)in->
data[0];
369 dstd = (
double *)
out->data[0];
370 if (
s->start_periods > 0 &&
s->stop_periods > 0) {
371 const double *
src = srcd;
372 if (
s->start_found_periods >= 0) {
373 for (
int n = 0; n < in_nb_samples; n++) {
374 filter_start_dbl(
ctx,
src + n * nb_channels,
375 dstd, &out_nb_samples,
378 in_nb_samples = out_nb_samples;
382 for (
int n = 0; n < in_nb_samples; n++) {
383 filter_stop_dbl(
ctx,
src + n * nb_channels,
384 dstd, &out_nb_samples,
387 }
else if (
s->start_periods > 0) {
388 for (
int n = 0; n < in_nb_samples; n++) {
389 filter_start_dbl(
ctx, srcd + n * nb_channels,
390 dstd, &out_nb_samples,
393 }
else if (
s->stop_periods > 0) {
394 for (
int n = 0; n < in_nb_samples; n++) {
395 filter_stop_dbl(
ctx, srcd + n * nb_channels,
396 dstd, &out_nb_samples,
404 if (out_nb_samples > 0) {
405 s->next_pts += out_nb_samples;
406 out->nb_samples = out_nb_samples;
430 if (
s->start_periods == 1 &&
s->stop_periods == 0 &&
431 s->start_found_periods < 0) {
433 in->
pts =
s->next_pts;
437 if (
s->start_periods == 0 &&
s->stop_periods == 0)
482 .
name =
"silenceremove",
485 .priv_class = &silenceremove_class,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
float(* compute_flt)(float *c, float s, float ws, int size, int *front, int *back)
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static av_cold int init(AVFilterContext *ctx)
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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).
static void clear_windows(SilenceRemoveContext *s)
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
static const AVFilterPad silenceremove_inputs[]
int64_t start_duration_opt
const char * name
Filter name.
int64_t start_silence_opt
int nb_channels
Number of channels in this layout.
A link between two filters.
AVFILTER_DEFINE_CLASS(silenceremove)
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
A filter pad used for either input or output.
static int config_output(AVFilterLink *outlink)
#define FILTER_INPUTS(array)
static int filter_frame(AVFilterLink *outlink, AVFrame *in)
Describe the class of an AVClass context structure.
static const AVOption silenceremove_options[]
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
static av_cold void uninit(AVFilterContext *ctx)
double(* compute_dbl)(double *c, double s, double ws, int size, int *front, int *back)
int64_t window_duration_opt
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int config_input(AVFilterLink *inlink)
int format
agreed upon media format
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
FF_FILTER_FORWARD_WANTED(outlink, inlink)
int nb_samples
number of audio samples (per channel) described by this frame
const AVFilter ff_af_silenceremove
#define AV_TIME_BASE
Internal time base represented as integer.
const char * name
Pad name.
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)
static int activate(AVFilterContext *ctx)
int64_t stop_duration_opt
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
FF_FILTER_FORWARD_STATUS(inlink, outlink)
#define FILTER_OUTPUTS(array)
static const AVFilterPad silenceremove_outputs[]
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
@ AV_SAMPLE_FMT_DBL
double
#define FILTER_SAMPLEFMTS(...)
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.