Commit 181ea34b authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

snapshot: add true subsecond timestamp and pad with zeroes (fix #9012)

The previous value was quite bogus.
parent 3328b21b
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h>
#include <dirent.h> #include <dirent.h>
#include <time.h> #include <time.h>
...@@ -174,30 +175,21 @@ int vout_snapshot_SaveImage(char **name, int *sequential, ...@@ -174,30 +175,21 @@ int vout_snapshot_SaveImage(char **name, int *sequential,
free(filename); free(filename);
} }
} else { } else {
struct tm curtime; struct timeval tv;
time_t lcurtime = time(NULL) ; struct tm curtime;
char buffer[128];
if (!localtime_r(&lcurtime, &curtime)) {
const unsigned int id = (image->i_pts / 100000) & 0xFFFFFF; gettimeofday(&tv, NULL);
if (localtime_r(&tv.tv_sec, &curtime) == NULL)
msg_Warn(object, "failed to get current time. Falling back to legacy snapshot naming"); gmtime_r(&tv.tv_sec, &curtime);
if (strftime(buffer, sizeof(buffer), "%Y-%m-%d-%Hh%Mm%Ss",
if (asprintf(&filename, "%s" DIR_SEP "%s%u.%s", &curtime) == 0)
cfg->path, prefix, id, cfg->format) < 0) strcpy(buffer, "error");
filename = NULL;
} else { if (asprintf(&filename, "%s" DIR_SEP "%s%s%03lu.%s",
/* suffix with the last decimal digit in 10s of seconds resolution cfg->path, prefix, buffer, tv.tv_usec / 1000,
* FIXME gni ? */ cfg->format) < 0)
const int id = (image->i_pts / (100*1000)) & 0xFF; filename = NULL;
char buffer[128];
if (!strftime(buffer, sizeof(buffer), "%Y-%m-%d-%Hh%Mm%Ss", &curtime))
strcpy(buffer, "error");
if (asprintf(&filename, "%s" DIR_SEP "%s%s%1u.%s",
cfg->path, prefix, buffer, id, cfg->format) < 0)
filename = NULL;
}
} }
free(prefix); free(prefix);
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment