[FFmpeg-devel] [PATCH] Fix loss of precision for silencedetect on large files

Allan Cady allancady at yahoo.com
Wed Mar 27 00:07:10 EET 2019


When the silencedetect filter is run against very large files, the
output timestamps gradually lose precision as the scan proceeds
further into the file. This is because the output is formatted (in
libavutil/timestamp.h) as "%.6g", which limits the total field length.
Eventually, for offsets greater than 100000 seconds (about 28 hours),
fractions of a second disappear altogether, and the timestamps
are logged as whole integers. This is insufficient precision for
my purposes.

I propose changing the format to "%.3f", which will give millisecond
precision for all timestamps regardless of offset.

Patch file is attached.

EXAMPLE

For a sample scan on a file that's about 35 hours (126000 seconds) length:

$ ffmpeg -i input.mp3 -filter_complex silencedetect=n=-30dB:d=3,ametadata=mode=print:file=silence-out.txt -f null -

The output looks like this near the beginning:

frame:83085 pts:47856431 pts_time:2170.36
lavfi.silence_start=2166.86
frame:83139 pts:47887535 pts_time:2171.77
lavfi.silence_end=2171.77
lavfi.silence_duration=4.91061

Further on we get this:

frame:2450348 pts:1411399919 pts_time:64009.1
lavfi.silence_start=64005.6
frame:2450371 pts:1411413167 pts_time:64009.7
lavfi.silence_end=64009.7
lavfi.silence_duration=4.10082

Eventually after it passes 100000 seconds:

frame:4738029 pts:2729104175 pts_time:123769
lavfi.silence_start=123765
frame:4738055 pts:2729119151 pts_time:123770
lavfi.silence_end=123770
lavfi.silence_duration=4.17918

The start and end times are now in whole integers (seconds).

After making this patch and building the code myself, I now get this
output near the end:

frame:4738029 pts:2729104175 pts_time:123768.897
lavfi.silence_start=123765.411
frame:4738055 pts:2729119151 pts_time:123769.576
lavfi.silence_end=123769.584
lavfi.silence_duration=4.173

This gives me the output I want.

Thank you,

Allan Cady
Seattle WA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-loss-of-precision-for-silencedetect-on-large-fil.patch
Type: application/octet-stream
Size: 921 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190326/4ff7f90c/attachment.obj>


More information about the ffmpeg-devel mailing list