[FFmpeg-devel] [PATCH] Add mkdir support for HLS localtime-generated segment files
Michael Niedermayer
michael at niedermayer.cc
Sun Feb 14 01:29:26 CET 2016
On Wed, Feb 03, 2016 at 10:44:28PM +0100, Johan Ström wrote:
> Hi,
>
> this patch adds -use_localtime_mkdir option to the HLS encoder.
> Use with -use_localtime, and set -hls_segment_filename to a path
> which contains a subdirectory i.e.
> /some/path/%Y%m%d/%Y%m%dT%H%M%S-%s.ts
> This will mkdir the %Y%m%d-part of the path if it does not already exist.
>
> In addition, each filename in the playlist output will be prefixed
> with this subdirectory (if playlist and segment shares the same base
> path).
>
> Example:
>
> $ ffmpeg .... -f hls -use_localtime 1 -use_localtime_mkdir 1
> -hls_segment_filename /dvr/test/%Y%m%d/%Y%m%dT%H%M%S-%s.ts
> /dvr/test/playlist.m3u8
>
> This will create put segments created (today) in
> /dvr/test/20160203/, and the 20160203 dir will be automatically
> created if it does not already exist.
> The m3u8 playlist will contain segment paths like this:
>
> 20160203/20160203T224121-1454535681.ts
>
> The subdir support could possibly be enabled outside of the
> localtime/mkdir-scope.
>
>
> Regards
> Johan
>
> hlsenc.c | 46 ++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 40 insertions(+), 6 deletions(-)
> f3bbd115d143c8dd40fef92eb4a84b6c4ef574e7 0001-hlsenc-add-use_localtime_mkdir-option-to-automatical.patch
> From 40327f78d70b3f1b97b222de5adf70020c466db9 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Johan=20Str=C3=B6m?= <johan at stromnet.se>
> Date: Wed, 3 Feb 2016 22:20:07 +0100
> Subject: [PATCH] hlsenc: add use_localtime_mkdir option to automatically
> create time-based directory
>
> Use with -use_localtime, and set -hls_segment_filename to a path which
> contains a subdirectory i.e. /some/path/%Y%m%d/%Y%m%dT%H%M%S-%s.ts
> This will mkdir the %Y%m%d-part of the path if it does not already
> exist.
> In addition, each filename in the playlist output will be prefixed with
> this subdirectory (if playlist and segment shares the same base path).
> ---
> libavformat/hlsenc.c | 46 ++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 40 insertions(+), 6 deletions(-)
missing update to the docs
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index bc28e3c..073618d 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -82,6 +82,7 @@ typedef struct HLSContext {
> char *segment_filename;
>
> int use_localtime; ///< flag to expand filename with localtime
> + int use_localtime_mkdir;///< flag to mkdir dirname in timebased filename
> int allowcache;
> int64_t recording_time;
> int has_video;
> @@ -303,16 +304,33 @@ static int hls_mux_init(AVFormatContext *s)
> }
>
> /* Create a new segment and append it to the segment list */
> -static int hls_append_segment(HLSContext *hls, double duration, int64_t pos,
> - int64_t size)
> +static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, double duration,
> + int64_t pos, int64_t size)
> {
> HLSSegment *en = av_malloc(sizeof(*en));
> + char *tmp, *p;
> + const char *pl_dir, *filename;
> int ret;
>
> if (!en)
> return AVERROR(ENOMEM);
>
> - av_strlcpy(en->filename, av_basename(hls->avf->filename), sizeof(en->filename));
> + filename = av_basename(hls->avf->filename);
> +
> + if (hls->use_localtime_mkdir) {
> + /* Possibly prefix with mkdir'ed subdir, if playlist share same
> + * base path. */
> + tmp = av_strdup(s->filename);
> + if (!tmp)
> + return AVERROR(ENOMEM);
en leaks here
also can you add a fate test for this feature ?
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160214/76b86fbc/attachment.sig>
More information about the ffmpeg-devel
mailing list