[FFmpeg-devel] [PATCH] libavutil/timestamp.h: Fix loss of precision in timestamps for silencedetect on long files

Allan Cady allancady at yahoo.com
Thu Feb 22 03:21:27 EET 2024


I had a similar thought, as all timestamps would have the same issue.

This is my first contribution here, and I don't know the code very well, so I was being cautious. I'm open to expanding the scope, but I'm sure I would need some help doing it right and not breaking things.

For starters, I'm curious why there are two functions & macros:

av_ts2str/av_ts_make_string (which used "%" format specifier)
av_ts2timestr/av_ts_make_time_string (which used "%6g")

Do you know the rationale for that? I see that only av_ts2timestr is used in silencedetect.c.

And are you suggesting we should fold those two functions into one?

I did notice something in the output from silencedetect. After I made my change, I see the output is now:


frame:92404 pts:53224175 pts_time:2413.79
lavfi.silence_start=2411.120272
frame:92411 pts:53228207 pts_time:2413.98
lavfi.silence_end=2413.992744
lavfi.silence_duration=2.872472


I see that the pts_time values still have the original formatting. I don't know what pts_time is, or where those lines are coming from. Seems like maybe those should have fixed precision as well.

Guidance for a noob please? Thanks.

(P.S. Can you tell me, when I reply to the list (as opposed to patch submission using git send-email), how should I address the email? Obviously it should go to ffmpeg-devel at ffmpeg.org, but should I include you as a recipient, or as a cc:, or only to the list? or is there some other way it gets directed to you? Any other guidance on how to format email? Thanks.)




On Wednesday, February 21, 2024 at 12:25:23 PM PST, Marton Balint <cus at passwd.hu> wrote: 

On Tue, 20 Feb 2024, Allan Cady via ffmpeg-devel wrote:

> When the silencedetect audio filter is run against long files, the
> output timestamps gradually lose precision as the scan proceeds further
> into the file. This is because the output format specifier ("%.6g" in
> libavutil/timestamp.h) limits the total field width to six significant
> digits. As the offset into the file increases, digits drop off the end,
> until eventually, for offsets greater than 100000 seconds (about 28
> hours), fractions of a second disappear altogether, and the timestamps
> are logged as whole seconds.
>
> This patch changes the format to "%.6f" for silencedetect, which will
> give microsecond precision for all timestamps regardless of offset.
>
> libavutil/timestamp.h exposes a macro, av_ts2timestr, as the public
> interface. This macro was used by silencedetect.c, as well as other
> source files. In order to fix the issue for silencedetect without
> affecting other files and tests, I have added a new macro,
> av_ts2timestr_fixed_precision, which uses the new format specifier.
> The original av_ts_make_time_string remains, with the original
> behavior.

I'd rather just to fix av_ts_make_string to not limit the number of 
significant digits. Something like:

1) Print the number in decimal notation with at most 6 fractional digits. 
2) Use less fractional digits if the first format would not fit into 
AV_TS_MAX_STRING_SIZE.
3) Use scientific notation if the second format would not fit into 
AV_TS_MAX_STRINT_SIZE.

Regards,
Marton

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel at ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list