From: george <george@sx.gl> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avformat/segment: add -strftime_mkdir option Date: Mon, 10 Oct 2022 11:53:15 +0300 Message-ID: <b9a1f8cc-3b36-36b2-ceb6-f45c7c520374@sx.gl> (raw) This enabled automatically creating directories for strftime-formatted segment names. Signed-off-by: George-Cristian Jiglau <george@mux.ro> --- 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".
reply other threads:[~2022-10-10 8:53 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=b9a1f8cc-3b36-36b2-ceb6-f45c7c520374@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