libavformat/hlsenc: default segment name and use_localtime
ffmpeg | branch: master | Bela Bodecs <bodecsb@vivanet.hu> | Sun Jan 1 11:00:45 2017 +0800| [8fd3e02eee87e0830fa7ab1dbb65160e5be76d20] | committer: Bela Bodecs libavformat/hlsenc: default segment name and use_localtime in hlcenc.c, in the hls_write_header() function the default format string for strftime() function contains %s specifier when use_localtime is true. This %s specifier will insert the seconds since EPOCH. But %s is not available on all system/environment. This patch check %s availabilty at runtine and alter the default format string if necessary. Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8fd3e02eee87e0830f...
libavformat/hlsenc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index c9d8e3c..57fc9c1 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -829,13 +829,23 @@ fail: return err; } +static const char * get_default_pattern_localtime_fmt(void) +{ + char b[21]; + time_t t = time(NULL); + struct tm *p, tmbuf; + p = localtime_r(&t, &tmbuf); + // no %s support when strftime returned error or left format string unchanged + return (!strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%I%S.ts" : "-%s.ts"; +} + static int hls_write_header(AVFormatContext *s) { HLSContext *hls = s->priv_data; int ret, i; char *p; const char *pattern = "%d.ts"; - const char *pattern_localtime_fmt = "-%s.ts"; + const char *pattern_localtime_fmt = get_default_pattern_localtime_fmt(); const char *vtt_pattern = "%d.vtt"; AVDictionary *options = NULL; int basename_size;
participants (1)
-
git@videolan.org