[FFmpeg-devel] [PATCH] expand hls_fmp4_init_filename with strftime()

Nikola Pajkovsky nikis at pajkis.cz
Fri Oct 23 09:02:35 EEST 2020


Steven Liu <lq at chinaffmpeg.org> writes:

>> 2020年10月23日 上午5:01,Nikola Pajkovsky <nikis at pajkis.cz> 写道:
>> 
>> init.mp4 can be expanded with strftime() the same way as
>> hls_segment_filename.
>> 
>> Signed-off-by: Nikola Pajkovsky <nikis at pajkis.cz>
>> ---
>> doc/muxers.texi      |  7 ++++++
>> libavformat/hlsenc.c | 52 ++++++++++++++++++++++++++++++++++----------
>> 2 files changed, 48 insertions(+), 11 deletions(-)
>> 
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index 813b4678f409..179b9239517b 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -859,6 +859,13 @@ fmp4 files may be used in HLS version 7 and above.
>> @item hls_fmp4_init_filename @var{filename}
>> Set filename to the fragment files header file, default filename is @file{init.mp4}.
>> 
>> +Use @code{-strftime 1} on @var{filename} to expand the segment filename with localtime.
>> + at example
>> +ffmpeg -i in.nut  -hls_segment_type fmp4 -strftime 1 -hls_fmp4_init_filename "%s_init.mp4" out.m3u8
>> + at end example
>> +This will produce init like this
>> + at file{1602678741_init.mp4}
>> +
>> @item hls_fmp4_init_resend
>> Resend init file after m3u8 file refresh every time, default is @var{0}.
>> 
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index cb31d6aed7cf..691020cc6a46 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -258,6 +258,27 @@ typedef struct HLSContext {
>>     int has_video_m3u8; /* has video stream m3u8 list */
>> } HLSContext;
>> 
>> +static int strftime_expand(const char *fmt, char **dest)
>> +{
>> +    int r = 1;
>> +    time_t now0;
>> +    struct tm *tm, tmpbuf;
>> +    char *buf;
>> +
>> +    buf = av_mallocz(MAX_URL_SIZE);
>> +    if (!buf)
>> +        return AVERROR(ENOMEM);
>> +
>> +    time(&now0);
>> +    tm = localtime_r(&now0, &tmpbuf);
>> +    r = strftime(buf, MAX_URL_SIZE, fmt, tm);
>> +    if (!r)
>> +        return AVERROR(EINVAL);
> Should it memleak here or not? When the strftime return null.

Good catch. It's been while, since I wrote something in C. I'll
prepare v2.

-- 
Nikola


More information about the ffmpeg-devel mailing list