From patchwork Sun Jan 1 03:03:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 2002 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp3458659vsb; Sat, 31 Dec 2016 19:03:28 -0800 (PST) X-Received: by 10.28.236.83 with SMTP id k80mr43259331wmh.0.1483239808040; Sat, 31 Dec 2016 19:03:28 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m4si64565528wmf.85.2016.12.31.19.03.27; Sat, 31 Dec 2016 19:03:28 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF8766899EA; Sun, 1 Jan 2017 05:03:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wj0-f182.google.com (mail-wj0-f182.google.com [209.85.210.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9D57680D22 for ; Sun, 1 Jan 2017 05:03:14 +0200 (EET) Received: by mail-wj0-f182.google.com with SMTP id tq7so166566852wjb.0 for ; Sat, 31 Dec 2016 19:03:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=bXcc6SwA7hi0SVDZ46E04qoNKeiK4Imx9g/VgrPtl3A=; b=e4eVO+hM59bIMRWiGEAZOUfB8L7YxfgsrqhOHQW3pNVG55Ld/ZqAFx9K2eEWrJVtf8 3il/DUewVbI9kcQrclZiz7EYX3UmEjRDxF+SD2iBBaszoadaurav/aRu6cTfeWoSWo7I Yni4vxnmPp1yRFsmvY375AhB1e/iBW1ATOvvn3y35vrvF/ahcP9RIVIb8KflAuK+KtLW CNHlGx3j9mGFMXC0FQHSCR9L5VFQMvNuJc3lV/9ymKxvWPImX5q/wtbcT101nwrWeAye gZxvawI/U5ZH0l934Um0/iFv7hFMojthsiqBxBsgCgm+kKkuztvBjn2ONvX+DLYeUe6Q qVZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=bXcc6SwA7hi0SVDZ46E04qoNKeiK4Imx9g/VgrPtl3A=; b=BwYrBiaydh73Kv5QO569BI4tKApdNlEwTJrHqbqM7eH+ssogAe15PwWwO5/xnETkg0 kHi685i6H9B+/KodD77I6WWOuzpdZwkanC2nVF1t+FG2zfI8v23V8Rjuz+rtIqdGxAae fZg+UZOIsaJB3YD5UY/YesKb25G7BsNd9CeUvm/g+ik/s/HDqjT4we+I4HQ33lorJ/dS LfPbEAZipqF9n3eubUMxMJHWbsWU1BXCeSt1ZDQYYt8lAWcktvP4vAAgz8K/zX0kYBFK mFIZIul2qhWRndtaAs15vbPAWrKltC77Z0nh6EhJ9eEo3jdhzZm1d4vXsPgvAE1VI1Fk DqAw== X-Gm-Message-State: AIkVDXLYBr+mWT1kSa3roxynMJHkW/i2cWafngiLaE0GXj1f8MRS1Cu8KrLXBrQMR91ayRJfg8NPVeVpU9g8Hg== X-Received: by 10.194.136.166 with SMTP id qb6mr43618866wjb.42.1483239797863; Sat, 31 Dec 2016 19:03:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.171.106 with HTTP; Sat, 31 Dec 2016 19:03:17 -0800 (PST) In-Reply-To: <37d0a6e0-0681-95ef-02d9-c3ffacc0467d@vivanet.hu> References: <20161230171111.GA26868@sunshine.barsnick.net> <8e080f1c-0567-eba6-ccd1-e1bd94abf7ac@vivanet.hu> <37d0a6e0-0681-95ef-02d9-c3ffacc0467d@vivanet.hu> From: Steven Liu Date: Sun, 1 Jan 2017 11:03:17 +0800 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [PATCH] libavformat/hlsenc: default segment name and, use_localtime X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 2017-01-01 0:56 GMT+08:00 Bodecs Bela : > > > 2016.12.31. 14:19 keltezéssel, Steven Liu írta: > >> 2016-12-31 19:16 GMT+08:00 Bodecs Bela : >> >> >>> 2016.12.31. 11:48 keltezéssel, Steven Liu írta: >>> >>> 2016-12-31 1:24 GMT+08:00 Bodecs Bela : >>>> >>>> 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 >>>>>> >>>>> _______________________________________________ >>>>> ffmpeg-devel mailing list >>>>> ffmpeg-devel@ffmpeg.org >>>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >>>>> >>>>> Signed-off-by: Bela Bodecs >>>>> >>>>> --- >>>> 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"; >>>> Why check strftime result bigger than 2,not 1 not 3? >>>> >>>> I have faced different strftime behaviours on two different environments >>> where unknown specifier was in format string. >>> On one of them strftime returned 0, this was the expected return value by >>> me. >>> But on the other one, strftime returned 2 and put unknown specifier (%s) >>> as is into the result buffer. >>> So >2 will handle each cases. In normal behaviour, nowadays, length of >>> seconds string will be always longer than 2. >>> Should I put a comment about it into the code? >>> >> Maybe add a comment for the value 2 is better. >> > you are right. I have changed the testing line to be more self-explanatory. > I have attached the new patch. > >> >>> +} >>> >>>> + >>>> 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; >>>> >>>> _______________________________________________ >>> ffmpeg-devel mailing list >>> ffmpeg-devel@ffmpeg.org >>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >>> >>> _______________________________________________ >> ffmpeg-devel mailing list >> ffmpeg-devel@ffmpeg.org >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >> > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > --- libavformat/hlsenc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) const char *vtt_pattern = "%d.vtt"; AVDictionary *options = NULL; int basename_size; 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();