From: Emre Simsirli via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Emre Simsirli <mail@emresimsirli.com>
Subject: [FFmpeg-devel] [PATCH v2 1/2] avformat: Add strftime_mkdir command line parameter to segment muxer
Date: Wed, 25 Feb 2026 23:35:52 +0100
Message-ID: <20260225223726.107069-1-mail@emresimsirli.com> (raw)
In-Reply-To: <9e02b1d1-16e5-483c-a7a5-99a2385bc0c6@emresimsirli.com>
Adds strftime_mkdir parameter so that the parent directories defined in the segment name are correctly created. This makes the strftime functionality in 'segment' consistent with 'hls'.
Signed-off-by: Emre Simsirli <mail@emresimsirli.com>
---
libavformat/segment.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 2c7ba0e776..d84115ef3a 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -97,6 +97,7 @@ typedef struct SegmentContext {
int64_t time; ///< segment duration
int64_t min_seg_duration; ///< minimum segment duration
int use_strftime; ///< flag to expand filename with strftime
+ int use_strftime_mkdir; ///< flag to create parent directories with strftime_mkdir
int increment_tc; ///< flag to increment timecode if found
char *times_str; ///< segment times specification string
@@ -208,6 +209,20 @@ static int set_segment_filename(AVFormatContext *s)
av_bprint_finalize(&filename, NULL);
return AVERROR(ENOMEM);
}
+
+ if (seg->use_strftime_mkdir) {
+ const char* dir;
+ char* fn_copy = av_strdup(filename.str);
+ if (!fn_copy)
+ return AVERROR(ENOMEM);
+ dir = av_dirname(fn_copy);
+ if (ff_mkdir_p(dir) == -1 && errno != EEXIST) {
+ av_log(s, AV_LOG_ERROR, "Could not create directory %s with use_strftime_mkdir\n", dir);
+ av_freep(&fn_copy);
+ return AVERROR(errno);
+ }
+ av_freep(&fn_copy);
+ }
} else {
ret = ff_bprint_get_frame_filename(&filename, s->url, seg->segment_idx, 0);
if (ret < 0) {
@@ -1077,6 +1092,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 last directory component 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.53.0
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
next prev parent reply other threads:[~2026-02-25 22:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 22:23 [FFmpeg-devel] [PATCH] " Emre Simsirli via ffmpeg-devel
2026-02-25 22:35 ` Emre Simsirli via ffmpeg-devel [this message]
2026-02-25 22:35 ` [FFmpeg-devel] [PATCH v2 2/2] doc: Update segment muxer options with strftime_mkdir Emre Simsirli via ffmpeg-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260225223726.107069-1-mail@emresimsirli.com \
--to=ffmpeg-devel@ffmpeg.org \
--cc=mail@emresimsirli.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git