From patchwork Wed Dec 28 23:45:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodecs Bela X-Patchwork-Id: 1965 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2179382vsb; Wed, 28 Dec 2016 15:45:34 -0800 (PST) X-Received: by 10.28.62.141 with SMTP id l135mr37972275wma.20.1482968734492; Wed, 28 Dec 2016 15:45:34 -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 f124si52064042wmd.64.2016.12.28.15.45.33; Wed, 28 Dec 2016 15:45:34 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6F5BB689E51; Thu, 29 Dec 2016 01:45:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.vivacom.hu (mail.vivacom.hu [217.173.41.231]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6F50E689E43 for ; Thu, 29 Dec 2016 01:45:22 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by mail.vivacom.hu (Postfix) with ESMTP id 19AE9835A3 for ; Thu, 29 Dec 2016 00:45:25 +0100 (CET) X-Virus-Scanned: amavisd-new at example.com Received: from mail.vivacom.hu ([127.0.0.1]) by localhost (mail.vivacom.intra [127.0.0.1]) (amavisd-new, port 10024) with LMTP id LZWZRNtA0yW2 for ; Thu, 29 Dec 2016 00:45:23 +0100 (CET) Received: from [192.168.3.9] (pool-dsl-2f-00fd.externet.hu [217.173.47.253]) by mail.vivacom.hu (Postfix) with ESMTPA id AAEF782C3A for ; Thu, 29 Dec 2016 00:45:23 +0100 (CET) From: Bodecs Bela To: FFmpeg development discussions and patches Message-ID: <19981fca-7a89-f83c-3f83-ec20bc049a19@vivanet.hu> Date: Thu, 29 Dec 2016 00:45:18 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavformat/hlsenc: fix delete_segments when use_localtime_mkdir 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" Dear All, when delete_segments hls_flag is specified, deleting old segments may fail in certain cases when use_localtime_mkdir is in effect and hls_segment_filename expression contains subdirs. This patch fixes this behaviour. Command to reproduce the bug: ffmpeg -loglevel info -y -re -f lavfi -i color=c=red:size=640x480:r=25 -f lavfi -i anullsrc=r=44100:cl=stereo -c:v mpeg2video -g 25 -acodec aac -cutoff 20000 -ac 2 -ar 44100 -ab 192k -f hls -hls_time 3 -hls_list_size 5 -hls_flags delete_segments -use_localtime_mkdir 1 -use_localtime 1 -hls_segment_filename "bb/bb%Y%m%d%H%I%S.ts" stream.m3u8 thank you in advance, Bela Bodecs From ac4c24c2826d2704e595fbde515b184429a64073 Mon Sep 17 00:00:00 2001 From: Bela Bodecs Date: Thu, 29 Dec 2016 00:30:00 +0100 Subject: [PATCH 1/1] libavformat/hlsenc: fix delete_segments when use_localtime_mkdir When delete_segments hls_flag is specified, deleting old segments may fail in certain cases when use_localtime_mkdir is in effect and hls_segment_filename expression contains subdirs. This patch fixes this behaviour. Signed-off-by: Bela Bodecs --- libavformat/hlsenc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index cf4d4bd..c9d8e3c 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -194,7 +194,7 @@ static int hls_delete_old_segments(HLSContext *hls) { } } - if (segment) { + if (segment && !hls->use_localtime_mkdir) { if (hls->segment_filename) { dirname = av_strdup(hls->segment_filename); } else { @@ -211,15 +211,20 @@ static int hls_delete_old_segments(HLSContext *hls) { while (segment) { av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n", segment->filename); - path_size = strlen(dirname) + strlen(segment->filename) + 1; + path_size = (hls->use_localtime_mkdir ? 0 : strlen(dirname)) + strlen(segment->filename) + 1; path = av_malloc(path_size); if (!path) { ret = AVERROR(ENOMEM); goto fail; } - av_strlcpy(path, dirname, path_size); - av_strlcat(path, segment->filename, path_size); + if (hls->use_localtime_mkdir) + av_strlcpy(path, segment->filename, path_size); + else { // segment->filename contains basename only + av_strlcpy(path, dirname, path_size); + av_strlcat(path, segment->filename, path_size); + } + if (unlink(path) < 0) { av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n", path, strerror(errno)); -- 2.5.3.windows.1