Re: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (4th attempt)
On Sun, Feb 04, 2018 at 12:51:59PM +, Dr. Alan Barclay wrote: > On 17/01/2018 11:15, Carl Eugen Hoyos wrote: > >2018-01-17 11:56 GMT+01:00 Dr. Alan Barclay: > > > >>Attached in a further patch - adding the error checks. > > > >Please merge this patch into your previous patch. > > Both patches updated. > > Alan. > > >And please avoid top-posting here, Carl Eugen > >___ > >ffmpeg-devel mailing list > >ffmpeg-devel@ffmpeg.org > >http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > [...] > diff --git a/libavformat/internal.h b/libavformat/internal.h > index 1e2a3e05a1..2e8fa85d08 100644 > --- a/libavformat/internal.h > +++ b/libavformat/internal.h > @@ -703,4 +703,11 @@ int ff_unlock_avformat(void); > */ > void ff_format_set_url(AVFormatContext *s, char *url); > > +/** > + * Make the specified directory. > + * > + * @param path path for directory > + */ > +int ff_mkdir_p(const char *path); the return code and its relation to errno should be documented or better the function should return the error code like all other functions in ffmpeg and not depend on errno also the relation of pathes and url needs to be documented is a "file://..." working or should it be a file path [...] > img2enc.c | 16 > 1 file changed, 16 insertions(+) > 020db7642303243c3e0170376d0826158e44616f > 0002-Adding-mkdir-option-for-img2enc.patch > From 0b35e014cf36499f0b4b5e064b7f0ce71287649a Mon Sep 17 00:00:00 2001 > From: "Dr. Alan Barclay" > Date: Sun, 4 Feb 2018 12:21:51 + > Subject: [PATCH 2/2] Adding mkdir option for img2enc. update to doc/muxers.texi is missing > > --- > libavformat/img2enc.c | 16 > 1 file changed, 16 insertions(+) > > diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c > index a09cc8ec50..8f3fd98018 100644 > --- a/libavformat/img2enc.c > +++ b/libavformat/img2enc.c > @@ -42,6 +42,7 @@ typedef struct VideoMuxData { > char target[4][1024]; > int update; > int use_strftime; > +int use_mkdir; > int frame_pts; > const char *muxer; > int use_rename; > @@ -114,6 +115,20 @@ static int write_packet(AVFormatContext *s, AVPacket > *pkt) > img->img_number, img->path); > return AVERROR(EINVAL); > } > +if (img->use_mkdir) { > +const char *temp_path; > +char *temp_filename = av_strdup(filename); > +if (!temp_filename) { > +return AVERROR(ENOMEM); > +} > +temp_path = av_dirname(temp_filename); > +if (ff_mkdir_p(temp_path) == -1 && errno != EEXIST) { > +av_log(s, AV_LOG_ERROR, "Could not create directory %s\n", > temp_path); > +av_free(temp_filename); > +return AVERROR(errno); > +} > +av_free(temp_filename); > +} > for (i = 0; i < 4; i++) { > snprintf(img->tmp[i], sizeof(img->tmp[i]), "%s.tmp", filename); > av_strlcpy(img->target[i], filename, sizeof(img->target[i])); > @@ -212,6 +227,7 @@ static const AVOption muxoptions[] = { > { "update", "continuously overwrite one file", OFFSET(update), > AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, > { "start_number", "set first number in the sequence", > OFFSET(img_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, ENC }, > { "strftime", "use strftime for filename", OFFSET(use_strftime), > AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, > +{ "mkdir","make sub-dirs as required", OFFSET(use_mkdir), > AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, > { "frame_pts","use current frame pts for filename", > OFFSET(frame_pts), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, > { "atomic_writing", "write files atomically (using temporary files and > renames)", OFFSET(use_rename), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, > { NULL }, > -- > 2.11.0 > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Democracy is the form of government in which you can choose your dictator signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (4th attempt)
On 17/01/2018 11:15, Carl Eugen Hoyos wrote: 2018-01-17 11:56 GMT+01:00 Dr. Alan Barclay: Attached in a further patch - adding the error checks. Please merge this patch into your previous patch. Both patches updated. Alan. And please avoid top-posting here, Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel -- Dr. Alan Barclay Electric Scribe Ltd. 118 Stanley Street Aberdeen AB10 6UQ, U.K. +44 1224 591779 office +44 7803 606485 mobile a...@escribe.co.uk From 79d3ef8419e806abbc6c55fc563d04a6879feb15 Mon Sep 17 00:00:00 2001 From: "Dr. Alan Barclay" Date: Sun, 4 Feb 2018 12:07:55 + Subject: [PATCH 1/2] Move mkdir_p(), renamed ff_mkdir_p(), from hlsenc.c to utils.c. --- libavformat/hlsenc.c | 37 ++--- libavformat/internal.h | 7 +++ libavformat/utils.c| 33 + 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index cc13c94e97..a51248ec02 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -225,39 +225,6 @@ typedef struct HLSContext { AVIOContext *sub_m3u8_out; } HLSContext; -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 hlsenc_io_open(AVFormatContext *s, AVIOContext **pb, char *filename, AVDictionary **options) { HLSContext *hls = s->priv_data; @@ -1504,7 +1471,7 @@ static int hls_start(AVFormatContext *s, VariantStream *vs) return AVERROR(ENOMEM); } dir = av_dirname(fn_copy); -if (mkdir_p(dir) == -1 && errno != EEXIST) { +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); @@ -1730,7 +1697,7 @@ static int format_name(char *buf, int buf_len, int index) } dir = av_dirname(mod_buf_dup); -if (mkdir_p(dir) == -1 && errno != EEXIST) { +if (ff_mkdir_p(dir) == -1 && errno != EEXIST) { ret = AVERROR(errno); goto fail; } diff --git a/libavformat/internal.h b/libavformat/internal.h index 1e2a3e05a1..2e8fa85d08 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -703,4 +703,11 @@ int ff_unlock_avformat(void); */ void ff_format_set_url(AVFormatContext *s, char *url); +/** + * Make the specified directory. + * + * @param path path for directory + */ +int ff_mkdir_p(const char *path); + #endif /* AVFORMAT_INTERNAL_H */ diff --git a/libavformat/utils.c b/libavformat/utils.c index 28ea071409..11bacdf1b4 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -5658,3 +5658,36 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif } + +int ff_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; +} -- 2.11.0 From 0b35e014cf36499f0b4b5e064b7f0ce71287649a Mon Sep 17 00:00:00 2001 From: "Dr. Alan Barclay" Date: Sun, 4 Feb 2018 12:21:51 + Subject: [PATCH 2/2] Adding mkdir option for img2enc. --- libavformat/img2enc.c | 16 1 file changed, 16 insertions(+) diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index a09cc8ec50..8f3fd98018 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -42,6 +42,7 @@ typedef struct VideoMuxData { char target[4][1024]; int update;
Re: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (3rd attempt)
On Wed, 17 Jan 2018, Dr. Alan Barclay wrote: Hi, Attached in a further patch - adding the error checks. Derek - I don't think there is a functional downside to this 'mkdir' option being a default behaviour, but it would introduce a minor performance penalty (which users maybe don't want). I'd rather keep the mkdir functionality disabled by default, from a security standpoint I don't really like the idea of an ordinary muxer creating dirs, replacing parts of the path as default behaviour... Thanks, Marton All comments and help appreciated. Thanks and Regards, Alan. On 27/12/2017 16:01, Derek Buitenhuis wrote: Hi, On 12/27/2017 12:27 PM, Dr Alan Barclay wrote: Resending the two (git format-patch) patches, without the top lines removed (which I thought I needed to do as some patch emails didn't seem to have them). All comments and help appreciated. [...] Subject: [PATCH 1/2] Move mkdir_p (renamed ff_mkdir_p) from hlsenc.c to utils.c. --- libavformat/hlsenc.c | 35 +-- libavformat/internal.h | 7 +++ libavformat/utils.c| 33 + 3 files changed, 41 insertions(+), 34 deletions(-) On a technical level, this patch looks OK. Subject: [PATCH 2/2] Adding mkdir option for img2enc. --- libavformat/img2enc.c | 8 1 file changed, 8 insertions(+) I'm not sure how others feel about the premise (mkdir in img2enc). I personally don't mind - though, maybe it should be default instead of an option? (Maybe a bad idea.) +if (img->use_mkdir) { +char *temp_filename = av_strdup(filename); +const char *temp_path = av_dirname(temp_filename); +ff_mkdir_p(temp_path); +av_free(temp_filename); +} This lacks error checks for av_strdup and ff_mkdir_p. - Derek ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel -- Dr. Alan Barclay Electric Scribe Ltd. 118 Stanley Street Aberdeen AB10 6UQ, U.K. +44 1224 591779 office +44 7803 606485 mobile a...@escribe.co.uk ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (3rd attempt)
2018-01-17 11:56 GMT+01:00 Dr. Alan Barclay: > Attached in a further patch - adding the error checks. Please merge this patch into your previous patch. And please avoid top-posting here, Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (3rd attempt)
Hi, Attached in a further patch - adding the error checks. Derek - I don't think there is a functional downside to this 'mkdir' option being a default behaviour, but it would introduce a minor performance penalty (which users maybe don't want). All comments and help appreciated. Thanks and Regards, Alan. On 27/12/2017 16:01, Derek Buitenhuis wrote: Hi, On 12/27/2017 12:27 PM, Dr Alan Barclay wrote: Resending the two (git format-patch) patches, without the top lines removed (which I thought I needed to do as some patch emails didn't seem to have them). All comments and help appreciated. [...] Subject: [PATCH 1/2] Move mkdir_p (renamed ff_mkdir_p) from hlsenc.c to utils.c. --- libavformat/hlsenc.c | 35 +-- libavformat/internal.h | 7 +++ libavformat/utils.c| 33 + 3 files changed, 41 insertions(+), 34 deletions(-) On a technical level, this patch looks OK. Subject: [PATCH 2/2] Adding mkdir option for img2enc. --- libavformat/img2enc.c | 8 1 file changed, 8 insertions(+) I'm not sure how others feel about the premise (mkdir in img2enc). I personally don't mind - though, maybe it should be default instead of an option? (Maybe a bad idea.) +if (img->use_mkdir) { +char *temp_filename = av_strdup(filename); +const char *temp_path = av_dirname(temp_filename); +ff_mkdir_p(temp_path); +av_free(temp_filename); +} This lacks error checks for av_strdup and ff_mkdir_p. - Derek ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel -- Dr. Alan Barclay Electric Scribe Ltd. 118 Stanley Street Aberdeen AB10 6UQ, U.K. +44 1224 591779 office +44 7803 606485 mobile a...@escribe.co.uk From a85be3fbf11f40567370c58f6c7e72d7edbd3109 Mon Sep 17 00:00:00 2001 From: "Dr. Alan Barclay"Date: Wed, 17 Jan 2018 10:44:17 + Subject: [PATCH 2/2] Added error checking for mkdir option. --- libavformat/img2enc.c | 12 ++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index a8ee064396..9de2c8f356 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -116,9 +116,17 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EINVAL); } if (img->use_mkdir) { +const char *temp_path; char *temp_filename = av_strdup(filename); -const char *temp_path = av_dirname(temp_filename); -ff_mkdir_p(temp_path); +if (!temp_filename) { +return AVERROR(ENOMEM); +} +temp_path = av_dirname(temp_filename); +if (ff_mkdir_p(temp_path) == -1 && errno != EEXIST) { +av_log(s, AV_LOG_ERROR, "Could not create directory %s\n", temp_path); +av_free(temp_filename); +return AVERROR(errno); +} av_free(temp_filename); } for (i = 0; i < 4; i++) { -- 2.11.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (2nd attempt)
Hi, On 12/27/2017 12:27 PM, Dr Alan Barclay wrote: > Resending the two (git format-patch) patches, without the top lines > removed (which I thought I needed to do as some patch emails didn't seem > to have them). > > All comments and help appreciated. [...] > Subject: [PATCH 1/2] Move mkdir_p (renamed ff_mkdir_p) from hlsenc.c to > utils.c. > > --- > libavformat/hlsenc.c | 35 +-- > libavformat/internal.h | 7 +++ > libavformat/utils.c| 33 + > 3 files changed, 41 insertions(+), 34 deletions(-) On a technical level, this patch looks OK. > Subject: [PATCH 2/2] Adding mkdir option for img2enc. > > --- > libavformat/img2enc.c | 8 > 1 file changed, 8 insertions(+) I'm not sure how others feel about the premise (mkdir in img2enc). I personally don't mind - though, maybe it should be default instead of an option? (Maybe a bad idea.) > +if (img->use_mkdir) { > +char *temp_filename = av_strdup(filename); > +const char *temp_path = av_dirname(temp_filename); > +ff_mkdir_p(temp_path); > +av_free(temp_filename); > +} This lacks error checks for av_strdup and ff_mkdir_p. - Derek ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (2nd attempt)
Hi, Resending the two (git format-patch) patches, without the top lines removed (which I thought I needed to do as some patch emails didn't seem to have them). All comments and help appreciated. Thanks and Regards, Alan. On 27/12/17 01:41, Michael Niedermayer wrote: On Tue, Dec 26, 2017 at 10:44:31PM +, Dr Alan Barclay wrote: Hi All, Please would someone with an interest in img2enc take a look at my revised patches for a minor feature addition and consider committing it to the main line for me. Example: ffmpeg -i ~/trailer.mp4 -strftime 1 -mkdir 1 %Y/%m/%d/out_%H-%M-%S.jpg Without the new mkdir option, this command will fail if the directory hierarchy for the jpg files does not already exist, which can be difficult to predict for time-stamped directories. This patch adds a mkdir option to img2enc which invites it to make whatever directory hierarchy is necessary for each output file. When used in conjunction with the strftime then the jpg files will be located in a newly created (time-stamped) directory as processing progresses. My typical usage scenario is capturing a long-running live video feed (perhaps time-lapsed) and storing the resulting images in a time-stamped directory hierarchy fashion, rather than as a numbered sequence of files in a single directory. If you look at the code you will see that only a half dozen lines of code were required in img2enc. The function for creating directories already existed in hlsenc.c but I've moved into utils.c as I presumed that was a more generic location for it. All comments appreciated. Thanks ad Regards, Alan. On 17/12/17 22:46, Carl Eugen Hoyos wrote: 2017-12-17 23:41 GMT+01:00 Dr Alan Barclay: Please would someone with an interest in img2enc take a look at my minor feature addition and consider committing it to the main line for me. To be acceptable, the patch has to be split in two and please move the definition into internal.h Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel hlsenc.c | 35 +-- internal.h |7 +++ utils.c| 33 + 3 files changed, 41 insertions(+), 34 deletions(-) 9560fd03958f79f77b01c0e02c55d98e3dc7b937 0001-Move-mkdir_p-renamed-ff_mkdir_p-from-hlsenc.c-to-uti.patch --- libavformat/hlsenc.c | 35 +-- libavformat/internal.h | 7 +++ libavformat/utils.c| 33 + 3 files changed, 41 insertions(+), 34 deletions(-) these patches are missing commit messages patches should be genrated with git format-patch or git send-email [...] ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >From 70675348150c43f898ee97466c123fbf7ff65bcb Mon Sep 17 00:00:00 2001 From: "Dr. Alan Barclay" Date: Tue, 26 Dec 2017 22:17:59 + Subject: [PATCH 1/2] Move mkdir_p (renamed ff_mkdir_p) from hlsenc.c to utils.c. --- libavformat/hlsenc.c | 35 +-- libavformat/internal.h | 7 +++ libavformat/utils.c| 33 + 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index bbc2742dc7..633ddc309e 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -208,39 +208,6 @@ typedef struct HLSContext { AVIOContext *sub_m3u8_out; } HLSContext; -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 is_http_proto(char *filename) { const char *proto = avio_find_protocol_name(filename); return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0; @@ -1407,7 +1374,7 @@ static int hls_start(AVFormatContext *s, VariantStream *vs) return AVERROR(ENOMEM); } dir = av_dirname(fn_copy); -if (mkdir_p(dir) == -1 && errno != EEXIST) { +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);
Re: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (2nd attempt)
On Tue, Dec 26, 2017 at 10:44:31PM +, Dr Alan Barclay wrote: > Hi All, > > Please would someone with an interest in img2enc take a look at my revised > patches for a minor feature addition and consider committing it to the main > line for me. > > Example: > ffmpeg -i ~/trailer.mp4 -strftime 1 -mkdir 1 %Y/%m/%d/out_%H-%M-%S.jpg > > Without the new mkdir option, this command will fail if the directory > hierarchy for the jpg files does not already exist, which can be difficult > to predict for time-stamped directories. > > This patch adds a mkdir option to img2enc which invites it to make whatever > directory hierarchy is necessary for each output file. When used in > conjunction with the strftime then the jpg files will be located in a newly > created (time-stamped) directory as processing progresses. > > My typical usage scenario is capturing a long-running live video feed > (perhaps time-lapsed) and storing the resulting images in a time-stamped > directory hierarchy fashion, rather than as a numbered sequence of files in > a single directory. > > If you look at the code you will see that only a half dozen lines of code > were required in img2enc. The function for creating directories already > existed in hlsenc.c but I've moved into utils.c as I presumed that was a > more generic location for it. > > All comments appreciated. > > Thanks ad Regards, > Alan. > > > On 17/12/17 22:46, Carl Eugen Hoyos wrote: > >2017-12-17 23:41 GMT+01:00 Dr Alan Barclay: > > > >>Please would someone with an interest in img2enc take a look > >>at my minor feature addition and consider committing it to the > >>main line for me. > >To be acceptable, the patch has to be split in two and please > >move the definition into internal.h > > > >Carl Eugen > >___ > >ffmpeg-devel mailing list > >ffmpeg-devel@ffmpeg.org > >http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > hlsenc.c | 35 +-- > internal.h |7 +++ > utils.c| 33 + > 3 files changed, 41 insertions(+), 34 deletions(-) > 9560fd03958f79f77b01c0e02c55d98e3dc7b937 > 0001-Move-mkdir_p-renamed-ff_mkdir_p-from-hlsenc.c-to-uti.patch > --- > libavformat/hlsenc.c | 35 +-- > libavformat/internal.h | 7 +++ > libavformat/utils.c| 33 + > 3 files changed, 41 insertions(+), 34 deletions(-) these patches are missing commit messages patches should be genrated with git format-patch or git send-email [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Elect your leaders based on what they did after the last election, not based on what they say before an election. signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (2nd attempt)
Hi All, Please would someone with an interest in img2enc take a look at my revised patches for a minor feature addition and consider committing it to the main line for me. Example: ffmpeg -i ~/trailer.mp4 -strftime 1 -mkdir 1 %Y/%m/%d/out_%H-%M-%S.jpg Without the new mkdir option, this command will fail if the directory hierarchy for the jpg files does not already exist, which can be difficult to predict for time-stamped directories. This patch adds a mkdir option to img2enc which invites it to make whatever directory hierarchy is necessary for each output file. When used in conjunction with the strftime then the jpg files will be located in a newly created (time-stamped) directory as processing progresses. My typical usage scenario is capturing a long-running live video feed (perhaps time-lapsed) and storing the resulting images in a time-stamped directory hierarchy fashion, rather than as a numbered sequence of files in a single directory. If you look at the code you will see that only a half dozen lines of code were required in img2enc. The function for creating directories already existed in hlsenc.c but I've moved into utils.c as I presumed that was a more generic location for it. All comments appreciated. Thanks ad Regards, Alan. On 17/12/17 22:46, Carl Eugen Hoyos wrote: 2017-12-17 23:41 GMT+01:00 Dr Alan Barclay: Please would someone with an interest in img2enc take a look at my minor feature addition and consider committing it to the main line for me. To be acceptable, the patch has to be split in two and please move the definition into internal.h Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel --- libavformat/hlsenc.c | 35 +-- libavformat/internal.h | 7 +++ libavformat/utils.c| 33 + 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index bbc2742dc7..633ddc309e 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -208,39 +208,6 @@ typedef struct HLSContext { AVIOContext *sub_m3u8_out; } HLSContext; -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 is_http_proto(char *filename) { const char *proto = avio_find_protocol_name(filename); return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0; @@ -1407,7 +1374,7 @@ static int hls_start(AVFormatContext *s, VariantStream *vs) return AVERROR(ENOMEM); } dir = av_dirname(fn_copy); -if (mkdir_p(dir) == -1 && errno != EEXIST) { +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); diff --git a/libavformat/internal.h b/libavformat/internal.h index e76ac12371..f471019a45 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -551,6 +551,13 @@ static inline int ff_rename(const char *oldpath, const char *newpath, void *logc } /** + * Make the specified directory. + * + * @param path path for directory + */ +int ff_mkdir_p(const char *path); + +/** * Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end * which is always set to 0. * diff --git a/libavformat/utils.c b/libavformat/utils.c index 84e49208b8..aac58010b2 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -5606,3 +5606,36 @@ FF_ENABLE_DEPRECATION_WARNINGS return st->internal->avctx->time_base; #endif } + +int ff_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,
Re: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc
2017-12-17 23:41 GMT+01:00 Dr Alan Barclay: > Please would someone with an interest in img2enc take a look > at my minor feature addition and consider committing it to the > main line for me. To be acceptable, the patch has to be split in two and please move the definition into internal.h Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] Adding mkdir option for img2enc
Hi All, Please would someone with an interest in img2enc take a look at my minor feature addition and consider committing it to the main line for me. Example: ffmpeg -i ~/trailer.mp4 -strftime 1 -mkdir 1 %Y/%m/%d/out_%H-%M-%S.jpg Without the new mkdir option, this command will fail if the directory hierarchy for the jpg files does not already exist, which can be difficult to predict for time-stamped directories. This patch adds a mkdir option to img2enc which invites it to make whatever directory hierarchy is necessary for each output file. When used in conjunction with the strftime then the jpg files will be located in a newly created (time-stamped) directory as processing progresses. My typical usage scenario is capturing a long-running live video feed (perhaps time-lapsed) and storing the resulting images in a time-stamped directory hierarchy fashion, rather than as a numbered sequence of files in a single directory. If you look at the code you will see that only a half dozen lines of code were required in img2enc. The function for creating directories already existed in hlsenc.c but I've moved into utils.c as I presumed that was a more generic location for it. All comments appreciated. Thanks ad Regards, Alan. >From 666ba7be8878a401c1e7fedd6dd7f56c9e049e14 Mon Sep 17 00:00:00 2001 From: "Dr. Alan Barclay"Date: Sun, 17 Dec 2017 19:24:44 + Subject: [PATCH] Adding mkdir option for img2enc. --- libavformat/avformat.h | 7 +++ libavformat/hlsenc.c | 33 - libavformat/img2enc.c | 8 libavformat/utils.c| 33 + 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 4f2798a871..8e76fb3349 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -2990,6 +2990,13 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVRational av_stream_get_codec_timebase(const AVStream *st); /** + * Make the specified directory. + * + * @param path path for directory + */ +int mkdir_p(const char *path); + +/** * @} */ diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index dd09739651..8523916d98 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -205,39 +205,6 @@ typedef struct HLSContext { int http_persistent; } HLSContext; -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 is_http_proto(char *filename) { const char *proto = avio_find_protocol_name(filename); return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0; diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index b680676bff..d037719ca1 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -42,6 +42,7 @@ typedef struct VideoMuxData { char target[4][1024]; int update; int use_strftime; +int use_mkdir; int frame_pts; const char *muxer; int use_rename; @@ -114,6 +115,12 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) img->img_number, img->path); return AVERROR(EINVAL); } +if (img->use_mkdir) { +char *temp_filename = av_strdup(filename); +const char *temp_path = av_dirname(temp_filename); +mkdir_p(temp_path); +av_free(temp_filename); +} for (i = 0; i < 4; i++) { snprintf(img->tmp[i], sizeof(img->tmp[i]), "%s.tmp", filename); av_strlcpy(img->target[i], filename, sizeof(img->target[i])); @@ -212,6 +219,7 @@ static const AVOption muxoptions[] = { { "update", "continuously overwrite one file", OFFSET(update), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, { "start_number", "set first number in the sequence", OFFSET(img_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, ENC }, { "strftime", "use strftime for filename", OFFSET(use_strftime), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, +{ "mkdir","make sub-dirs as required", OFFSET(use_mkdir), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, { "frame_pts","use current frame pts for filename", OFFSET(frame_pts), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, {