@@ -32,6 +32,8 @@
#include "avfilter.h"
#include "internal.h"
+const char TS_FMT_SILENCEDETECT[] = "%.6f";
+
typedef struct SilenceDetectContext {
const AVClass *class;
double noise; ///< noise amplitude ratio
@@ -87,11 +89,11 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples,
s->start[channel] = insamples->pts + av_rescale_q(current_sample / s->channels + 1 - nb_samples_notify * s->independent_channels / s->channels,
(AVRational){ 1, s->last_sample_rate }, time_base);
set_meta(insamples, s->mono ? channel + 1 : 0, "silence_start",
- av_ts2timestr(s->start[channel], &time_base));
+ av_ts2timestr_fmt(s->start[channel], &time_base, TS_FMT_SILENCEDETECT));
if (s->mono)
av_log(s, AV_LOG_INFO, "channel: %d | ", channel);
av_log(s, AV_LOG_INFO, "silence_start: %s\n",
- av_ts2timestr(s->start[channel], &time_base));
+ av_ts2timestr_fmt(s->start[channel], &time_base, TS_FMT_SILENCEDETECT));
}
}
} else {
@@ -102,15 +104,15 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples,
int64_t duration_ts = end_pts - s->start[channel];
if (insamples) {
set_meta(insamples, s->mono ? channel + 1 : 0, "silence_end",
- av_ts2timestr(end_pts, &time_base));
+ av_ts2timestr_fmt(end_pts, &time_base, TS_FMT_SILENCEDETECT));
set_meta(insamples, s->mono ? channel + 1 : 0, "silence_duration",
- av_ts2timestr(duration_ts, &time_base));
+ av_ts2timestr_fmt(duration_ts, &time_base, TS_FMT_SILENCEDETECT));
}
if (s->mono)
av_log(s, AV_LOG_INFO, "channel: %d | ", channel);
av_log(s, AV_LOG_INFO, "silence_end: %s | silence_duration: %s\n",
- av_ts2timestr(end_pts, &time_base),
- av_ts2timestr(duration_ts, &time_base));
+ av_ts2timestr_fmt(end_pts, &time_base, TS_FMT_SILENCEDETECT),
+ av_ts2timestr_fmt(duration_ts, &time_base, TS_FMT_SILENCEDETECT));
}
s->nb_null_samples[channel] = 0;
s->start[channel] = INT64_MIN;
@@ -32,6 +32,8 @@
#define AV_TS_MAX_STRING_SIZE 32
+#define AV_TS_FMT_DEFAULT "%.6g"
+
/**
* Fill the provided buffer with a string containing a timestamp
* representation.
@@ -53,6 +55,23 @@ static inline char *av_ts_make_string(char *buf, int64_t ts)
*/
#define av_ts2str(ts) av_ts_make_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts)
+/**
+ * Fill the provided buffer with a string containing a timestamp time
+ * representation, allowing format specification.
+ *
+ * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
+ * @param ts the timestamp to represent
+ * @param tb the timebase of the timestamp
+ * @param format string for timestamp output, e.g. AV_TS_FMT_DEFAULT.
+ * @return the buffer in input
+ */
+static inline char *av_ts_make_time_string_format(char *buf, int64_t ts, AVRational *tb, const char *format)
+{
+ if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
+ else snprintf(buf, AV_TS_MAX_STRING_SIZE, format, av_q2d(*tb) * ts);
+ return buf;
+}
+
/**
* Fill the provided buffer with a string containing a timestamp time
* representation.
@@ -64,15 +83,15 @@ static inline char *av_ts_make_string(char *buf, int64_t ts)
*/
static inline char *av_ts_make_time_string(char *buf, int64_t ts, AVRational *tb)
{
- if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
- else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.6g", av_q2d(*tb) * ts);
+ av_ts_make_time_string_format(buf, ts, tb, AV_TS_FMT_DEFAULT);
return buf;
}
/**
- * Convenience macro, the return value should be used only directly in
+ * Convenience macros, the return value should be used only directly in
* function arguments but never stand-alone.
*/
-#define av_ts2timestr(ts, tb) av_ts_make_time_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb)
+#define av_ts2timestr_fmt(ts, tb, fmt) av_ts_make_time_string_format((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb, fmt)
+#define av_ts2timestr(ts, tb) av_ts_make_time_string_format((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb, AV_TS_FMT_DEFAULT)
#endif /* AVUTIL_TIMESTAMP_H */
@@ -1,5 +1,5 @@
pkt_pts=0|tag:lavfi.silence_duration=0.523107|tag:lavfi.silence_end=0.690023|tag:lavfi.silence_start=0.736417
-pkt_pts=46080|tag:lavfi.silence_start=1.27626|tag:lavfi.silence_end=1.80751|tag:lavfi.silence_duration=0.531247
+pkt_pts=46080|tag:lavfi.silence_start=1.276259|tag:lavfi.silence_end=1.807506|tag:lavfi.silence_duration=0.531247
pkt_pts=92160
pkt_pts=138240
pkt_pts=184320