History

avfilter/af_silenceremove: add timestamp option

Paul B Mahol committed 3 years ago

Commit 62d41101 parent b95d1232 files · +27 −2Browse files

Unified · Split

2 files
  1. doc/filters.texi +10 −0
  2. libavfilter/af_silenceremove.c +17 −2
doc/filters.texi+10−0
@@ -6485,6 +6485,16 @@ In that case it may be needed to also set @option{start_silence} and/or · 6484 unmodified lines
64856485 @option{stop_silence} to nonzero values with also @option{start_duration} and/or
64866486 @option{stop_duration} to nonzero values.
64876487 Default value is @code{0.02}. Allowed range is from @code{0} to @code{10}.
6488+
6489+@item timestamp
6490+Set processing mode of every audio frame output timestamp.
6491+@table @option
6492+@item write
6493+Full timestamps rewrite, keep only the start time for the first output frame.
6494+@item copy
6495+Non-dropped frames are left with same timestamp as input audio frame.
6496+@end table
6497+Defaults value is @code{write}.
64886498 @end table
64896499
64906500 @subsection Examples
libavfilter/af_silenceremove.c+17−2
@@ -41,6 +41,12 @@ enum SilenceDetect { · 40 unmodified lines
4141 D_NB
4242 };
4343
44+enum TimestampMode {
45+ TS_WRITE,
46+ TS_COPY,
47+ TS_NB
48+};
49+
4450 enum ThresholdMode {
4551 T_ANY,
4652 T_ALL,
@@ -67,6 +73,8 @@ typedef struct SilenceRemoveContext { · 20 unmodified lines
6773
6874 int64_t window_duration_opt;
6975
76+ int timestamp_mode;
77+
7078 int start_found_periods;
7179 int stop_found_periods;
7280
@@ -138,6 +146,9 @@ static const AVOption silenceremove_options[] = { · 65 unmodified lines
138146 { "median", "use median of absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_MEDIAN},0, 0, AF, "detection" },
139147 { "ptp", "use absolute of max peak to min peak difference", 0, AV_OPT_TYPE_CONST, {.i64=D_PTP}, 0, 0, AF, "detection" },
140148 { "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF },
149+ { "timestamp", "set how every output frame timestamp is processed", OFFSET(timestamp_mode), AV_OPT_TYPE_INT, {.i64=TS_WRITE}, 0, TS_NB-1, AF, "timestamp" },
150+ { "write", "full timestamps rewrite, keep only the start time", 0, AV_OPT_TYPE_CONST, {.i64=TS_WRITE}, 0, 0, AF, "timestamp" },
151+ { "copy", "non-dropped frames are left with same timestamp", 0, AV_OPT_TYPE_CONST, {.i64=TS_COPY}, 0, 0, AF, "timestamp" },
141152 { NULL }
142153 };
143154
@@ -293,7 +304,10 @@ static int filter_frame(AVFilterLink *outlink, AVFrame *in) · 149 unmodified lines
293304 return AVERROR(ENOMEM);
294305 }
295306
296− out->pts = s->next_pts;
307+ if (s->timestamp_mode == TS_WRITE)
308+ out->pts = s->next_pts;
309+ else
310+ out->pts = in->pts;
297311
298312 switch (outlink->format) {
299313 case AV_SAMPLE_FMT_FLT:
@@ -395,7 +409,8 @@ static int activate(AVFilterContext *ctx) · 95 unmodified lines
395409 if (ret > 0) {
396410 if (s->start_periods == 1 && s->stop_periods == 0 &&
397411 s->start_found_periods < 0) {
398− in->pts = s->next_pts;
412+ if (s->timestamp_mode == TS_WRITE)
413+ in->pts = s->next_pts;
399414 s->next_pts += in->nb_samples;
400415 return ff_filter_frame(outlink, in);
401416 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t