Go to the documentation of this file.
126 #define OFFSET(x) offsetof(SilenceRemoveContext, x)
127 #define AF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
128 #define AFR AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
131 {
"start_periods",
"set periods of silence parts to skip from start",
OFFSET(start_periods),
AV_OPT_TYPE_INT, {.i64=0}, 0, 9000,
AF },
132 {
"start_duration",
"set start duration of non-silence part",
OFFSET(start_duration_opt),
AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX,
AF },
133 {
"start_threshold",
"set threshold for start silence detection",
OFFSET(start_threshold),
AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX,
AFR },
134 {
"start_silence",
"set start duration of silence part to keep",
OFFSET(start_silence_opt),
AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX,
AF },
138 {
"stop_periods",
"set periods of silence parts to skip from end",
OFFSET(stop_periods),
AV_OPT_TYPE_INT, {.i64=0}, -9000, 9000,
AF },
140 {
"stop_threshold",
"set threshold for stop silence detection",
OFFSET(stop_threshold),
AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX,
AFR },
141 {
"stop_silence",
"set stop duration of silence part to keep",
OFFSET(stop_silence_opt),
AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX,
AF },
144 {
"avg",
"use mean absolute values of samples", 0,
AV_OPT_TYPE_CONST, {.i64=
D_AVG}, 0, 0,
AF, .unit =
"detection" },
145 {
"rms",
"use root mean squared values of samples", 0,
AV_OPT_TYPE_CONST, {.i64=
D_RMS}, 0, 0,
AF, .unit =
"detection" },
148 {
"ptp",
"use absolute of max peak to min peak difference", 0,
AV_OPT_TYPE_CONST, {.i64=
D_PTP}, 0, 0,
AF, .unit =
"detection" },
149 {
"dev",
"use standard deviation from values of samples", 0,
AV_OPT_TYPE_CONST, {.i64=
D_DEV}, 0, 0,
AF, .unit =
"detection" },
150 {
"window",
"set duration of window for silence detection",
OFFSET(window_duration_opt),
AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000,
AF },
152 {
"write",
"full timestamps rewrite, keep only the start time", 0,
AV_OPT_TYPE_CONST, {.i64=
TS_WRITE}, 0, 0,
AF, .unit =
"timestamp" },
153 {
"copy",
"non-dropped frames are left with same timestamp", 0,
AV_OPT_TYPE_CONST, {.i64=
TS_COPY}, 0, 0,
AF, .unit =
"timestamp" },
170 if (
s->stop_periods < 0) {
171 s->stop_periods = -
s->stop_periods;
181 s->start_window->nb_samples,
182 s->start_window->ch_layout.nb_channels,
183 s->start_window->format);
185 s->stop_window->nb_samples,
186 s->stop_window->ch_layout.nb_channels,
187 s->stop_window->format);
189 s->start_window_pos = 0;
190 s->start_window_size = 0;
191 s->stop_window_pos = 0;
192 s->stop_window_size = 0;
193 s->start_queue_pos = 0;
194 s->start_queue_size = 0;
195 s->stop_queue_pos = 0;
196 s->stop_queue_size = 0;
207 s->window_duration =
FFMAX(1,
s->window_duration);
218 s->start_found_periods = 0;
219 s->stop_found_periods = 0;
229 switch (
s->detection) {
240 s->cache_size =
s->window_duration;
248 if (!
s->start_window || !
s->stop_window || !
s->start_cache || !
s->stop_cache)
253 if (!
s->start_queuef || !
s->stop_queuef)
260 if (!
s->start_front || !
s->start_back || !
s->stop_front || !
s->stop_back)
265 switch (
s->detection) {
267 s->compute_flt = compute_avg_flt;
268 s->compute_dbl = compute_avg_dbl;
271 s->compute_flt = compute_dev_flt;
272 s->compute_dbl = compute_dev_dbl;
275 s->compute_flt = compute_ptp_flt;
276 s->compute_dbl = compute_ptp_dbl;
279 s->compute_flt = compute_median_flt;
280 s->compute_dbl = compute_median_dbl;
283 s->compute_flt = compute_peak_flt;
284 s->compute_dbl = compute_peak_dbl;
287 s->compute_flt = compute_rms_flt;
288 s->compute_dbl = compute_rms_dbl;
300 int max_out_nb_samples;
301 int out_nb_samples = 0;
310 s->next_pts = in->
pts;
316 if (max_out_nb_samples <= 0) {
329 out->pts =
s->next_pts;
333 switch (outlink->
format) {
335 srcf = (
const float *)in->
data[0];
336 dstf = (
float *)
out->data[0];
337 if (
s->start_periods > 0 &&
s->stop_periods > 0) {
338 const float *
src = srcf;
339 if (
s->start_found_periods >= 0) {
340 for (
int n = 0; n < in_nb_samples; n++) {
341 filter_start_flt(
ctx,
src + n * nb_channels,
342 dstf, &out_nb_samples,
345 in_nb_samples = out_nb_samples;
349 for (
int n = 0; n < in_nb_samples; n++) {
350 filter_stop_flt(
ctx,
src + n * nb_channels,
351 dstf, &out_nb_samples,
354 }
else if (
s->start_periods > 0) {
355 for (
int n = 0; n < in_nb_samples; n++) {
356 filter_start_flt(
ctx, srcf + n * nb_channels,
357 dstf, &out_nb_samples,
360 }
else if (
s->stop_periods > 0) {
361 for (
int n = 0; n < in_nb_samples; n++) {
362 filter_stop_flt(
ctx, srcf + n * nb_channels,
363 dstf, &out_nb_samples,
369 srcd = (
const double *)in->
data[0];
370 dstd = (
double *)
out->data[0];
371 if (
s->start_periods > 0 &&
s->stop_periods > 0) {
372 const double *
src = srcd;
373 if (
s->start_found_periods >= 0) {
374 for (
int n = 0; n < in_nb_samples; n++) {
375 filter_start_dbl(
ctx,
src + n * nb_channels,
376 dstd, &out_nb_samples,
379 in_nb_samples = out_nb_samples;
383 for (
int n = 0; n < in_nb_samples; n++) {
384 filter_stop_dbl(
ctx,
src + n * nb_channels,
385 dstd, &out_nb_samples,
388 }
else if (
s->start_periods > 0) {
389 for (
int n = 0; n < in_nb_samples; n++) {
390 filter_start_dbl(
ctx, srcd + n * nb_channels,
391 dstd, &out_nb_samples,
394 }
else if (
s->stop_periods > 0) {
395 for (
int n = 0; n < in_nb_samples; n++) {
396 filter_stop_dbl(
ctx, srcd + n * nb_channels,
397 dstd, &out_nb_samples,
405 if (out_nb_samples > 0) {
406 s->next_pts += out_nb_samples;
407 out->nb_samples = out_nb_samples;
431 if (
s->start_periods == 1 &&
s->stop_periods == 0 &&
432 s->start_found_periods < 0) {
434 in->
pts =
s->next_pts;
438 if (
s->start_periods == 0 &&
s->stop_periods == 0)
483 .
name =
"silenceremove",
486 .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.