[FFmpeg-devel] [PATCH] avformat/hlsenc: detecting duplicated segment filenames

Steven Liu lingjiujianke at gmail.com
Mon Dec 26 12:22:10 EET 2016


2016-12-26 17:55 GMT+08:00 Steven Liu <lingjiujianke at gmail.com>:

>
>
> 2016-12-26 17:05 GMT+08:00 Steven Liu <lingjiujianke at gmail.com>:
>
>>
>>
>> 2016-12-26 9:14 GMT+08:00 Bodecs Bela <bodecsb at vivanet.hu>:
>>
>>> Dear All,
>>>
>>> with use_localtime parameter hlsenc may produce identical filenames for
>>> different but still existing segments. It happens when
>>> hls_segment_filename contains
>>> syntacticaly correct but inadequate format parameters. Currently there
>>> is no any log message when such a situaton occurs but these cases should
>>> be avoided in most times. This patch generate warning log messages in
>>> these
>>> cases.
>>>
>>> best regards,
>>>
>>> bb
>>>
>>>> From 7055e0b0bec3fee61373dd446bcab24d15117b7e Mon Sep 17 00:00:00 2001
>>>
>>> From: Bela Bodecs <bodecsb at vivanet.hu>
>>>
>>> Date: Mon, 26 Dec 2016 02:00:49 +0100
>>>
>>> Subject: [PATCH] avformat/hlsenc: detecting duplicated segment filenames
>>>
>>>
>>>> with use_localtime parameter hlsenc may produce identical filenames for
>>>
>>> different but still existing segments. It happens when
>>>
>>> hls_segment_filename contains
>>>
>>> syntacticaly correct but inadequate format parameters. Currently there
>>>
>>> is no any log message when such a situaton occurs but these cases should
>>>
>>> be avoided in most times. This patch generate warning messages in these
>>>
>>> cases.
>>>
>>>
>>>> Signed-off-by: Bela Bodecs <bodecsb at vivanet.hu>
>>>
>>> ---
>>>
>>>  libavformat/hlsenc.c | 34 ++++++++++++++++++++++++++++++++++
>>>
>>>  1 file changed, 34 insertions(+)
>>>
>>>
>>>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>>
>>> index acf3a30..11ec3b8 100644
>>>
>>> --- a/libavformat/hlsenc.c
>>>
>>> +++ b/libavformat/hlsenc.c
>>>
>>> @@ -653,6 +653,38 @@ fail:
>>>
>>>      return ret;
>>>
>>>  }
>>>
>>>
>>>
>>> +static HLSSegment * find_segment_by_filename(HLSSegment * segment,
>>>> const char * filename)
>>>
>>> +{
>>>
>>> +    /* filename may contain rel/abs path, but segments store only
>>>> basename */
>>>
>>> +    char *p, *dirname, *path;
>>>
>>> +    int path_size;
>>>
>>> +    HLSSegment *ret_segment = NULL;
>>>
>>> +    dirname = av_strdup(filename);
>>>
>>> +    if (!dirname)
>>>
>>> +        return NULL;
>>>
>>> +    p = (char *)av_basename(dirname); // av_dirname would return . in
>>>> case of no dir
>>>
>>> +    *p = '\0'; // maybe empty
>>>
>>> +
>>>
>>> +    while (segment) {
>>>
>>> +        path_size = strlen(dirname) + strlen(segment->filename) + 1;
>>>
>>> +        path = av_malloc(path_size);
>>>
>>> +        if (!path)
>>>
>>> +            goto end;
>>>
>>> +        av_strlcpy(path, dirname, path_size);
>>>
>>> +        av_strlcat(path, segment->filename, path_size);
>>>
>>> +        if (!strcmp(path,filename)) {
>>>
>>> +            ret_segment = segment;
>>>
>>> +            av_free(path);
>>>
>>> +            goto end;
>>>
>>> +        }
>>>
>>> +        av_free(path);
>>>
>>> +        segment = segment->next;
>>>
>>> +    }
>>>
>>> +end:
>>>
>>> +    av_free(dirname);
>>>
>>> +    return ret_segment;
>>>
>>> +}
>>>
>>> +
>>>
>>>  static int hls_start(AVFormatContext *s)
>>>
>>>  {
>>>
>>>      HLSContext *c = s->priv_data;
>>>
>>> @@ -685,6 +717,8 @@ static int hls_start(AVFormatContext *s)
>>>
>>>                  av_log(oc, AV_LOG_ERROR, "Could not get segment
>>>> filename with use_localtime\n");
>>>
>>>                  return AVERROR(EINVAL);
>>>
>>>              }
>>>
>>> +            if (find_segment_by_filename(c->segments, oc->filename) ||
>>>> find_segment_by_filename(c->old_segments, oc->filename))
>>>
>>> +                av_log(c, AV_LOG_WARNING, "Duplicated segment filename
>>>> detected: %s\n",oc->filename);
>>>
>>>
>>>
>>>              if (c->use_localtime_mkdir) {
>>>
>>>                  const char *dir;
>>>
>>> --
>>>
>>> 2.5.3.windows.1
>>>
>>>
>>>>
>> LTGM
>>
>>
>>
>>
>>>
>>>
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>>
>>
>
> localhost:mpegts liuqi$ ./ffmpeg -loglevel info   -y -f lavfi -i
> color=c=red:size=640x480:r=25 -f lavfi -f lavfi -i
> color=c=pink:size=1920x1080:r=25 -f lavfi -i anullsrc=r=44100:cl=stereo
>  -f lavfi -i anullsrc=r=44100:cl=stereo -filter_complex
> "[1]setpts=PTS-STARTPTS[1o]; [0:v]setpts=PTS-STARTPTS [0vo]; [1o][0vo]
> overlay=x=10:y=10 ,  split=3 [v1][v2][vimg] ; [v1] scale=size=960x540,
> setdar=dar=16/9, nullsink ; [v2] scale=size=640x360,  setdar=dar=16/9 ,
> nullsink ; [vimg] fps=1/5, scale=size=320x180, nullsink ;
> [3]asetpts=PTS-STARTPTS [0ao]; [2]asetpts=PTS-STARTPTS [2o]; [0ao][2o] amix
> [aout1] "   -map "[aout1]"  -acodec aac -cutoff 20000 -ac 2 -ar 44100 -ab
> 192k  -f hls -hls_time 3 -hls_list_size 100 -hls_flags delete_segments
> -use_localtime 1 -hls_segment_filename 'segment%Y%m%d%H%M%S.ts'
> stream.m3u8}}}
> ffmpeg version N-82932-g6e26b6e Copyright (c) 2000-2016 the FFmpeg
> developers
>   built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
>   configuration: --enable-fontconfig --enable-gpl --enable-libass
> --enable-libbluray --enable-libfreetype --enable-libmp3lame
> --enable-libspeex --enable-libx264 --enable-libx265 --enable-version3
> --cc='ccache gcc'
>   libavutil      55. 43.100 / 55. 43.100
>   libavcodec     57. 70.100 / 57. 70.100
>   libavformat    57. 61.100 / 57. 61.100
>   libavdevice    57.  2.100 / 57.  2.100
>   libavfilter     6. 68.100 /  6. 68.100
>   libswscale      4.  3.101 /  4.  3.101
>   libswresample   2.  4.100 /  2.  4.100
>   libpostproc    54.  2.100 / 54.  2.100
> Input #0, lavfi, from 'color=c=red:size=640x480:r=25':
>   Duration: N/A, start: 0.000000, bitrate: N/A
>     Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480
> [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
> Input #1, lavfi, from 'color=c=pink:size=1920x1080:r=25':
>   Duration: N/A, start: 0.000000, bitrate: N/A
>     Stream #1:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080
> [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
> Input #2, lavfi, from 'anullsrc=r=44100:cl=stereo':
>   Duration: N/A, start: 0.000000, bitrate: 705 kb/s
>     Stream #2:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
> Input #3, lavfi, from 'anullsrc=r=44100:cl=stereo':
>   Duration: N/A, start: 0.000000, bitrate: 705 kb/s
>     Stream #3:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
> [mpegts @ 0x7feb3b808400] frame size not set
> Output #0, hls, to 'stream.m3u8}}}':
>   Metadata:
>     encoder         : Lavf57.61.100
>     Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 192 kb/s
> (default)
>     Metadata:
>       encoder         : Lavc57.70.100 aac
> Stream mapping:
>   Stream #0:0 (rawvideo) -> setpts
>   Stream #1:0 (rawvideo) -> setpts
>   Stream #2:0 (pcm_u8) -> asetpts
>   Stream #3:0 (pcm_u8) -> asetpts
>   amix -> Stream #0:0 (aac)
> Press [q] to stop, [?] for help
> [hls muxer @ 0x7feb3c02a800] Duplicated segment filename detected:
> segment20161226175432.ts
> [hls muxer @ 0x7feb3c02a800] Duplicated segment filename detected:
> segment20161226175433.ts
>     Last message repeated 1 times
> [hls muxer @ 0x7feb3c02a800] Duplicated segment filename detected:
> segment20161226175434.ts
> [hls muxer @ 0x7feb3c02a800] Duplicated segment filename detected:
> segment20161226175436.ts
> [hls muxer @ 0x7feb3c02a800] Duplicated segment filename detected:
> segment20161226175436.ts
>     Last message repeated 1 times
> [hls muxer @ 0x7feb3c02a800] Duplicated segment filename detected:
> segment20161226175438.ts
> [hls muxer @ 0x7feb3c02a800] Duplicated segment filename detected:
> segment20161226175439.ts
> [hls muxer @ 0x7feb3c02a800] Duplicated segment filename detected:
> segment20161226175439.ts
> [hls muxer @ 0x7feb3c02a800] Duplicated segment filename detected:
> segment20161226175440.ts
> size=N/A time=00:01:05.03 bitrate=N/A speed=5.93x
> video:0kB audio:17kB subtitle:0kB other streams:0kB global headers:0kB
> muxing overhead: unknown
> [aac @ 0x7feb3c02be00] Qavg: 65536.000
> Exiting normally, received signal 2.
> localhost:mpegts liuqi$ cat stream.m3u8}}}
> #EXTM3U
> #EXT-X-VERSION:3
> #EXT-X-TARGETDURATION:4
> #EXT-X-MEDIA-SEQUENCE:0
> #EXTINF:3.018600,
> segment20161226175430.ts
> #EXTINF:2.995367,
> segment20161226175431.ts
> #EXTINF:2.995378,
> segment20161226175432.ts
> #EXTINF:2.995378,
> segment20161226175432.ts
> #EXTINF:2.995367,
> segment20161226175433.ts
> #EXTINF:3.018600,
> segment20161226175433.ts
> #EXTINF:2.995378,
> segment20161226175433.ts
> #EXTINF:2.995367,
> segment20161226175434.ts
> #EXTINF:2.995378,
> segment20161226175434.ts
> #EXTINF:2.995378,
> segment20161226175435.ts
> #EXTINF:3.018589,
> segment20161226175436.ts
> #EXTINF:2.995378,
> segment20161226175436.ts
> #EXTINF:2.995367,
> segment20161226175436.ts
> #EXTINF:2.995378,
> segment20161226175436.ts
> #EXTINF:2.995378,
> segment20161226175437.ts
> #EXTINF:3.018589,
> segment20161226175438.ts
> #EXTINF:2.995378,
> segment20161226175438.ts
> #EXTINF:2.995378,
> segment20161226175439.ts
> #EXTINF:2.995367,
> segment20161226175439.ts
> #EXTINF:2.995378,
> segment20161226175439.ts
> #EXTINF:3.018589,
> segment20161226175440.ts
> #EXTINF:2.020144,
> segment20161226175440.ts
> #EXT-X-ENDLIST
>
>
>
>
>
> Tested pass!
>
>
>
applied!


Thanks


More information about the ffmpeg-devel mailing list