* [FFmpeg-devel] [PATCH] libavformat/segment: strftime date sub-directories
@ 2021-12-21 21:39 James Dutton
2021-12-21 21:45 ` James Dutton
0 siblings, 1 reply; 2+ messages in thread
From: James Dutton @ 2021-12-21 21:39 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Automatically create sub-directories if needed based on date.
E.g.
ffmpeg ... -timelimit 2147483647 -f segment -strftime 1 -segment_time
10 "%Y/%m/%d/%Y-%m-%d_%H-%M-%S.mkv"
Signed-off-by: James Courtier-Dutton <james.dutton@gmail.com>
---
libavformat/segment.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/libavformat/segment.c b/libavformat/segment.c
index e9b0aa4fa8..86ca243ae6 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -198,12 +198,27 @@ static int set_segment_filename(AVFormatContext *s)
if (seg->use_strftime) {
time_t now0;
struct tm *tm, tmpbuf;
+ const char *dir;
+ char *fn_copy;
time(&now0);
tm = localtime_r(&now0, &tmpbuf);
if (!strftime(buf, sizeof(buf), s->url, tm)) {
av_log(oc, AV_LOG_ERROR, "Could not get segment filename
with strftime\n");
return AVERROR(EINVAL);
}
+ /* Automatically create directories if needed */
+ /* E.g. %Y/%m/%d/%Y-%m-%d_%H-%M-%S.mkv */
+ fn_copy = av_strdup(buf);
+ 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 use_localtime_mkdir\n", dir);
+ av_free(fn_copy);
+ return AVERROR(errno);
+ }
+ av_free(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);
--
2.25.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavformat/segment: strftime date sub-directories
2021-12-21 21:39 [FFmpeg-devel] [PATCH] libavformat/segment: strftime date sub-directories James Dutton
@ 2021-12-21 21:45 ` James Dutton
0 siblings, 0 replies; 2+ messages in thread
From: James Dutton @ 2021-12-21 21:45 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Hi,
This is a follow on from:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/CAAMvbhG9QsKSXfUzrt3REsRR89J5scYd84ec6OLEARqx4CUD-A@mail.gmail.com/
On Tue, 21 Dec 2021 at 21:39, James Dutton <james.dutton@gmail.com> wrote:
>
> Automatically create sub-directories if needed based on date.
> E.g.
> ffmpeg ... -timelimit 2147483647 -f segment -strftime 1 -segment_time
> 10 "%Y/%m/%d/%Y-%m-%d_%H-%M-%S.mkv"
>
> Signed-off-by: James Courtier-Dutton <james.dutton@gmail.com>
> ---
> libavformat/segment.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/libavformat/segment.c b/libavformat/segment.c
> index e9b0aa4fa8..86ca243ae6 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -198,12 +198,27 @@ static int set_segment_filename(AVFormatContext *s)
> if (seg->use_strftime) {
> time_t now0;
> struct tm *tm, tmpbuf;
> + const char *dir;
> + char *fn_copy;
> time(&now0);
> tm = localtime_r(&now0, &tmpbuf);
> if (!strftime(buf, sizeof(buf), s->url, tm)) {
> av_log(oc, AV_LOG_ERROR, "Could not get segment filename
> with strftime\n");
> return AVERROR(EINVAL);
> }
> + /* Automatically create directories if needed */
> + /* E.g. %Y/%m/%d/%Y-%m-%d_%H-%M-%S.mkv */
> + fn_copy = av_strdup(buf);
> + 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 use_localtime_mkdir\n", dir);
> + av_free(fn_copy);
> + return AVERROR(errno);
> + }
> + av_free(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);
> --
> 2.25.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-21 21:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-21 21:39 [FFmpeg-devel] [PATCH] libavformat/segment: strftime date sub-directories James Dutton
2021-12-21 21:45 ` James Dutton
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