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

Michael Niedermayer michael at niedermayer.cc
Thu Sep 27 01:10:19 EEST 2018


On Wed, Sep 26, 2018 at 10:07:58AM +0100, James Courtier-Dutton wrote:
> On 26 September 2018 at 00:18, Steven Liu <lq at chinaffmpeg.org> wrote:
> 
> >
> >
> > > On Sep 26, 2018, at 06:49, James Courtier-Dutton <james.dutton at gmail.com>
> > wrote:
> > > On 25 September 2018 at 23:24, Steven Liu <lq at chinaffmpeg.org> wrote:
> > yes, the error message is confusing, maybe change it here is better.
> > >
> > > +            av_log(oc, AV_LOG_ERROR, "Could not create directory %s\n",
> > dir);
> > >
> >
> >
> Attached patch has the changed error message.

>  segment.c |   15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> a026d4ed5e2ba0505f93a3eece153a567707b812  0001-avformat-segment-strftime-date-sub-directories.patch
> From 8d8ea7d1f87a77ee23b6681a714da378b5361e4d Mon Sep 17 00:00:00 2001
> From: James Courtier-Dutton <James.Dutton at gmail.com>
> Date: Wed, 26 Sep 2018 10:05:13 +0100
> Subject: [PATCH] avformat/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"
> 
> Signed-off-by: James Courtier-Dutton <James.Dutton at gmail.com>
> ---
>  libavformat/segment.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/libavformat/segment.c b/libavformat/segment.c
> index 7fb4dc7..0e17380 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -200,12 +200,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\n", dir);
> +            av_free(fn_copy);
> +            return AVERROR(errno);
> +        }
> +        av_free(fn_copy);

How does this interact with urls that are not the file protocol ?

I see that this starts out with s->url and then seems to simply treat it as
if it was a local file. Its quite possible iam missing something but url != filename

[...]


-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180927/3ec7443f/attachment.sig>


More information about the ffmpeg-devel mailing list