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 AA5F34436E for ; Mon, 10 Oct 2022 08:53:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B72AF68BCAA; Mon, 10 Oct 2022 11:53:23 +0300 (EEST) Received: from mail.sx.gl (unknown [86.127.212.246]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 60FD068B1E1 for ; Mon, 10 Oct 2022 11:53:17 +0300 (EEST) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sx.gl; s=mail; t=1665391996; bh=BPnx5BBtAUOM1LfXMz4BvhlcSUd00sAo8XqpPCYGb9M=; h=Date:From:Subject:To; b=HYQVnrp7om5S6yC3JLtpUiFoEnopR8GdtHqquXnpnek/hxk2+vC9dx7ysYmJW+lWM xPP8GeaRLtq0t3eHafIdYHEl+MHAogz49YTPnxG+70eoNtGCuxXy7T8ZhCZDgQJKSx +AgpLWZIrHDP772QyZltZSXodYSx8p45PRr9+31c= Date: Mon, 10 Oct 2022 11:53:15 +0300 MIME-Version: 1.0 From: george To: ffmpeg-devel@ffmpeg.org Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] avformat/segment: add -strftime_mkdir option 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: This enabled automatically creating directories for strftime-formatted segment names. Signed-off-by: George-Cristian Jiglau --- doc/muxers.texi | 11 +++++++++++ libavformat/segment.c | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 4edbb22b00..77792379d9 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -2445,6 +2445,17 @@ segments to write. If this is selected, the output segment name must contain a @code{strftime} function template. Default value is @code{0}. +@item strftime_mkdir @var{1|0| +Used together with -strftime, it will create all subdirectories of the +expanded segment name. Default value is @code{0}. + +@example +ffmpeg -i in.nut -strftime 1 -strftime_mkdir 1 -hls_segment_filename '%Y/%m/%d/file-%Y%m%d-%s.ts' out.m3u8 +@end example +This example will create a directory hierarchy 2016/02/15 (if any of them do not exist), and then +produce the playlist, @file{out.m3u8}, and segment files: +@file{2016/02/15/file-20160215-1455569023.ts}, @file{2016/02/15/file-20160215-1455569024.ts}, etc. + @item break_non_keyframes @var{1|0} If enabled, allow segments to start on frames other than keyframes. This improves behavior on some players when the time between keyframes is diff --git a/libavformat/segment.c b/libavformat/segment.c index c904e20708..ef95b34beb 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -93,9 +93,11 @@ typedef struct SegmentContext { int list_type; ///< set the list type AVIOContext *list_pb; ///< list file put-byte context int64_t time; ///< segment duration - int use_strftime; ///< flag to expand filename with strftime int increment_tc; ///< flag to increment timecode if found + int use_strftime; ///< flag to expand filename with strftime + int use_strftime_mkdir; ///< flag to mkdir dirname in strftime filename + char *times_str; ///< segment times specification string int64_t *times; ///< list of segment interval specification int nb_times; ///< number of elments in the times array @@ -203,6 +205,19 @@ static int set_segment_filename(AVFormatContext *s) av_log(oc, AV_LOG_ERROR, "Could not get segment filename with strftime\n"); return AVERROR(EINVAL); } + if (seg->use_strftime_mkdir) { + const char *dir; + char *fn_copy = av_strdup(oc->url); + 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 strftime_mkdir\n", dir); + av_freep(&fn_copy); + return AVERROR(errno); + } + av_freep(&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); @@ -1038,6 +1053,7 @@ static const AVOption options[] = { { "segment_start_number", "set the sequence number of the first segment", OFFSET(segment_idx), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E }, { "segment_wrap_number", "set the number of wrap before the first segment", OFFSET(segment_idx_wrap_nb), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E }, { "strftime", "set filename expansion with strftime at segment creation", OFFSET(use_strftime), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E }, + { "strftime_mkdir", "create directory components in strftime-generated filename", OFFSET(use_strftime_mkdir), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E }, { "increment_tc", "increment timecode between each segment", OFFSET(increment_tc), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E }, { "break_non_keyframes", "allow breaking segments on non-keyframes", OFFSET(break_non_keyframes), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E }, -- 2.36.2 _______________________________________________ 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".