|
|
@ -35,7 +35,7 @@ |
|
|
|
typedef struct SilenceDetectContext { |
|
|
|
typedef struct SilenceDetectContext { |
|
|
|
const AVClass *class; |
|
|
|
const AVClass *class; |
|
|
|
double noise; ///< noise amplitude ratio
|
|
|
|
double noise; ///< noise amplitude ratio
|
|
|
|
double duration; ///< minimum duration of silence until notification
|
|
|
|
int64_t duration; ///< minimum duration of silence until notification
|
|
|
|
int mono; ///< mono mode : check each channel separately (default = check when ALL channels are silent)
|
|
|
|
int mono; ///< mono mode : check each channel separately (default = check when ALL channels are silent)
|
|
|
|
int channels; ///< number of channels
|
|
|
|
int channels; ///< number of channels
|
|
|
|
int independent_channels; ///< number of entries in following arrays (always 1 in mono mode)
|
|
|
|
int independent_channels; ///< number of entries in following arrays (always 1 in mono mode)
|
|
|
@ -50,13 +50,14 @@ typedef struct SilenceDetectContext { |
|
|
|
AVRational time_base); |
|
|
|
AVRational time_base); |
|
|
|
} SilenceDetectContext; |
|
|
|
} SilenceDetectContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_DURATION (24*3600*1000000LL) |
|
|
|
#define OFFSET(x) offsetof(SilenceDetectContext, x) |
|
|
|
#define OFFSET(x) offsetof(SilenceDetectContext, x) |
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM |
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM |
|
|
|
static const AVOption silencedetect_options[] = { |
|
|
|
static const AVOption silencedetect_options[] = { |
|
|
|
{ "n", "set noise tolerance", OFFSET(noise), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0, DBL_MAX, FLAGS }, |
|
|
|
{ "n", "set noise tolerance", OFFSET(noise), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0, DBL_MAX, FLAGS }, |
|
|
|
{ "noise", "set noise tolerance", OFFSET(noise), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0, DBL_MAX, FLAGS }, |
|
|
|
{ "noise", "set noise tolerance", OFFSET(noise), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0, DBL_MAX, FLAGS }, |
|
|
|
{ "d", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DOUBLE, {.dbl=2.}, 0, 24*60*60, FLAGS }, |
|
|
|
{ "d", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=2000000}, 0, MAX_DURATION,FLAGS }, |
|
|
|
{ "duration", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DOUBLE, {.dbl=2.}, 0, 24*60*60, FLAGS }, |
|
|
|
{ "duration", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=2000000}, 0, MAX_DURATION,FLAGS }, |
|
|
|
{ "mono", "check each channel separately", OFFSET(mono), AV_OPT_TYPE_BOOL, {.i64=0.}, 0, 1, FLAGS }, |
|
|
|
{ "mono", "check each channel separately", OFFSET(mono), AV_OPT_TYPE_BOOL, {.i64=0.}, 0, 1, FLAGS }, |
|
|
|
{ "m", "check each channel separately", OFFSET(mono), AV_OPT_TYPE_BOOL, {.i64=0.}, 0, 1, FLAGS }, |
|
|
|
{ "m", "check each channel separately", OFFSET(mono), AV_OPT_TYPE_BOOL, {.i64=0.}, 0, 1, FLAGS }, |
|
|
|
{ NULL } |
|
|
|
{ NULL } |
|
|
@ -142,6 +143,7 @@ static int config_input(AVFilterLink *inlink) |
|
|
|
int c; |
|
|
|
int c; |
|
|
|
|
|
|
|
|
|
|
|
s->channels = inlink->channels; |
|
|
|
s->channels = inlink->channels; |
|
|
|
|
|
|
|
s->duration = av_rescale(s->duration, inlink->sample_rate, AV_TIME_BASE); |
|
|
|
s->independent_channels = s->mono ? s->channels : 1; |
|
|
|
s->independent_channels = s->mono ? s->channels : 1; |
|
|
|
s->nb_null_samples = av_mallocz_array(sizeof(*s->nb_null_samples), s->independent_channels); |
|
|
|
s->nb_null_samples = av_mallocz_array(sizeof(*s->nb_null_samples), s->independent_channels); |
|
|
|
if (!s->nb_null_samples) |
|
|
|
if (!s->nb_null_samples) |
|
|
@ -174,7 +176,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) |
|
|
|
const int nb_channels = inlink->channels; |
|
|
|
const int nb_channels = inlink->channels; |
|
|
|
const int srate = inlink->sample_rate; |
|
|
|
const int srate = inlink->sample_rate; |
|
|
|
const int nb_samples = insamples->nb_samples * nb_channels; |
|
|
|
const int nb_samples = insamples->nb_samples * nb_channels; |
|
|
|
const int64_t nb_samples_notify = srate * s->duration * (s->mono ? 1 : nb_channels); |
|
|
|
const int64_t nb_samples_notify = s->duration * (s->mono ? 1 : nb_channels); |
|
|
|
int c; |
|
|
|
int c; |
|
|
|
|
|
|
|
|
|
|
|
// scale number of null samples to the new sample rate
|
|
|
|
// scale number of null samples to the new sample rate
|
|
|
|