From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3670C405F4 for ; Tue, 21 Dec 2021 21:40:23 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F0BBD68AEE7; Tue, 21 Dec 2021 23:40:20 +0200 (EET) Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 87E2F68AE86 for ; Tue, 21 Dec 2021 23:40:15 +0200 (EET) Received: by mail-yb1-f182.google.com with SMTP id j2so313495ybg.9 for ; Tue, 21 Dec 2021 13:40:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=WBVIJvJSiTU1F60HVIRj/bgZWDju3P3mMCiXND7GtwE=; b=CwaUdhGOVCSyIQq28e4Npc63ScNeTcvNjplxtsN7nyjVaJhhgOAPWk+nFAQ2jPhtfe 9WEYOOtQ9q5pco20VPxfFofBQ7UYHCeBDHabgqLle/9tYH/pGm0u7PmhJUX6rsA/fLfk weqKvx5GutoImU+TY5azHgNedRkio/Y+7GN79f2YA7AoVpD9gYQemeskva/mNva/p/za foT9JGz98f8Lr3rzq7KYRML8Rs4p3x3kUoYDQ9kwPAJ/T+50hEvKdW+HpeIY8CTWoRHn aqc8ck1p3lFgASD1wAdVCUSoenL4+IC2cYgujsBj8+rov0/7isJzlkbgzPePG6q3kEGd XZ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=WBVIJvJSiTU1F60HVIRj/bgZWDju3P3mMCiXND7GtwE=; b=Jt9Ihxz8c0WSUjwgLfapXeQ1uNxELWq+ALARM6TuCqyeIL4OpfDXf4MejcKJdnXwb9 aCMeor1M+S6a14Yww5xvB48xj2dFbeidcvSAa4IVU5WQJaWk3Fe7cj47gJmk9iC14y51 Nye3zwzUTF8b8fP5eGB8auV/DR5O2qrfug6WSDhXrF/FAyR5M69BEBFF49OSWIHKmcu+ eLyh95rmv7hSn5JJWqcYeJKJ66aIVohEG8TEKLcxYjSD/vf57BIsP/mKZR4E7OC6qVnq mTHsG3H2uCH8dz3xlaXg9IkaOoW/jB99Wr2h2/5ZkYdF/qVApWUdcLt042UAIrQKrjz7 evuQ== X-Gm-Message-State: AOAM532SFw9DVKnS1wycsV9Yj9I7Ov7LOGU1dP2l74MEaL0+ibdZwPGZ KbWwfQIakyjYn15rDkIedKQTKeI/d6FMJxOhyFBSnpU3AzQDuw== X-Google-Smtp-Source: ABdhPJxGcQ0uHtWpBrnH1W9gRmYqOrHnnpztsTtWQnBjgSErpkO01+PBpW6k/w9J1XcCtQbuNgmHm05ppBUC+zRsTEU= X-Received: by 2002:a25:26cb:: with SMTP id m194mr342183ybm.558.1640122813796; Tue, 21 Dec 2021 13:40:13 -0800 (PST) MIME-Version: 1.0 From: James Dutton Date: Tue, 21 Dec 2021 21:39:37 +0000 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] libavformat/segment: strftime date sub-directories X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 e9b0aa4fa8..86ca243ae6 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -198,12 +198,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.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".