common: round all integer times to milliseconds

This means that a time of 4.5678 is displayed as "00:00:04.568" when the
format string is "%H:%M:%S.%T". Likewise, 59.99999 will be displayed as
"00:01:00.000". Before this change, the sub-ms times were just
truncated.

Requested by TheAMM.
This commit is contained in:
wm4 2018-04-30 19:27:00 +02:00 committed by Jan Ekström
parent 6bd2bdc745
commit 8f67fa13f1
1 changed files with 6 additions and 2 deletions

View File

@ -16,6 +16,7 @@
*/
#include <stdarg.h>
#include <math.h>
#include <assert.h>
#include <libavutil/common.h>
@ -48,14 +49,17 @@ char *mp_format_time_fmt(const char *fmt, double time)
time = time < 0 ? -time : time;
long long int itime = time;
long long int h, m, tm, s;
int ms;
int ms = lrint((time - itime) * 1000);
if (ms >= 1000) {
ms -= 1000;
itime += 1;
}
s = itime;
tm = s / 60;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
ms = (time - itime) * 1000;
char *res = talloc_strdup(NULL, "");
while (*fmt) {
if (fmt[0] == '%') {