[FFmpeg-devel] [PATCH] avformat/hlsenc: refine EXT-X-BYTERANGE support for segments

Michael Niedermayer michael at niedermayer.cc
Tue Sep 13 01:19:29 EEST 2016


On Mon, Sep 12, 2016 at 07:04:54PM +0800, Steven Liu wrote:
> 2016-09-12 18:52 GMT+08:00 Michael Niedermayer <michael at niedermayer.cc>:
> 
> > On Mon, Sep 12, 2016 at 05:39:31PM +0800, Steven Liu wrote:
> > > 2016-09-12 17:35 GMT+08:00 Steven Liu <lingjiujianke at gmail.com>:
> > >
> > > >
> > > >
> > > > 2016-09-12 17:28 GMT+08:00 Michael Niedermayer <michael at niedermayer.cc
> > >:
> > > >
> > > >> On Mon, Sep 12, 2016 at 03:01:24PM +0800, Steven Liu wrote:
> > > >> > refine EXT-X-BYTERANGE tag,
> > > >> > the spec link:
> > > >> > https://tools.ietf.org/html/draft-pantos-http-live-streaming
> > > >> -19#section-4.3.2.2
> > > >> >
> > > >> > the apple doc:
> > > >> > https://developer.apple.com/library/ios/technotes/tn2288/_in
> > > >> dex.html#//apple_ref/doc/uid/DTS40012238-CH1-BYTE_RANGE_
> > > >> SUPPORT_FOR_SEGMENTS
> > > >> >
> > > >> > command line:
> > > >> > ./ffmpeg -i ~/Movies/objectC/a.mp4 -c copy -f hls -hls_time 7
> > > >> > -hls_list_size 100 -hls_segment_size 2500000 -t 40 output-test.m3u8
> > > >> >
> > > >> > output:
> > > >> >
> > > >> > localhost:ffmpeg liuqi$ ll *.ts ;cat output-test.m3u8
> > > >> > -rw-r--r--  1 liuqi  staff  2792176  9 12 14:44 output-test0.ts
> > > >> > -rw-r--r--  1 liuqi  staff  3112528  9 12 14:44 output-test3.ts
> > > >> > -rw-r--r--  1 liuqi  staff  3377420  9 12 14:44 output-test6.ts
> > > >> > -rw-r--r--  1 liuqi  staff  1228016  9 12 14:44 output-test7.ts
> > > >> >  #EXTM3U
> > > >> >  #EXT-X-VERSION:4
> > > >> >  #EXT-X-TARGETDURATION:10
> > > >> >  #EXT-X-MEDIA-SEQUENCE:0
> > > >> >  #EXTINF:9.021000,
> > > >> >  #EXT-X-BYTERANGE:1334988 at 0
> > > >> >  output-test0.ts
> > > >> >  #EXTINF:3.000000,
> > > >> >  #EXT-X-BYTERANGE:721356 at 1334988
> > > >> >  output-test0.ts
> > > >> >  #EXTINF:3.000000,
> > > >> >  #EXT-X-BYTERANGE:735832 at 2056344
> > > >> >  output-test0.ts
> > > >> >  #EXTINF:6.000000,
> > > >> >  #EXT-X-BYTERANGE:1645940 at 0
> > > >> >  output-test3.ts
> > > >> >  #EXTINF:3.000000,
> > > >> >  #EXT-X-BYTERANGE:715152 at 1645940
> > > >> >  output-test3.ts
> > > >> >  #EXTINF:3.000000,
> > > >> >  #EXT-X-BYTERANGE:751436 at 2361092
> > > >> >  output-test3.ts
> > > >> >  #EXTINF:9.000000,
> > > >> >  #EXT-X-BYTERANGE:3377420 at 0
> > > >> >  output-test6.ts
> > > >> >  #EXTINF:3.960000,
> > > >> >  #EXT-X-BYTERANGE:1228016 at 0
> > > >> >  output-test7.ts
> > > >> >  #EXT-X-ENDLIST
> > > >> >  localhost:ffmpeg liuqi$
> > > >> >
> > > >> >  ticket-id: #5839
> > > >> >
> > > >> > Signed-off-by: Steven Liu <lingjiujianke at gmail.com>
> > > >> > ---
> > > >> >  libavformat/hlsenc.c | 38 +++++++++++++++++++++++++++++++++-----
> > > >> >  1 file changed, 33 insertions(+), 5 deletions(-)
> > > >> >
> > > >> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> > > >> > index a376312..08995f6 100644
> > > >> > --- a/libavformat/hlsenc.c
> > > >> > +++ b/libavformat/hlsenc.c
> > > >> > @@ -104,6 +104,7 @@ typedef struct HLSContext {
> > > >> >      double duration;      // last segment duration computed so
> > far, in
> > > >> > seconds
> > > >> >      int64_t start_pos;    // last segment starting position
> > > >> >      int64_t size;         // last segment size
> > > >> > +     int64_t max_seg_size; // every segment file max size
> > > >> >      int nb_entries;
> > > >> >      int discontinuity_set;
> > > >> >
> > > >>
> > > >> fatal: corrupt patch at line 11
> > > >> maybe the comment :
> > > >
> > > >
> > > >  > -rw-r--r--  1 liuqi  staff  2792176  9 12 14:44 output-test0.ts
> > > > > -rw-r--r--  1 liuqi  staff  3112528  9 12 14:44 output-test3.ts
> > > > > -rw-r--r--  1 liuqi  staff  3377420  9 12 14:44 output-test6.ts
> > > > > -rw-r--r--  1 liuqi  staff  1228016  9 12 14:44 output-test7.ts
> > > >
> > > > give the error  for patch ??
> > > >
> > >
> >
> > > update patch, remove the commit message with '-'
> >
> > The problem was not the commit message, the problem was "\n"
> > added to long lines of diff (word wrap)
> >
> > a more verbose commit message would be better than 1 line
> >
> > patch update,
> 
> split long commit message to 2 lines

>  hlsenc.c |   34 +++++++++++++++++++++++++++++++---
>  1 file changed, 31 insertions(+), 3 deletions(-)
> 3cb76b9c371cd40f41a51a84a142f849727eed44  0001-avformat-hlsenc-refine-EXT-X-BYTERANGE-support-for-s.patch
> From 4c357e9e213cbc3b10667f3e69b43b6b30581913 Mon Sep 17 00:00:00 2001
> From: Steven Liu <lingjiujianke at gmail.com>
> Date: Mon, 12 Sep 2016 18:59:19 +0800
> Subject: [PATCH] avformat/hlsenc: refine EXT-X-BYTERANGE support for segments
> 
> refine EXT-X-BYTERANGE tag,
> the spec link:
> https://tools.ietf.org/html/draft-pantos-http-live-streaming-19#section-4.3.2.2
> the apple doc:
> https://developer.apple.com/library/ios/technotes/tn2288/_index.html#
> //apple_ref/doc/uid/DTS40012238-CH1-BYTE_RANGE_SUPPORT_FOR_SEGMENTS
> 
> command line:
> ./ffmpeg -i ~/Movies/objectC/a.mp4 -c copy -f hls -hls_time 7
>  -hls_list_size 100 -hls_segment_size 2500000 -t 40 output-test.m3u8
> output:
> localhost:ffmpeg liuqi$ ll *.ts ;cat output-test.m3u8
>  -rw-r--r--  1 liuqi  staff  2792176  9 12 14:44 output-test0.ts
>  -rw-r--r--  1 liuqi  staff  3112528  9 12 14:44 output-test3.ts
>  -rw-r--r--  1 liuqi  staff  3377420  9 12 14:44 output-test6.ts
>  -rw-r--r--  1 liuqi  staff  1228016  9 12 14:44 output-test7.ts
>  #EXTM3U
>  #EXT-X-VERSION:4
>  #EXT-X-TARGETDURATION:10
>  #EXT-X-MEDIA-SEQUENCE:0
>  #EXTINF:9.021000,
>  #EXT-X-BYTERANGE:1334988 at 0
>  output-test0.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:721356 at 1334988
>  output-test0.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:735832 at 2056344
>  output-test0.ts
>  #EXTINF:6.000000,
>  #EXT-X-BYTERANGE:1645940 at 0
>  output-test3.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:715152 at 1645940
>  output-test3.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:751436 at 2361092
>  output-test3.ts
>  #EXTINF:9.000000,
>  #EXT-X-BYTERANGE:3377420 at 0
>  output-test6.ts
>  #EXTINF:3.960000,
>  #EXT-X-BYTERANGE:1228016 at 0
>  output-test7.ts
>  #EXT-X-ENDLIST
>  localhost:ffmpeg liuqi$
> 
>  ticket-id: #5839
> 
> Signed-off-by: Steven Liu <lingjiujianke at gmail.com>
> ---
>  libavformat/hlsenc.c | 34 +++++++++++++++++++++++++++++++---
>  1 file changed, 31 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index a376312..7ec469a 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c

> @@ -104,6 +104,7 @@ typedef struct HLSContext {
>      double duration;      // last segment duration computed so far, in seconds
>      int64_t start_pos;    // last segment starting position
>      int64_t size;         // last segment size
> +     int64_t max_seg_size; // every segment file max size
>      int nb_entries;
>      int discontinuity_set;

wrong indention


>  
> @@ -476,7 +477,7 @@ static int hls_window(AVFormatContext *s, int last)
>      AVIOContext *sub_out = NULL;
>      char temp_filename[1024];
>      int64_t sequence = FFMAX(hls->start_sequence, hls->sequence - hls->nb_entries);

> -    int version = hls->flags & HLS_SINGLE_FILE ? 4 : 3;

> +    int version = 0;

the value written is unused


>      const char *proto = avio_find_protocol_name(s->filename);
>      int use_rename = proto && !strcmp(proto, "file");
>      static unsigned warned_non_file;
> @@ -485,6 +486,12 @@ static int hls_window(AVFormatContext *s, int last)
>      AVDictionary *options = NULL;
>      double prog_date_time = hls->initial_prog_date_time;
>  
> +    if (hls->flags & (HLS_SINGLE_FILE) || hls->max_seg_size > 0) {
> +        version = 4;
> +    } else {
> +        version = 3;
> +    }
> +
>      if (!use_rename && !warned_non_file++)
>          av_log(s, AV_LOG_ERROR, "Cannot use rename on non file protocol, this may lead to races and temporarly partial files\n");
>  
> @@ -533,7 +540,8 @@ static int hls_window(AVFormatContext *s, int last)
>              avio_printf(out, "#EXTINF:%ld,\n",  lrint(en->duration));
>          else
>              avio_printf(out, "#EXTINF:%f,\n", en->duration);
> -        if (hls->flags & HLS_SINGLE_FILE)
> +        if (hls->flags & HLS_SINGLE_FILE ||
> +            hls->max_seg_size > 0)
>               avio_printf(out, "#EXT-X-BYTERANGE:%"PRIi64"@%"PRIi64"\n",
>                           en->size, en->pos);
>          if (hls->flags & HLS_PROGRAM_DATE_TIME) {
> @@ -573,7 +581,8 @@ static int hls_window(AVFormatContext *s, int last)
>  
>          for (en = hls->segments; en; en = en->next) {
>              avio_printf(sub_out, "#EXTINF:%f,\n", en->duration);
> -            if (hls->flags & HLS_SINGLE_FILE)
> +            if (hls->flags & HLS_SINGLE_FILE ||
> +                hls->max_seg_size > 0)

"hls->flags & HLS_SINGLE_FILE || hls->max_seg_size > 0"
occurs several times maybe this can be simplified ?

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- 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/20160913/fab63979/attachment.sig>


More information about the ffmpeg-devel mailing list