From: George-Cristian Jiglau <george@sx.gl> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2] avformat/segment: add -strftime_mkdir option Date: Mon, 10 Oct 2022 13:14:59 +0300 Message-ID: <20221010101459.1781083-1-george@sx.gl> (raw) This enables automatically creating directories for strftime-formatted segment names. Signed-off-by: George-Cristian Jiglau <george@sx.gl> --- doc/muxers.texi | 4 ++++ libavformat/segment.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/doc/muxers.texi b/doc/muxers.texi index 4edbb22b00..96b63f4b9e 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -2445,6 +2445,10 @@ 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}. + @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..f75c7228f1 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -94,6 +94,7 @@ typedef struct SegmentContext { AVIOContext *list_pb; ///< list file put-byte context int64_t time; ///< segment duration int use_strftime; ///< flag to expand filename with strftime + int use_strftime_mkdir; ///< flag to mkdir dirname in strftime filename int increment_tc; ///< flag to increment timecode if found char *times_str; ///< segment times specification string @@ -203,6 +204,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 +1052,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".
next reply other threads:[~2022-10-10 10:15 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-10 10:14 George-Cristian Jiglau [this message] 2022-12-27 14:42 Steven Viola
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=20221010101459.1781083-1-george@sx.gl \ --to=george@sx.gl \ --cc=ffmpeg-devel@ffmpeg.org \ /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