diff mbox

[FFmpeg-devel] libavformat/segment: strftime date sub-directories

Message ID CAAMvbhExOevmtGekr94_M7stg+brWDagUhoV4WAH=eeSAtNtxA@mail.gmail.com
State Superseded
Headers show

Commit Message

James Dutton Nov. 30, 2017, 11:07 p.m. UTC

Comments

Michael Niedermayer Sept. 22, 2018, 4:26 p.m. UTC | #1
On Thu, Nov 30, 2017 at 11:07:03PM +0000, James Courtier-Dutton wrote:
> 

>  segment.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)
> e3e9961df186f73adb24f7a334d398884e894d53  0001-libavformat-segment-strftime-date-sub-directories.patch
> From b6a6f6d577e562c09c7cc1fc0befd2d73a9c0f32 Mon Sep 17 00:00:00 2001
> From: James Courtier-Dutton <James.Dutton@gmail.com>
> Date: Thu, 30 Nov 2017 22:56:04 +0000
> Subject: [PATCH] libavformat/segment: strftime date sub-directories
> 
> 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"
> ---
>  libavformat/segment.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)

doesnt apply anymore

Applying: libavformat/segment: strftime date sub-directories
Using index info to reconstruct a base tree...
M	libavformat/segment.c
Falling back to patching base and 3-way merge...
Auto-merging libavformat/segment.c
CONFLICT (content): Merge conflict in libavformat/segment.c
error: Failed to merge in the changes.
Patch failed at 0001 libavformat/segment: strftime date sub-directories
hint: Use 'git am --show-current-patch' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

[...]
James Dutton Sept. 24, 2018, 11:44 a.m. UTC | #2
Updated patch is here:
https://patchwork.ffmpeg.org/patch/10469/

Functionalist has not changed. It has been updated to apply to the latest
master branch.


On 22 September 2018 at 17:26, Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Thu, Nov 30, 2017 at 11:07:03PM +0000, James Courtier-Dutton wrote:
> >
>
> >  segment.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 48 insertions(+)
> > e3e9961df186f73adb24f7a334d398884e894d53  0001-libavformat-segment-
> strftime-date-sub-directories.patch
> > From b6a6f6d577e562c09c7cc1fc0befd2d73a9c0f32 Mon Sep 17 00:00:00 2001
> > From: James Courtier-Dutton <James.Dutton@gmail.com>
> > Date: Thu, 30 Nov 2017 22:56:04 +0000
> > Subject: [PATCH] libavformat/segment: strftime date sub-directories
> >
> > 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"
> > ---
> >  libavformat/segment.c | 48 ++++++++++++++++++++++++++++++
> ++++++++++++++++++
> >  1 file changed, 48 insertions(+)
>
> doesnt apply anymore
>
> Applying: libavformat/segment: strftime date sub-directories
> Using index info to reconstruct a base tree...
> M       libavformat/segment.c
> Falling back to patching base and 3-way merge...
> Auto-merging libavformat/segment.c
> CONFLICT (content): Merge conflict in libavformat/segment.c
> error: Failed to merge in the changes.
> Patch failed at 0001 libavformat/segment: strftime date sub-directories
> hint: Use 'git am --show-current-patch' to see the failed patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".
>
> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> When you are offended at any man's fault, turn to yourself and study your
> own failings. Then you will forget your anger. -- Epictetus
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
diff mbox

Patch

From b6a6f6d577e562c09c7cc1fc0befd2d73a9c0f32 Mon Sep 17 00:00:00 2001
From: James Courtier-Dutton <James.Dutton@gmail.com>
Date: Thu, 30 Nov 2017 22:56:04 +0000
Subject: [PATCH] libavformat/segment: strftime date sub-directories

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"
---
 libavformat/segment.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 81d3f1d..f8484bf 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -186,6 +186,39 @@  static int segment_mux_init(AVFormatContext *s)
     return 0;
 }
 
+static int mkdir_p(const char *path) {
+    int ret = 0;
+    char *temp = av_strdup(path);
+    char *pos = temp;
+    char tmp_ch = '\0';
+
+    if (!path || !temp) {
+        return -1;
+    }
+
+    if (!strncmp(temp, "/", 1) || !strncmp(temp, "\\", 1)) {
+        pos++;
+    } else if (!strncmp(temp, "./", 2) || !strncmp(temp, ".\\", 2)) {
+        pos += 2;
+    }
+
+    for ( ; *pos != '\0'; ++pos) {
+        if (*pos == '/' || *pos == '\\') {
+            tmp_ch = *pos;
+            *pos = '\0';
+            ret = mkdir(temp, 0755);
+            *pos = tmp_ch;
+        }
+    }
+
+    if ((*(pos - 1) != '/') || (*(pos - 1) != '\\')) {
+        ret = mkdir(temp, 0755);
+    }
+
+    av_free(temp);
+    return ret;
+}
+
 static int set_segment_filename(AVFormatContext *s)
 {
     SegmentContext *seg = s->priv_data;
@@ -198,12 +231,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(oc->filename, sizeof(oc->filename), s->filename, 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(oc->filename);
+        if (!fn_copy) {
+            return AVERROR(ENOMEM);
+        }
+        dir = av_dirname(fn_copy);
+        if (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(oc->filename, sizeof(oc->filename),
                                      s->filename, seg->segment_idx) < 0) {
         av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", s->filename);
-- 
2.7.4