diff mbox

[FFmpeg-devel] libavformat/hlsenc: default segment name and, use_localtime

Message ID ce720b46-db3b-fe59-c3b8-3a35f86449a5@vivanet.hu
State Superseded
Headers show

Commit Message

Bodecs Bela Dec. 30, 2016, 5:24 p.m. UTC
2016.12.30. 18:11 keltezéssel, Moritz Barsnick írta:
> On Fri, Dec 30, 2016 at 15:38:25 +0100, Bodecs Bela wrote:
>> is not available on all system/environment. This patch checks %s
>> availabilty at runtine and alter the default format string if necessary.
> You forgot to add the patch.
please, forgive me. I attached it now.
>
> Moritz
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Bela
diff mbox

Patch

From 00530d632427c8e9170e0aff6b807a704af60e51 Mon Sep 17 00:00:00 2001
From: Bela Bodecs <bodecsb@vivanet.hu>
Date: Fri, 30 Dec 2016 15:15:39 +0100
Subject: [PATCH] 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>
---
 libavformat/hlsenc.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index c9d8e3c..76b85e8 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -829,13 +829,22 @@  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);
+    return (strftime(b, sizeof(b), "%s", p) > 2) ? "-%s.ts" : "-%Y%m%d%H%I%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;
-- 
2.5.3.windows.1