Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avformat: Add strftime_mkdir command line parameter to segment muxer
@ 2026-02-25 22:23 Emre Simsirli via ffmpeg-devel
  2026-02-25 22:35 ` [FFmpeg-devel] [PATCH v2 1/2] " Emre Simsirli via ffmpeg-devel
  0 siblings, 1 reply; 3+ messages in thread
From: Emre Simsirli via ffmpeg-devel @ 2026-02-25 22:23 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Emre Simsirli

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-25 22:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-25 22:23 [FFmpeg-devel] [PATCH] avformat: Add strftime_mkdir command line parameter to segment muxer Emre Simsirli via ffmpeg-devel
2026-02-25 22:35 ` [FFmpeg-devel] [PATCH v2 1/2] " Emre Simsirli via ffmpeg-devel
2026-02-25 22:35   ` [FFmpeg-devel] [PATCH v2 2/2] doc: Update segment muxer options with strftime_mkdir Emre Simsirli via ffmpeg-devel

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