From patchwork Wed Sep 26 09:07:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Dutton X-Patchwork-Id: 10487 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:1286:0:0:0:0:0 with SMTP id 6-v6csp483307jap; Wed, 26 Sep 2018 02:08:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV60xXDg04xaR3mUFC93BRvS87cow+DGEq+3b2qsw5PPof7//qSYec8fLbPFYhrZLvq+ybBxh X-Received: by 2002:a1c:9692:: with SMTP id y140-v6mr3478332wmd.82.1537952929707; Wed, 26 Sep 2018 02:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537952929; cv=none; d=google.com; s=arc-20160816; b=uHmn/kJOs6j2RFz6WHJfP7Dd8mARgWeHcc7Z+DrBlScvPykP/NXZC9mYRryrWb1odR yPrj4e/wv9eBoMIpyXOJxtuiqipDlelezf74m2bIv4d0I3FmF0Q1SCxpOjPt9pT00rli +16/VStuJA9+8XO3Sfkj94IwGafldsvYbCPa55gt8n7nIiu+fcWQvq9XAZHxv4lqPmP7 jBD6s3z3k4nGybt/29KhwGvUGTIvnCNDjfJjI4prJkmxgPiDMoGBhH0UuVgIdfBiPmhT Lia04vleHt3aGhZwQMBY0lkSIlxqE5FerfydV6bkIPapfEWFYHKyVG/BXPoZQXifG/MN F/1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:delivered-to; bh=OcwC8wi9hcSeM0PdNsNOUrEX+Aav2Drq8S6vQXvjCWc=; b=vmkAcxIgjsiDkppttkJJNNTjb9kRZX8JDFXJpYLsaZk1YgyzZCR/yXzsiuqKKHgJoU LHy1sfghZh1HYb9RiSQ+sKMFX960vZt5kWk+CmdCvVgl34Jqb+ynYDOWH6Bt1UVYPAUW ETfSGo1XTwL07mXX6i3jakbFCb1hSPX/yUeHaGJwVXFL1SYTgYQdnCfttTr/i8zGm1Ls 4n50oPnkwmMWF7NSWnhM6i7g0ZwKJVx+qV7MJvx3hKfw5C9t6gIWFjn2i5q2Yly3EQJ+ FzGMSSAVmXPxO94pd+UDdt0RhaixfxeIo+f3DSoX/BELqnvMWdnOpuFMVgY3b6CxEy5R RO2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=pALIYbkA; 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 sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 145-v6si4194091wme.85.2018.09.26.02.08.48; Wed, 26 Sep 2018 02:08:49 -0700 (PDT) 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 header.s=20161025 header.b=pALIYbkA; 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 sp=QUARANTINE 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 A03F568A518; Wed, 26 Sep 2018 12:08:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6D8C0689A0C for ; Wed, 26 Sep 2018 12:08:24 +0300 (EEST) Received: by mail-ot1-f65.google.com with SMTP id e18-v6so27446864oti.8 for ; Wed, 26 Sep 2018 02:08:40 -0700 (PDT) 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 :cc; bh=32MCyxmILh6xySImfvwEv34fReVZZo/w3hlOciCQM5M=; b=pALIYbkAiBi/O/OhRyzbeAkVq6ksXF+X1euUKc4lrzuxPQ5uOre1l239BqpDzMW9Wk Kbh3AZh6A6d5O49xqZmyPTDTEPATKtOFAEWj9kNWQ3a7HCo5k8LmhHil+4SRMvH0UL6h LR+DEyrfl7RnFTOPGJ56E8CrBTQeA1dtyM0l3Y10vYYJdPFcBZs9LoDKFyaa6ogZXMO4 BA6nKEFFUw7Eb4AnhMXaJ26L6zZC9r8/aP2/sm62fbsIN0XU1u+2SHsd0NxSvNT/tQrA x4IDXe08nCxfwCbr/kW/KwgphAwWOxk0m000HKLGBiv9/HCAvVWRemMvCbbTviYNhT6m 1ZkQ== 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:cc; bh=32MCyxmILh6xySImfvwEv34fReVZZo/w3hlOciCQM5M=; b=L/ahfFQo79jS4DWykDecCCuoJU89vCzEHmKRY8JmhBTyVnvznM7+LDcvjaQq08qMEt 3FVDnEy0XdZWt1j1pb/hgaucz6cXor2JZTa0H7EXYrKFKdkOLc69cmQD2TAaG0ijkJap xjKWujSeVFnPl+8sRadNsAv2IQ5Td8VshaUOKlnNpIcTD67Uo84k8bUuu9Dv52zIbIQp uPF7fR7E2yPMu4FMnkDWIgxbZ2RCDKlcGCInBpKe7SXIt2hrji6Em5ALZ4WBHnV6WkEI ijzS5QcGdvr8fAvgLDkD7KR8tWjoSrx7IQ/FEx4L05BKAJlPGydkHQWiw4TvjGOYUYBd Gzgg== X-Gm-Message-State: ABuFfojr9zRay2+jhV/8VkYMhjBKwnFIkLgLCd3db9ZFYLFAKHnvaEpF XMb1QWVXX+Of9gVd7UsoTH6wpizdRYzyysqv0Jp4+g== X-Received: by 2002:a9d:210a:: with SMTP id i10-v6mr3682224otb.238.1537952919416; Wed, 26 Sep 2018 02:08:39 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:2ef3:0:0:0:0:0 with HTTP; Wed, 26 Sep 2018 02:07:58 -0700 (PDT) In-Reply-To: References: <20180922162656.GB3200@michaelspb> <20180924124833.GI20958@sunshine.barsnick.net> <20180925092228.GB5851@sunshine.barsnick.net> <725C767D-31BF-4225-A2BF-3A151F2B0993@chinaffmpeg.org> <3A356D75-7489-4FCE-9573-FBC6B0064905@chinaffmpeg.org> <183EFA33-3FB5-4D82-9F2B-9EF806874795@chinaffmpeg.org> From: James Courtier-Dutton Date: Wed, 26 Sep 2018 10:07:58 +0100 Message-ID: To: Steven Liu X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [PATCH] libavformat/segment: strftime date sub-directories 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 Cc: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On 26 September 2018 at 00:18, Steven Liu wrote: > > > > On Sep 26, 2018, at 06:49, James Courtier-Dutton > wrote: > > On 25 September 2018 at 23:24, Steven Liu wrote: > yes, the error message is confusing, maybe change it here is better. > > > > + av_log(oc, AV_LOG_ERROR, "Could not create directory %s\n", > dir); > > > > Attached patch has the changed error message. From 8d8ea7d1f87a77ee23b6681a714da378b5361e4d Mon Sep 17 00:00:00 2001 From: James Courtier-Dutton Date: Wed, 26 Sep 2018 10:05:13 +0100 Subject: [PATCH] avformat/segment: strftime date sub-directories Automatically create sub-directories if needed based on date. E.g. ffmpeg ... -timelimit 2147483647 -f segment -strftime 1 -segment_time 10 "%Y/%m/%d/%Y-%m-%d_%H-%M-%S.mkv" Signed-off-by: James Courtier-Dutton --- libavformat/segment.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libavformat/segment.c b/libavformat/segment.c index 7fb4dc7..0e17380 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -200,12 +200,27 @@ static int set_segment_filename(AVFormatContext *s) if (seg->use_strftime) { time_t now0; struct tm *tm, tmpbuf; + const char *dir; + char *fn_copy; time(&now0); tm = localtime_r(&now0, &tmpbuf); if (!strftime(buf, sizeof(buf), s->url, tm)) { av_log(oc, AV_LOG_ERROR, "Could not get segment filename with strftime\n"); return AVERROR(EINVAL); } + /* Automatically create directories if needed */ + /* E.g. %Y/%m/%d/%Y-%m-%d_%H-%M-%S.mkv */ + fn_copy = av_strdup(buf); + if (!fn_copy) { + return AVERROR(ENOMEM); + } + dir = av_dirname(fn_copy); + if (ff_mkdir_p(dir) == -1 && errno != EEXIST) { + av_log(oc, AV_LOG_ERROR, "Could not create directory %s\n", dir); + av_free(fn_copy); + return AVERROR(errno); + } + av_free(fn_copy); } else if (av_get_frame_filename(buf, sizeof(buf), s->url, seg->segment_idx) < 0) { av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", s->url); -- 2.7.4