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

2021-12-21 Thread James Dutton
Hi,

This is a follow on from:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/caamvbhg9qsksxfuzrt3resrr89j5scyd84ec6olearqx4cu...@mail.gmail.com/


On Tue, 21 Dec 2021 at 21:39, James Dutton  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 
> ---
>  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();
>  tm = localtime_r(, );
>  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-requ...@ffmpeg.org with subject "unsubscribe".


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

2018-09-27 Thread Steven Liu
Steven Liu  于2018年9月27日周四 下午2:53写道:
>
> Steven Liu  于2018年9月27日周四 上午6:37写道:
> >
> >
> >
> > > On Sep 27, 2018, at 06:10, Michael Niedermayer  
> > > wrote:
> > >
> > > On Wed, Sep 26, 2018 at 10:07:58AM +0100, James Courtier-Dutton wrote:
> > >> On 26 September 2018 at 00:18, Steven Liu  wrote:
> > >>
> > >>>
> > >>>
> >  On Sep 26, 2018, at 06:49, James Courtier-Dutton 
> >  
> > >>> wrote:
> >  On 25 September 2018 at 23:24, Steven Liu  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 
> > >> 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 
> > >> ---
> > >> 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();
> > >> tm = localtime_r(, );
> > >> 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
> > There will have no error message, and cannot create directory on the HTTP 
> > server.
> > And the same problem is in hlsenc, I think this is a good question, let me 
> > think about how to fix it.
>
> Have checked, that should be ok for http:
>
> MacBook:xxx StevenLiu$ sudo ls
> /usr/local/nginx/html/StevenLiu_test/output_dir/Subdir/SubSubdir/
> Password:
> ls: /usr/local/nginx/html/StevenLiu_test/output_dir/Subdir/SubSubdir/:
> No such file or directory
> MacBook:xxx StevenLiu$ sudo ls
> /usr/local/nginx/html/StevenLiu_test/output_dir/Subdir/
> ls: /usr/local/nginx/html/StevenLiu_test/output_dir/Subdir/: No such
> file or directory
> MacBook:xxx StevenLiu$ sudo ls 
> /usr/local/nginx/html/StevenLiu_test/output_dir/
> ls: /usr/local/nginx/html/StevenLiu_test/output_dir/: No such file or 
> directory
> MacBook:xxx StevenLiu$ sudo ls /usr/local/nginx/html/StevenLiu_test/
> ls: /usr/local/nginx/html/StevenLiu_test/: No such file or directory
> MacBook:xxx StevenLiu$ ./ffmpeg -re -i ~/Movies/objectC/facebook.mp4
> -c:v h264_videotoolbox -g 15 -f hls -hls_time 2 -t 10 -method PUT
> http://127.0.0.1/StevenLiu_test/output_dir/Subdir/SubSubdir/output_test.m3u8
> ffmpeg version N-92065-g476a77128a Copyright (c) 2000-2018 the FFmpeg 
> developers
>   built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
>   configuration: --enable-libass --enable-opengl --enable-libx264
> --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local
> --enable-libtesseract --enable-libspeex --enable-libfreetype
> --enable-libfontconfig --enable-libfdk-aac --enable-videotoolbox
> --enable-libxml2 --enable-librsvg --enable-libtensorflow
>   libavutil  56. 19.101 / 56. 19.101
>   libavcodec 58. 31.101 / 58. 31.101
>   libavformat58. 18.103 / 58. 18.103
>   libavdevice58.  4.104 / 58.  4.104
>   libavfilter 7. 33.100 /  7. 33.100
>   libswscale  5.  2.100 / 

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

2018-09-27 Thread Steven Liu
Steven Liu  于2018年9月27日周四 上午6:37写道:
>
>
>
> > On Sep 27, 2018, at 06:10, Michael Niedermayer  
> > wrote:
> >
> > On Wed, Sep 26, 2018 at 10:07:58AM +0100, James Courtier-Dutton wrote:
> >> On 26 September 2018 at 00:18, Steven Liu  wrote:
> >>
> >>>
> >>>
>  On Sep 26, 2018, at 06:49, James Courtier-Dutton 
> >>> wrote:
>  On 25 September 2018 at 23:24, Steven Liu  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 
> >> 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 
> >> ---
> >> 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();
> >> tm = localtime_r(, );
> >> 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
> There will have no error message, and cannot create directory on the HTTP 
> server.
> And the same problem is in hlsenc, I think this is a good question, let me 
> think about how to fix it.

Have checked, that should be ok for http:

MacBook:xxx StevenLiu$ sudo ls
/usr/local/nginx/html/StevenLiu_test/output_dir/Subdir/SubSubdir/
Password:
ls: /usr/local/nginx/html/StevenLiu_test/output_dir/Subdir/SubSubdir/:
No such file or directory
MacBook:xxx StevenLiu$ sudo ls
/usr/local/nginx/html/StevenLiu_test/output_dir/Subdir/
ls: /usr/local/nginx/html/StevenLiu_test/output_dir/Subdir/: No such
file or directory
MacBook:xxx StevenLiu$ sudo ls /usr/local/nginx/html/StevenLiu_test/output_dir/
ls: /usr/local/nginx/html/StevenLiu_test/output_dir/: No such file or directory
MacBook:xxx StevenLiu$ sudo ls /usr/local/nginx/html/StevenLiu_test/
ls: /usr/local/nginx/html/StevenLiu_test/: No such file or directory
MacBook:xxx StevenLiu$ ./ffmpeg -re -i ~/Movies/objectC/facebook.mp4
-c:v h264_videotoolbox -g 15 -f hls -hls_time 2 -t 10 -method PUT
http://127.0.0.1/StevenLiu_test/output_dir/Subdir/SubSubdir/output_test.m3u8
ffmpeg version N-92065-g476a77128a Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
  configuration: --enable-libass --enable-opengl --enable-libx264
--enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local
--enable-libtesseract --enable-libspeex --enable-libfreetype
--enable-libfontconfig --enable-libfdk-aac --enable-videotoolbox
--enable-libxml2 --enable-librsvg --enable-libtensorflow
  libavutil  56. 19.101 / 56. 19.101
  libavcodec 58. 31.101 / 58. 31.101
  libavformat58. 18.103 / 58. 18.103
  libavdevice58.  4.104 / 58.  4.104
  libavfilter 7. 33.100 /  7. 33.100
  libswscale  5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc55.  2.100 / 55.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'/Users/StevenLiu/Movies/objectC/facebook.mp4':
  Metadata:
major_brand : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder   

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

2018-09-26 Thread Steven Liu


> On Sep 27, 2018, at 06:10, Michael Niedermayer  wrote:
> 
> On Wed, Sep 26, 2018 at 10:07:58AM +0100, James Courtier-Dutton wrote:
>> On 26 September 2018 at 00:18, Steven Liu  wrote:
>> 
>>> 
>>> 
 On Sep 26, 2018, at 06:49, James Courtier-Dutton 
>>> wrote:
 On 25 September 2018 at 23:24, Steven Liu  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 
>> 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 
>> ---
>> 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();
>> tm = localtime_r(, );
>> 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
There will have no error message, and cannot create directory on the HTTP 
server.
And the same problem is in hlsenc, I think this is a good question, let me 
think about how to fix it.
> 
> [...]
> 
> 
> -- 
> 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
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Thanks
Steven





___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-26 Thread Michael Niedermayer
On Wed, Sep 26, 2018 at 10:07:58AM +0100, James Courtier-Dutton wrote:
> On 26 September 2018 at 00:18, Steven Liu  wrote:
> 
> >
> >
> > > On Sep 26, 2018, at 06:49, James Courtier-Dutton 
> > wrote:
> > > On 25 September 2018 at 23:24, Steven Liu  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 
> 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 
> ---
>  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();
>  tm = localtime_r(, );
>  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


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-26 Thread Steven Liu
James Courtier-Dutton  于2018年9月26日周三 下午5:08写道:
>
> On 26 September 2018 at 00:18, Steven Liu  wrote:
>
> >
> >
> > > On Sep 26, 2018, at 06:49, James Courtier-Dutton 
> > wrote:
> > > On 25 September 2018 at 23:24, Steven Liu  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.
LGTM
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-26 Thread James Courtier-Dutton
On 26 September 2018 at 00:18, Steven Liu  wrote:

>
>
> > On Sep 26, 2018, at 06:49, James Courtier-Dutton 
> wrote:
> > On 25 September 2018 at 23:24, Steven Liu  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.
From 8d8ea7d1f87a77ee23b6681a714da378b5361e4d Mon Sep 17 00:00:00 2001
From: James Courtier-Dutton 
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 
---
 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();
 tm = localtime_r(, );
 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);
 } 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.7.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-25 Thread Steven Liu


> On Sep 26, 2018, at 06:49, James Courtier-Dutton  
> wrote:
> 
> 
> 
> On 25 September 2018 at 23:24, Steven Liu  wrote:
> @@ -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();
> tm = localtime_r(, );
> ==^^^ This is the time it uses. No command like option. 
of course i know this line.
> 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);
> ==look at here, what dose this error message mean?
I just think this error message is not a good message, because there have no 
use_localtime_mkdir for libavformat/segment.c
> 
> That is saying that the ff_mkdir_p  call failed.
> If the error message is confusing, we can change it to:
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);
> 

Thanks
Steven





___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-25 Thread Steven Liu


> On Sep 26, 2018, at 00:52, James Courtier-Dutton  
> 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"
>> 
>> 
>> 
>> 
>> Maybe you want add an option named “strftime_mkdir” not
>> “use_localtime_mkdir”.
>> You should add the option describe into doc/muxer.texi
>> 
>> reference to: https://trac.ffmpeg.org/ticket/7393
>> 
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> Thanks
>> Steven
>> 
>> Hi Steven,
> 
> I don't understand what you are suggesting?


Signed-off-by: James Courtier-Dutton 
---
libavformat/segment.c | 15 +++
1 file changed, 15 insertions(+)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 7fb4dc7..57fce8d 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();
tm = localtime_r(, );
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);
==look at here, what dose this error message mean?




+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.7.4



> There are no extra command line options to enable this feature.
> It just works it out from the format string.
> If you put a "/" in the format string, it creates the directories for you.
> As per my example command line above.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Thanks
Steven





___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-25 Thread James Courtier-Dutton
>
> 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"
>
>
>
>
> Maybe you want add an option named “strftime_mkdir” not
> “use_localtime_mkdir”.
> You should add the option describe into doc/muxer.texi
>
> reference to: https://trac.ffmpeg.org/ticket/7393
>
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> Thanks
> Steven
>
> Hi Steven,

I don't understand what you are suggesting?
There are no extra command line options to enable this feature.
It just works it out from the format string.
If you put a "/" in the format string, it creates the directories for you.
As per my example command line above.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-25 Thread Steven Liu


> On Sep 25, 2018, at 22:37, James Courtier-Dutton  
> wrote:
> 
> Updated patch.
> This one applies on top of
> commit bb660800a55f5171f77316941afe2e62534ee72c
> 
> 
> On 25 September 2018 at 15:00, Steven Liu  wrote:
> 
>> 
>> 
>>> On Sep 25, 2018, at 20:33, James Courtier-Dutton 
>> wrote:
>>> 
>>> On 25 September 2018 at 10:22, Moritz Barsnick  wrote:
>>> 
 
 Steven already posted a patch proposal to this list, factoring out the
 function:
 https://patchwork.ffmpeg.org/patch/10471/
 http://ffmpeg.org/pipermail/ffmpeg-devel/2018-September/234538.html
 
 
>>> That looks fine by me. I can resubmit my segment.c patch once 10471
>> reaches
>>> master tree or at least somewhere I can cherry pick from.
>>> 
>>> Kind Regards
>>> 
>>> James
>>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> Okay, you can go on do this, i have pushed that patch.
>> 
>> Thanks
>> Steven
>> 
>> 
>> 
>> 
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
> <0001-avformat-segment-strftime-date-sub-directories.patch>___


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

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 7fb4dc7..57fce8d 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();
 tm = localtime_r(, );
 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.7.4





Maybe you want add an option named “strftime_mkdir” not “use_localtime_mkdir”.
You should add the option describe into doc/muxer.texi

reference to: https://trac.ffmpeg.org/ticket/7393

> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Thanks
Steven





___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-25 Thread James Courtier-Dutton
Updated patch.
This one applies on top of
commit bb660800a55f5171f77316941afe2e62534ee72c


On 25 September 2018 at 15:00, Steven Liu  wrote:

>
>
> > On Sep 25, 2018, at 20:33, James Courtier-Dutton 
> wrote:
> >
> > On 25 September 2018 at 10:22, Moritz Barsnick  wrote:
> >
> >>
> >> Steven already posted a patch proposal to this list, factoring out the
> >> function:
> >> https://patchwork.ffmpeg.org/patch/10471/
> >> http://ffmpeg.org/pipermail/ffmpeg-devel/2018-September/234538.html
> >>
> >>
> > That looks fine by me. I can resubmit my segment.c patch once 10471
> reaches
> > master tree or at least somewhere I can cherry pick from.
> >
> > Kind Regards
> >
> > James
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> Okay, you can go on do this, i have pushed that patch.
>
> Thanks
> Steven
>
>
>
>
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
From 292a7802fe906399fb59267eb87d93624920409d Mon Sep 17 00:00:00 2001
From: James Courtier-Dutton 
Date: Tue, 25 Sep 2018 15:32:16 +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 
---
 libavformat/segment.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 7fb4dc7..57fce8d 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();
 tm = localtime_r(, );
 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.7.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-25 Thread Steven Liu


> On Sep 25, 2018, at 20:33, James Courtier-Dutton  
> wrote:
> 
> On 25 September 2018 at 10:22, Moritz Barsnick  wrote:
> 
>> 
>> Steven already posted a patch proposal to this list, factoring out the
>> function:
>> https://patchwork.ffmpeg.org/patch/10471/
>> http://ffmpeg.org/pipermail/ffmpeg-devel/2018-September/234538.html
>> 
>> 
> That looks fine by me. I can resubmit my segment.c patch once 10471 reaches
> master tree or at least somewhere I can cherry pick from.
> 
> Kind Regards
> 
> James
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Okay, you can go on do this, i have pushed that patch.

Thanks
Steven





___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-25 Thread James Courtier-Dutton
On 25 September 2018 at 10:22, Moritz Barsnick  wrote:

>
> Steven already posted a patch proposal to this list, factoring out the
> function:
> https://patchwork.ffmpeg.org/patch/10471/
> http://ffmpeg.org/pipermail/ffmpeg-devel/2018-September/234538.html
>
>
That looks fine by me. I can resubmit my segment.c patch once 10471 reaches
master tree or at least somewhere I can cherry pick from.

Kind Regards

James
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-25 Thread Moritz Barsnick
On Tue, Sep 25, 2018 at 08:49:25 +, Jeyapal, Karthick wrote:
> > It is a duplicate from hisenc.c.  hisenc already has this "create
> > sub-directories" feature, but I needed it for the segment use case.
> > I made it static so that it would be treated as local to the .c file.
> > I don't know ffmpeg well enough to know how best to de-duplicate it.
> > I am happy to update my patch, if someone can give me a pointer as to what
> > to do.
> 
> When faced with a similar situation, I created a new file(.c and .h) with 
> those function made global within libavformat(prefix it with ff_).
> Then these functions could be used by both hlsenc.c and other files inside 
> the libavformat library. 
> You could refer to below commit as a pointer
> https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/da49cdf6401ea3caa616c226f24dfb407633acd0

Steven already posted a patch proposal to this list, factoring out the
function:
https://patchwork.ffmpeg.org/patch/10471/
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-September/234538.html

Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-25 Thread Jeyapal, Karthick

On 9/25/18 12:28 AM, James Courtier-Dutton wrote:
> On 24 September 2018 at 13:48, Moritz Barsnick  wrote:
>
>> On Mon, Sep 24, 2018 at 12:39:42 +0100, James Courtier-Dutton 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"
>> [...]
>>> +static int mkdir_p(const char *path) {
>>
>> Is this code duplicated from libavformat/hlsenc.c?
>>
>> I don't know what the policy is, and how code from hls vs. segment has
>> been deduplicated previously, but it seems like this is a candidate for
>> being careful.
>>
>>
> It is a duplicate from hisenc.c.  hisenc already has this "create
> sub-directories" feature, but I needed it for the segment use case.
> I made it static so that it would be treated as local to the .c file.
> I don't know ffmpeg well enough to know how best to de-duplicate it.
> I am happy to update my patch, if someone can give me a pointer as to what
> to do.

When faced with a similar situation, I created a new file(.c and .h) with those 
function made global within libavformat(prefix it with ff_).
Then these functions could be used by both hlsenc.c and other files inside the 
libavformat library. 
You could refer to below commit as a pointer
https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/da49cdf6401ea3caa616c226f24dfb407633acd0

>
> Kind Regards
>
> James
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-24 Thread James Courtier-Dutton
On 24 September 2018 at 13:48, Moritz Barsnick  wrote:

> On Mon, Sep 24, 2018 at 12:39:42 +0100, James Courtier-Dutton 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"
> [...]
> > +static int mkdir_p(const char *path) {
>
> Is this code duplicated from libavformat/hlsenc.c?
>
> I don't know what the policy is, and how code from hls vs. segment has
> been deduplicated previously, but it seems like this is a candidate for
> being careful.
>
>
It is a duplicate from hisenc.c.  hisenc already has this "create
sub-directories" feature, but I needed it for the segment use case.
I made it static so that it would be treated as local to the .c file.
I don't know ffmpeg well enough to know how best to de-duplicate it.
I am happy to update my patch, if someone can give me a pointer as to what
to do.

Kind Regards

James
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-24 Thread Moritz Barsnick
On Mon, Sep 24, 2018 at 12:39:42 +0100, James Courtier-Dutton 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"
[...]
> +static int mkdir_p(const char *path) {

Is this code duplicated from libavformat/hlsenc.c?

I don't know what the policy is, and how code from hls vs. segment has
been deduplicated previously, but it seems like this is a candidate for
being careful.

Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-24 Thread James Courtier-Dutton
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 
wrote:

> On Thu, Nov 30, 2017 at 11:07:03PM +, 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 
> > Date: Thu, 30 Nov 2017 22:56:04 +
> > 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
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-24 Thread James Courtier-Dutton

From 6c74670e047bfc9e995c0f968c1688be768d13bd Mon Sep 17 00:00:00 2001
From: James Courtier-Dutton 
Date: Mon, 24 Sep 2018 12:34:54 +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 
---
 libavformat/segment.c | 48 
 1 file changed, 48 insertions(+)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 7fb4dc7..b2300d9 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;
@@ -200,12 +233,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();
 tm = localtime_r(, );
 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 (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.7.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-09-22 Thread Michael Niedermayer
On Thu, Nov 30, 2017 at 11:07:03PM +, 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 
> Date: Thu, 30 Nov 2017 22:56:04 +
> 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


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel