From patchwork Tue Sep 25 14:37:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Dutton X-Patchwork-Id: 10476 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:1286:0:0:0:0:0 with SMTP id 6-v6csp3760949jap; Tue, 25 Sep 2018 07:37:56 -0700 (PDT) X-Google-Smtp-Source: ACcGV620Si63koV6TDQMP7aMcmRgUFa0nMomWCOXk9MNuJcSMyrnY9ZZE53JoLxSJtGLhTo4v9Hn X-Received: by 2002:adf:8141:: with SMTP id 59-v6mr1341418wrm.127.1537886276405; Tue, 25 Sep 2018 07:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537886276; cv=none; d=google.com; s=arc-20160816; b=bMCxbvJ9DNbcDUBlu+VH4ug/yNEqOtFxWsi2QJ7o4C25GWVVB26N5HckSt04EcA97S qkiZY9bf0yP2YHFAg/SHaarj9OC2itVYRWjVGtkoPeaqOYBzoRV3pOnZQ/PgZYUHsrph MxiohXzg52kvW7H1P0HJfGa9BQx5rbvBTxPliAOKzqUSFjsKzP0uZVl6XSzRACbWH2iJ Ea1y9yf/sQiVfQXlPyu65BOPoIdb8UYncX60de+t5598TbffijE01OOW7WBsMmvqoEwg arjYPLo4uXGkvC34BazJxsnOw52QHwPdCG618pvFxTXUPsETgdQo+P7W4cjqa7v+IqdS S2GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=rErlXjla6hMUQ0yfgD/rnv73LQaelvAwtZaWZBS1egE=; b=hbGhrGa8bHtp2mSpVvoS7HFJyiYrzjpbjddYkvmQslvQ25e4EwMUe9Qw/qZ63Lfrc1 otXDSKsNia34DKRlao9JNw/yxaGvyAHryTB+n6DGeY/efWbnQVY7n3ZB6SrZYJt7YbCT syIHQ70Hc2ujbxcpUzx5QzihuP9ll0K7tGYSjzrVOSayqQsz0XVpg0fVVpHhyPKmgRvR +oA7ICg0QjCmZDr16+fkXLnhqxmehw5o8at3VHlCgXtZsPHE538I09LdRIkJ39MzPP/N 5rOrJFSxEjt3TNNmQjhRVyCz1UhewQR7wkgo4SwvI0sVOMZ879UhMrAWurhk2jPJ+Fqd WbBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=I+9xeGcM; 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 a5-v6si2444006wrv.365.2018.09.25.07.37.55; Tue, 25 Sep 2018 07:37:56 -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=I+9xeGcM; 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 D4D4068A320; Tue, 25 Sep 2018 17:37:37 +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 4247B68A308 for ; Tue, 25 Sep 2018 17:37:31 +0300 (EEST) Received: by mail-ot1-f65.google.com with SMTP id h15-v6so888966otj.5 for ; Tue, 25 Sep 2018 07:37:47 -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; bh=ykmxOaAsRS1YBzeeYujQ06X1WCNSQ6D6TacuRFE2wiI=; b=I+9xeGcM96cf46DhFtCoxokv6WGGAKwUOszfEEcsNzkaKYEvN87riQbUs71kACTig1 FxMpOCFanwededbzgDKBcsVfTAq1J9S68PcU5WG1Q4FJnyNmuCKzZnuQPLZl16zFM/Ih vQngCp1jMdC2OaxhqrRabzxoLdbYpT9Wk9FMHPtf0kprDs9QfNatBhVfDZIuDzl3cVH5 gzYOSYIKPZj52UeZ6dhJE7Iw09Xso59Rq9kW806HJXN11q8kpCVlt3ozDCsQ/sHFELTV zn9+Je8WNu2NTDzQQsslofnBnDXOEeehDgTZLDhqCuoS60DPag5rTdGtvYv2VL4CTse2 2njw== 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=ykmxOaAsRS1YBzeeYujQ06X1WCNSQ6D6TacuRFE2wiI=; b=PtF28n1Bb7dvuhr4jdiCMiNXhySUdjs0zNdQ6mwO/VJiK5RFZqxmxDxMHxR+isUQls C25FVPAg6rLDvvYTViqIX6b5OFEIWQ9iARK32D1QV8rquJTygI/wos0d81K+Uy1I5DpN CAqv+09b1dNqDDz9EEAGmihf+EQMJtjzqC88S2kJFL3Gg4rvKMbVKF+4JBl6MiRqR4lp z/VdfK1EO7rtTwi8fcoJPlcT0TUzY+qFPvWYX8ZQ2/gQ/f8qwTYEH50CQIF7Mn7dYpqg txJOauD1WNgQwLeFcguoeF9bYWl4RlLTdZYNMrQ9CKrd+V+o/WivptkO8v70VS4grNYq yg/Q== X-Gm-Message-State: ABuFfogV+V3/pC5mPwl07Dg7NfPNSzDzj+JSBFkUyFgVWfCF4t4CdtND BwVO51THyMK3oM6Keuqsf79/AdBm7b6Ns7r7QZU4vp9f X-Received: by 2002:a9d:747:: with SMTP id 65-v6mr870140ote.315.1537886265140; Tue, 25 Sep 2018 07:37:45 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:2ef3:0:0:0:0:0 with HTTP; Tue, 25 Sep 2018 07:37:04 -0700 (PDT) In-Reply-To: <725C767D-31BF-4225-A2BF-3A151F2B0993@chinaffmpeg.org> References: <20180922162656.GB3200@michaelspb> <20180924124833.GI20958@sunshine.barsnick.net> <20180925092228.GB5851@sunshine.barsnick.net> <725C767D-31BF-4225-A2BF-3A151F2B0993@chinaffmpeg.org> From: James Courtier-Dutton Date: Tue, 25 Sep 2018 15:37:04 +0100 Message-ID: To: FFmpeg development discussions and patches 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Updated patch. This one applies on top of commit bb660800a55f5171f77316941afe2e62534ee72c On 25 September 2018 at 15:00, Steven Liu wrote: > > > > On Sep 25, 2018, at 20:33, James Courtier-Dutton > wrote: > > > > On 25 September 2018 at 10:22, Moritz Barsnick wrote: > > > >> > >> Steven already posted a patch proposal to this list, factoring out the > >> function: > >> https://patchwork.ffmpeg.org/patch/10471/ > >> http://ffmpeg.org/pipermail/ffmpeg-devel/2018-September/234538.html > >> > >> > > That looks fine by me. I can resubmit my segment.c patch once 10471 > reaches > > master tree or at least somewhere I can cherry pick from. > > > > Kind Regards > > > > James > > _______________________________________________ > > ffmpeg-devel mailing list > > ffmpeg-devel@ffmpeg.org > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > Okay, you can go on do this, i have pushed that patch. > > Thanks > Steven > > > > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > From 292a7802fe906399fb59267eb87d93624920409d Mon Sep 17 00:00:00 2001 From: James Courtier-Dutton Date: Tue, 25 Sep 2018 15:32:16 +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..57fce8d 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 with use_localtime_mkdir\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