diff mbox

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

Message ID CADxeRwmDFoaFb=1=AQ_V7AOCdMNpQ+gaimXBnMXsTO5pWO=-SQ@mail.gmail.com
State Accepted
Headers show

Commit Message

Steven Liu Sept. 12, 2016, 7:01 a.m. UTC
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@0
 output-test0.ts
 #EXTINF:3.000000,
 #EXT-X-BYTERANGE:721356@1334988
 output-test0.ts
 #EXTINF:3.000000,
 #EXT-X-BYTERANGE:735832@2056344
 output-test0.ts
 #EXTINF:6.000000,
 #EXT-X-BYTERANGE:1645940@0
 output-test3.ts
 #EXTINF:3.000000,
 #EXT-X-BYTERANGE:715152@1645940
 output-test3.ts
 #EXTINF:3.000000,
 #EXT-X-BYTERANGE:751436@2361092
 output-test3.ts
 #EXTINF:9.000000,
 #EXT-X-BYTERANGE:3377420@0
 output-test6.ts
 #EXTINF:3.960000,
 #EXT-X-BYTERANGE:1228016@0
 output-test7.ts
 #EXT-X-ENDLIST
 localhost:ffmpeg liuqi$

 ticket-id: #5839

Signed-off-by: Steven Liu <lingjiujianke@gmail.com>
---
 libavformat/hlsenc.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)


@@ -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;
     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)
                  avio_printf(sub_out,
"#EXT-X-BYTERANGE:%"PRIi64"@%"PRIi64"\n",
                          en->size, en->pos);
             if (hls->baseurl)
@@ -610,7 +619,14 @@ static int hls_start(AVFormatContext *s)
         if (c->vtt_basename)
             av_strlcpy(vtt_oc->filename, c->vtt_basename,
                   sizeof(vtt_oc->filename));
-    } else {
+    } else if (c->max_seg_size > 0) {
+        if (av_get_frame_filename2(oc->filename, sizeof(oc->filename),
+            c->basename, c->wrap ? c->sequence % c->wrap : c->sequence,
+            AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
+                av_log(oc, AV_LOG_ERROR, "Invalid segment filename
template '%s' you can try use -use_localtime 1 with it\n", c->basename);
+                return AVERROR(EINVAL);
+        }
+    } else {
         if (c->use_localtime) {
             time_t now0;
             struct tm *tm, tmpbuf;
@@ -943,7 +959,18 @@ static int hls_write_packet(AVFormatContext *s,
AVPacket *pkt)
             if (hls->avf->oformat->priv_class && hls->avf->priv_data)
                 av_opt_set(hls->avf->priv_data, "mpegts_flags",
"resend_headers", 0);
             hls->number++;
-        } else {
+        } else if (hls->max_seg_size > 0) {
+            if (hls->avf->oformat->priv_class && hls->avf->priv_data)
+                av_opt_set(hls->avf->priv_data, "mpegts_flags",
"resend_headers", 0);
+            if (hls->start_pos >= hls->max_seg_size ) {
+                ff_format_io_close(s, &oc->pb);
+                if (hls->vtt_avf)
+                    ff_format_io_close(s, &hls->vtt_avf->pb);
+                ret = hls_start(s);
+                hls->start_pos = 0;
+                hls->number++;
+            }
+        } else {
             ff_format_io_close(s, &oc->pb);
             if (hls->vtt_avf)
                 ff_format_io_close(s, &hls->vtt_avf->pb);
@@ -1020,6 +1047,7 @@ static const AVOption options[] = {
     {"hls_key_info_file",    "file with key URI and key file path",
OFFSET(key_info_file),      AV_OPT_TYPE_STRING, {.str = NULL},
 0,       0,         E},
     {"hls_subtitle_path",     "set path of hls subtitles",
OFFSET(subtitle_filename), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
     {"hls_flags",     "set flags affecting HLS playlist and media file
generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E,
"flags"},
+    {"hls_segment_size", "set maximum size per segment file, (Byte)",
 OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX,
E},
     {"single_file",   "generate a single media file indexed with byte
ranges", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E,
"flags"},
     {"delete_segments", "delete segment files that are no longer part of
the playlist", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_DELETE_SEGMENTS }, 0,
UINT_MAX,   E, "flags"},
     {"round_durations", "round durations in m3u8 to whole numbers", 0,
AV_OPT_TYPE_CONST, {.i64 = HLS_ROUND_DURATIONS }, 0, UINT_MAX,   E,
"flags"},
--
2.7.4 (Apple Git-66)

Comments

Michael Niedermayer Sept. 12, 2016, 9:28 a.m. UTC | #1
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/_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@0
>  output-test0.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:721356@1334988
>  output-test0.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:735832@2056344
>  output-test0.ts
>  #EXTINF:6.000000,
>  #EXT-X-BYTERANGE:1645940@0
>  output-test3.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:715152@1645940
>  output-test3.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:751436@2361092
>  output-test3.ts
>  #EXTINF:9.000000,
>  #EXT-X-BYTERANGE:3377420@0
>  output-test6.ts
>  #EXTINF:3.960000,
>  #EXT-X-BYTERANGE:1228016@0
>  output-test7.ts
>  #EXT-X-ENDLIST
>  localhost:ffmpeg liuqi$
> 
>  ticket-id: #5839
> 
> Signed-off-by: Steven Liu <lingjiujianke@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

[...]
Steven Liu Sept. 12, 2016, 9:35 a.m. UTC | #2
2016-09-12 17:28 GMT+08:00 Michael Niedermayer <michael@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/_
> 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@0
> >  output-test0.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:721356@1334988
> >  output-test0.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:735832@2056344
> >  output-test0.ts
> >  #EXTINF:6.000000,
> >  #EXT-X-BYTERANGE:1645940@0
> >  output-test3.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:715152@1645940
> >  output-test3.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:751436@2361092
> >  output-test3.ts
> >  #EXTINF:9.000000,
> >  #EXT-X-BYTERANGE:3377420@0
> >  output-test6.ts
> >  #EXTINF:3.960000,
> >  #EXT-X-BYTERANGE:1228016@0
> >  output-test7.ts
> >  #EXT-X-ENDLIST
> >  localhost:ffmpeg liuqi$
> >
> >  ticket-id: #5839
> >
> > Signed-off-by: Steven Liu <lingjiujianke@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 ??
Steven Liu Sept. 12, 2016, 9:39 a.m. UTC | #3
2016-09-12 17:35 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:

>
>
> 2016-09-12 17:28 GMT+08:00 Michael Niedermayer <michael@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@0
>> >  output-test0.ts
>> >  #EXTINF:3.000000,
>> >  #EXT-X-BYTERANGE:721356@1334988
>> >  output-test0.ts
>> >  #EXTINF:3.000000,
>> >  #EXT-X-BYTERANGE:735832@2056344
>> >  output-test0.ts
>> >  #EXTINF:6.000000,
>> >  #EXT-X-BYTERANGE:1645940@0
>> >  output-test3.ts
>> >  #EXTINF:3.000000,
>> >  #EXT-X-BYTERANGE:715152@1645940
>> >  output-test3.ts
>> >  #EXTINF:3.000000,
>> >  #EXT-X-BYTERANGE:751436@2361092
>> >  output-test3.ts
>> >  #EXTINF:9.000000,
>> >  #EXT-X-BYTERANGE:3377420@0
>> >  output-test6.ts
>> >  #EXTINF:3.960000,
>> >  #EXT-X-BYTERANGE:1228016@0
>> >  output-test7.ts
>> >  #EXT-X-ENDLIST
>> >  localhost:ffmpeg liuqi$
>> >
>> >  ticket-id: #5839
>> >
>> > Signed-off-by: Steven Liu <lingjiujianke@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 '-'
Michael Niedermayer Sept. 12, 2016, 10:52 a.m. UTC | #4
On Mon, Sep 12, 2016 at 05:39:31PM +0800, Steven Liu wrote:
> 2016-09-12 17:35 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:
> 
> >
> >
> > 2016-09-12 17:28 GMT+08:00 Michael Niedermayer <michael@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@0
> >> >  output-test0.ts
> >> >  #EXTINF:3.000000,
> >> >  #EXT-X-BYTERANGE:721356@1334988
> >> >  output-test0.ts
> >> >  #EXTINF:3.000000,
> >> >  #EXT-X-BYTERANGE:735832@2056344
> >> >  output-test0.ts
> >> >  #EXTINF:6.000000,
> >> >  #EXT-X-BYTERANGE:1645940@0
> >> >  output-test3.ts
> >> >  #EXTINF:3.000000,
> >> >  #EXT-X-BYTERANGE:715152@1645940
> >> >  output-test3.ts
> >> >  #EXTINF:3.000000,
> >> >  #EXT-X-BYTERANGE:751436@2361092
> >> >  output-test3.ts
> >> >  #EXTINF:9.000000,
> >> >  #EXT-X-BYTERANGE:3377420@0
> >> >  output-test6.ts
> >> >  #EXTINF:3.960000,
> >> >  #EXT-X-BYTERANGE:1228016@0
> >> >  output-test7.ts
> >> >  #EXT-X-ENDLIST
> >> >  localhost:ffmpeg liuqi$
> >> >
> >> >  ticket-id: #5839
> >> >
> >> > Signed-off-by: Steven Liu <lingjiujianke@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

[...]
Steven Liu Sept. 12, 2016, 11:04 a.m. UTC | #5
2016-09-12 18:52 GMT+08:00 Michael Niedermayer <michael@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@gmail.com>:
> >
> > >
> > >
> > > 2016-09-12 17:28 GMT+08:00 Michael Niedermayer <michael@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@0
> > >> >  output-test0.ts
> > >> >  #EXTINF:3.000000,
> > >> >  #EXT-X-BYTERANGE:721356@1334988
> > >> >  output-test0.ts
> > >> >  #EXTINF:3.000000,
> > >> >  #EXT-X-BYTERANGE:735832@2056344
> > >> >  output-test0.ts
> > >> >  #EXTINF:6.000000,
> > >> >  #EXT-X-BYTERANGE:1645940@0
> > >> >  output-test3.ts
> > >> >  #EXTINF:3.000000,
> > >> >  #EXT-X-BYTERANGE:715152@1645940
> > >> >  output-test3.ts
> > >> >  #EXTINF:3.000000,
> > >> >  #EXT-X-BYTERANGE:751436@2361092
> > >> >  output-test3.ts
> > >> >  #EXTINF:9.000000,
> > >> >  #EXT-X-BYTERANGE:3377420@0
> > >> >  output-test6.ts
> > >> >  #EXTINF:3.960000,
> > >> >  #EXT-X-BYTERANGE:1228016@0
> > >> >  output-test7.ts
> > >> >  #EXT-X-ENDLIST
> > >> >  localhost:ffmpeg liuqi$
> > >> >
> > >> >  ticket-id: #5839
> > >> >
> > >> > Signed-off-by: Steven Liu <lingjiujianke@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
Michael Niedermayer Sept. 12, 2016, 10:19 p.m. UTC | #6
On Mon, Sep 12, 2016 at 07:04:54PM +0800, Steven Liu wrote:
> 2016-09-12 18:52 GMT+08:00 Michael Niedermayer <michael@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@gmail.com>:
> > >
> > > >
> > > >
> > > > 2016-09-12 17:28 GMT+08:00 Michael Niedermayer <michael@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@0
> > > >> >  output-test0.ts
> > > >> >  #EXTINF:3.000000,
> > > >> >  #EXT-X-BYTERANGE:721356@1334988
> > > >> >  output-test0.ts
> > > >> >  #EXTINF:3.000000,
> > > >> >  #EXT-X-BYTERANGE:735832@2056344
> > > >> >  output-test0.ts
> > > >> >  #EXTINF:6.000000,
> > > >> >  #EXT-X-BYTERANGE:1645940@0
> > > >> >  output-test3.ts
> > > >> >  #EXTINF:3.000000,
> > > >> >  #EXT-X-BYTERANGE:715152@1645940
> > > >> >  output-test3.ts
> > > >> >  #EXTINF:3.000000,
> > > >> >  #EXT-X-BYTERANGE:751436@2361092
> > > >> >  output-test3.ts
> > > >> >  #EXTINF:9.000000,
> > > >> >  #EXT-X-BYTERANGE:3377420@0
> > > >> >  output-test6.ts
> > > >> >  #EXTINF:3.960000,
> > > >> >  #EXT-X-BYTERANGE:1228016@0
> > > >> >  output-test7.ts
> > > >> >  #EXT-X-ENDLIST
> > > >> >  localhost:ffmpeg liuqi$
> > > >> >
> > > >> >  ticket-id: #5839
> > > >> >
> > > >> > Signed-off-by: Steven Liu <lingjiujianke@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@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@0
>  output-test0.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:721356@1334988
>  output-test0.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:735832@2056344
>  output-test0.ts
>  #EXTINF:6.000000,
>  #EXT-X-BYTERANGE:1645940@0
>  output-test3.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:715152@1645940
>  output-test3.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:751436@2361092
>  output-test3.ts
>  #EXTINF:9.000000,
>  #EXT-X-BYTERANGE:3377420@0
>  output-test6.ts
>  #EXTINF:3.960000,
>  #EXT-X-BYTERANGE:1228016@0
>  output-test7.ts
>  #EXT-X-ENDLIST
>  localhost:ffmpeg liuqi$
> 
>  ticket-id: #5839
> 
> Signed-off-by: Steven Liu <lingjiujianke@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 ?

[...]
Steven Liu Sept. 12, 2016, 10:49 p.m. UTC | #7
2016-09-13 6:19 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:

> On Mon, Sep 12, 2016 at 07:04:54PM +0800, Steven Liu wrote:
> > 2016-09-12 18:52 GMT+08:00 Michael Niedermayer <michael@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@gmail.com>:
> > > >
> > > > >
> > > > >
> > > > > 2016-09-12 17:28 GMT+08:00 Michael Niedermayer
> <michael@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@0
> > > > >> >  output-test0.ts
> > > > >> >  #EXTINF:3.000000,
> > > > >> >  #EXT-X-BYTERANGE:721356@1334988
> > > > >> >  output-test0.ts
> > > > >> >  #EXTINF:3.000000,
> > > > >> >  #EXT-X-BYTERANGE:735832@2056344
> > > > >> >  output-test0.ts
> > > > >> >  #EXTINF:6.000000,
> > > > >> >  #EXT-X-BYTERANGE:1645940@0
> > > > >> >  output-test3.ts
> > > > >> >  #EXTINF:3.000000,
> > > > >> >  #EXT-X-BYTERANGE:715152@1645940
> > > > >> >  output-test3.ts
> > > > >> >  #EXTINF:3.000000,
> > > > >> >  #EXT-X-BYTERANGE:751436@2361092
> > > > >> >  output-test3.ts
> > > > >> >  #EXTINF:9.000000,
> > > > >> >  #EXT-X-BYTERANGE:3377420@0
> > > > >> >  output-test6.ts
> > > > >> >  #EXTINF:3.960000,
> > > > >> >  #EXT-X-BYTERANGE:1228016@0
> > > > >> >  output-test7.ts
> > > > >> >  #EXT-X-ENDLIST
> > > > >> >  localhost:ffmpeg liuqi$
> > > > >> >
> > > > >> >  ticket-id: #5839
> > > > >> >
> > > > >> > Signed-off-by: Steven Liu <lingjiujianke@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@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@0
> >  output-test0.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:721356@1334988
> >  output-test0.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:735832@2056344
> >  output-test0.ts
> >  #EXTINF:6.000000,
> >  #EXT-X-BYTERANGE:1645940@0
> >  output-test3.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:715152@1645940
> >  output-test3.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:751436@2361092
> >  output-test3.ts
> >  #EXTINF:9.000000,
> >  #EXT-X-BYTERANGE:3377420@0
> >  output-test6.ts
> >  #EXTINF:3.960000,
> >  #EXT-X-BYTERANGE:1228016@0
> >  output-test7.ts
> >  #EXT-X-ENDLIST
> >  localhost:ffmpeg liuqi$
> >
> >  ticket-id: #5839
> >
> > Signed-off-by: Steven Liu <lingjiujianke@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 ?
>
> [...]
> patch update.
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
Michael Niedermayer Sept. 13, 2016, 12:20 a.m. UTC | #8
On Tue, Sep 13, 2016 at 06:49:41AM +0800, Steven Liu wrote:
> 2016-09-13 6:19 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:
> 
> > On Mon, Sep 12, 2016 at 07:04:54PM +0800, Steven Liu wrote:
> > > 2016-09-12 18:52 GMT+08:00 Michael Niedermayer <michael@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@gmail.com>:
> > > > >
> > > > > >
> > > > > >
> > > > > > 2016-09-12 17:28 GMT+08:00 Michael Niedermayer
> > <michael@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@0
> > > > > >> >  output-test0.ts
> > > > > >> >  #EXTINF:3.000000,
> > > > > >> >  #EXT-X-BYTERANGE:721356@1334988
> > > > > >> >  output-test0.ts
> > > > > >> >  #EXTINF:3.000000,
> > > > > >> >  #EXT-X-BYTERANGE:735832@2056344
> > > > > >> >  output-test0.ts
> > > > > >> >  #EXTINF:6.000000,
> > > > > >> >  #EXT-X-BYTERANGE:1645940@0
> > > > > >> >  output-test3.ts
> > > > > >> >  #EXTINF:3.000000,
> > > > > >> >  #EXT-X-BYTERANGE:715152@1645940
> > > > > >> >  output-test3.ts
> > > > > >> >  #EXTINF:3.000000,
> > > > > >> >  #EXT-X-BYTERANGE:751436@2361092
> > > > > >> >  output-test3.ts
> > > > > >> >  #EXTINF:9.000000,
> > > > > >> >  #EXT-X-BYTERANGE:3377420@0
> > > > > >> >  output-test6.ts
> > > > > >> >  #EXTINF:3.960000,
> > > > > >> >  #EXT-X-BYTERANGE:1228016@0
> > > > > >> >  output-test7.ts
> > > > > >> >  #EXT-X-ENDLIST
> > > > > >> >  localhost:ffmpeg liuqi$
> > > > > >> >
> > > > > >> >  ticket-id: #5839
> > > > > >> >
> > > > > >> > Signed-off-by: Steven Liu <lingjiujianke@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@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@0
> > >  output-test0.ts
> > >  #EXTINF:3.000000,
> > >  #EXT-X-BYTERANGE:721356@1334988
> > >  output-test0.ts
> > >  #EXTINF:3.000000,
> > >  #EXT-X-BYTERANGE:735832@2056344
> > >  output-test0.ts
> > >  #EXTINF:6.000000,
> > >  #EXT-X-BYTERANGE:1645940@0
> > >  output-test3.ts
> > >  #EXTINF:3.000000,
> > >  #EXT-X-BYTERANGE:715152@1645940
> > >  output-test3.ts
> > >  #EXTINF:3.000000,
> > >  #EXT-X-BYTERANGE:751436@2361092
> > >  output-test3.ts
> > >  #EXTINF:9.000000,
> > >  #EXT-X-BYTERANGE:3377420@0
> > >  output-test6.ts
> > >  #EXTINF:3.960000,
> > >  #EXT-X-BYTERANGE:1228016@0
> > >  output-test7.ts
> > >  #EXT-X-ENDLIST
> > >  localhost:ffmpeg liuqi$
> > >
> > >  ticket-id: #5839
> > >
> > > Signed-off-by: Steven Liu <lingjiujianke@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 ?
> >
> > [...]
> > patch update.
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> >

>  hlsenc.c |   33 ++++++++++++++++++++++++++++++---
>  1 file changed, 30 insertions(+), 3 deletions(-)
> 79f261d7ffd51c34366cb3aee212f9ac69c11fcf  0001-avformat-hlsenc-refine-EXT-X-BYTERANGE-support-for-s.patch
> From a7b11ee449002480d2460934cca009088912c8e3 Mon Sep 17 00:00:00 2001
> From: LiuQi <liuqi@gosun.com>
> Date: Tue, 13 Sep 2016 06:47:23 +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@0
>  output-test0.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:721356@1334988
>  output-test0.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:735832@2056344
>  output-test0.ts
>  #EXTINF:6.000000,
>  #EXT-X-BYTERANGE:1645940@0
>  output-test3.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:715152@1645940
>  output-test3.ts
>  #EXTINF:3.000000,
>  #EXT-X-BYTERANGE:751436@2361092
>  output-test3.ts
>  #EXTINF:9.000000,
>  #EXT-X-BYTERANGE:3377420@0
>  output-test6.ts
>  #EXTINF:3.960000,
>  #EXT-X-BYTERANGE:1228016@0
>  output-test7.ts
>  #EXT-X-ENDLIST
>  localhost:ffmpeg liuqi$
>

>  ticket-id: #5839

I see the ticket author intendes to test this and also had some review
coments 

[...]
Steven Liu Sept. 13, 2016, 3:25 a.m. UTC | #9
2016-09-13 8:20 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:

> On Tue, Sep 13, 2016 at 06:49:41AM +0800, Steven Liu wrote:
> > 2016-09-13 6:19 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:
> >
> > > On Mon, Sep 12, 2016 at 07:04:54PM +0800, Steven Liu wrote:
> > > > 2016-09-12 18:52 GMT+08:00 Michael Niedermayer
> <michael@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@gmail.com>:
> > > > > >
> > > > > > >
> > > > > > >
> > > > > > > 2016-09-12 17:28 GMT+08:00 Michael Niedermayer
> > > <michael@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@0
> > > > > > >> >  output-test0.ts
> > > > > > >> >  #EXTINF:3.000000,
> > > > > > >> >  #EXT-X-BYTERANGE:721356@1334988
> > > > > > >> >  output-test0.ts
> > > > > > >> >  #EXTINF:3.000000,
> > > > > > >> >  #EXT-X-BYTERANGE:735832@2056344
> > > > > > >> >  output-test0.ts
> > > > > > >> >  #EXTINF:6.000000,
> > > > > > >> >  #EXT-X-BYTERANGE:1645940@0
> > > > > > >> >  output-test3.ts
> > > > > > >> >  #EXTINF:3.000000,
> > > > > > >> >  #EXT-X-BYTERANGE:715152@1645940
> > > > > > >> >  output-test3.ts
> > > > > > >> >  #EXTINF:3.000000,
> > > > > > >> >  #EXT-X-BYTERANGE:751436@2361092
> > > > > > >> >  output-test3.ts
> > > > > > >> >  #EXTINF:9.000000,
> > > > > > >> >  #EXT-X-BYTERANGE:3377420@0
> > > > > > >> >  output-test6.ts
> > > > > > >> >  #EXTINF:3.960000,
> > > > > > >> >  #EXT-X-BYTERANGE:1228016@0
> > > > > > >> >  output-test7.ts
> > > > > > >> >  #EXT-X-ENDLIST
> > > > > > >> >  localhost:ffmpeg liuqi$
> > > > > > >> >
> > > > > > >> >  ticket-id: #5839
> > > > > > >> >
> > > > > > >> > Signed-off-by: Steven Liu <lingjiujianke@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@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@0
> > > >  output-test0.ts
> > > >  #EXTINF:3.000000,
> > > >  #EXT-X-BYTERANGE:721356@1334988
> > > >  output-test0.ts
> > > >  #EXTINF:3.000000,
> > > >  #EXT-X-BYTERANGE:735832@2056344
> > > >  output-test0.ts
> > > >  #EXTINF:6.000000,
> > > >  #EXT-X-BYTERANGE:1645940@0
> > > >  output-test3.ts
> > > >  #EXTINF:3.000000,
> > > >  #EXT-X-BYTERANGE:715152@1645940
> > > >  output-test3.ts
> > > >  #EXTINF:3.000000,
> > > >  #EXT-X-BYTERANGE:751436@2361092
> > > >  output-test3.ts
> > > >  #EXTINF:9.000000,
> > > >  #EXT-X-BYTERANGE:3377420@0
> > > >  output-test6.ts
> > > >  #EXTINF:3.960000,
> > > >  #EXT-X-BYTERANGE:1228016@0
> > > >  output-test7.ts
> > > >  #EXT-X-ENDLIST
> > > >  localhost:ffmpeg liuqi$
> > > >
> > > >  ticket-id: #5839
> > > >
> > > > Signed-off-by: Steven Liu <lingjiujianke@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 ?
> > >
> > > [...]
> > > patch update.
> > >
> > > _______________________________________________
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >
> > >
>
> >  hlsenc.c |   33 ++++++++++++++++++++++++++++++---
> >  1 file changed, 30 insertions(+), 3 deletions(-)
> > 79f261d7ffd51c34366cb3aee212f9ac69c11fcf  0001-avformat-hlsenc-refine-
> EXT-X-BYTERANGE-support-for-s.patch
> > From a7b11ee449002480d2460934cca009088912c8e3 Mon Sep 17 00:00:00 2001
> > From: LiuQi <liuqi@gosun.com>
> > Date: Tue, 13 Sep 2016 06:47:23 +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@0
> >  output-test0.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:721356@1334988
> >  output-test0.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:735832@2056344
> >  output-test0.ts
> >  #EXTINF:6.000000,
> >  #EXT-X-BYTERANGE:1645940@0
> >  output-test3.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:715152@1645940
> >  output-test3.ts
> >  #EXTINF:3.000000,
> >  #EXT-X-BYTERANGE:751436@2361092
> >  output-test3.ts
> >  #EXTINF:9.000000,
> >  #EXT-X-BYTERANGE:3377420@0
> >  output-test6.ts
> >  #EXTINF:3.960000,
> >  #EXT-X-BYTERANGE:1228016@0
> >  output-test7.ts
> >  #EXT-X-ENDLIST
> >  localhost:ffmpeg liuqi$
> >
>
> >  ticket-id: #5839
>
> I see the ticket author intendes to test this and also had some review
> coments
>
> [...]
>
> update patch,
Moritz Barsnick Sept. 13, 2016, 6:53 p.m. UTC | #10
On Tue, Sep 13, 2016 at 11:25:39 +0800, Steven Liu wrote:
> +    int byterange_mode = hls->flags & (HLS_SINGLE_FILE) || hls->max_seg_size > 0;
                                         ^               ^
Why the bracket?

> +                av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s' you can try use -use_localtime 1 with it\n", c->basename);
Rather:
                   av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s', you can try to use -use_localtime 1 with it\n", c->basename);

> +    {"hls_segment_size", "set maximum size per segment file, (Byte)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
       {"hls_segment_size", "set maximum size per segment file (in bytes)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},

This isn't a flag, right? Perhaps you shouldn't be putting the option
between the flags' lines (but probably still as the final option).

The value of 0 seems to have a special meaning. Is this documented
anywhere? In other words: You should also update doc/muxers.texi. (I
can help with the grammar of the wording.)

Moritz
Steven Liu Sept. 13, 2016, 10:51 p.m. UTC | #11
2016-09-14 2:53 GMT+08:00 Moritz Barsnick <barsnick@gmx.net>:

> On Tue, Sep 13, 2016 at 11:25:39 +0800, Steven Liu wrote:
> > +    int byterange_mode = hls->flags & (HLS_SINGLE_FILE) ||
> hls->max_seg_size > 0;
>                                          ^               ^
> Why the bracket?
>
> > +                av_log(oc, AV_LOG_ERROR, "Invalid segment filename
> template '%s' you can try use -use_localtime 1 with it\n", c->basename);
> Rather:
>                    av_log(oc, AV_LOG_ERROR, "Invalid segment filename
> template '%s', you can try to use -use_localtime 1 with it\n", c->basename);
>
> > +    {"hls_segment_size", "set maximum size per segment file, (Byte)",
> OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
>        {"hls_segment_size", "set maximum size per segment file (in
> bytes)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},     0,
> INT_MAX, E},
>
> This isn't a flag, right? Perhaps you shouldn't be putting the option
> between the flags' lines (but probably still as the final option).
>
I shall update patch :-)

>
> The value of 0 seems to have a special meaning. Is this documented
>
I cannot understand "The value of 0 seems to have a special meaning" ,
it will not set value when unuse hls_segment_size, so give it value of 0.
is that a problem?

> anywhere? In other words: You should also update doc/muxers.texi. (I
> can help with the grammar of the wording.)
>
patch will come soon :-D

>
> Moritz
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Steven Liu Sept. 15, 2016, 12:31 p.m. UTC | #12
2016-09-14 6:51 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:

>
>
> 2016-09-14 2:53 GMT+08:00 Moritz Barsnick <barsnick@gmx.net>:
>
>> On Tue, Sep 13, 2016 at 11:25:39 +0800, Steven Liu wrote:
>> > +    int byterange_mode = hls->flags & (HLS_SINGLE_FILE) ||
>> hls->max_seg_size > 0;
>>                                          ^               ^
>> Why the bracket?
>>
>> > +                av_log(oc, AV_LOG_ERROR, "Invalid segment filename
>> template '%s' you can try use -use_localtime 1 with it\n", c->basename);
>> Rather:
>>                    av_log(oc, AV_LOG_ERROR, "Invalid segment filename
>> template '%s', you can try to use -use_localtime 1 with it\n", c->basename);
>>
>> > +    {"hls_segment_size", "set maximum size per segment file, (Byte)",
>> OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
>>        {"hls_segment_size", "set maximum size per segment file (in
>> bytes)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},     0,
>> INT_MAX, E},
>>
>> This isn't a flag, right? Perhaps you shouldn't be putting the option
>> between the flags' lines (but probably still as the final option).
>>
> I shall update patch :-)
>
>>
>> The value of 0 seems to have a special meaning. Is this documented
>>
> I cannot understand "The value of 0 seems to have a special meaning" ,
> it will not set value when unuse hls_segment_size, so give it value of 0.
> is that a problem?
>
>> anywhere? In other words: You should also update doc/muxers.texi. (I
>> can help with the grammar of the wording.)
>>
> patch will come soon :-D
>
>>
>>
patch update
Steven Liu Sept. 17, 2016, 5:09 a.m. UTC | #13
2016-09-15 20:31 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:

>
>
> 2016-09-14 6:51 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:
>
>>
>>
>> 2016-09-14 2:53 GMT+08:00 Moritz Barsnick <barsnick@gmx.net>:
>>
>>> On Tue, Sep 13, 2016 at 11:25:39 +0800, Steven Liu wrote:
>>> > +    int byterange_mode = hls->flags & (HLS_SINGLE_FILE) ||
>>> hls->max_seg_size > 0;
>>>                                          ^               ^
>>> Why the bracket?
>>>
>>> > +                av_log(oc, AV_LOG_ERROR, "Invalid segment filename
>>> template '%s' you can try use -use_localtime 1 with it\n", c->basename);
>>> Rather:
>>>                    av_log(oc, AV_LOG_ERROR, "Invalid segment filename
>>> template '%s', you can try to use -use_localtime 1 with it\n", c->basename);
>>>
>>> > +    {"hls_segment_size", "set maximum size per segment file,
>>> (Byte)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},     0,
>>> INT_MAX, E},
>>>        {"hls_segment_size", "set maximum size per segment file (in
>>> bytes)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},     0,
>>> INT_MAX, E},
>>>
>>> This isn't a flag, right? Perhaps you shouldn't be putting the option
>>> between the flags' lines (but probably still as the final option).
>>>
>> I shall update patch :-)
>>
>>>
>>> The value of 0 seems to have a special meaning. Is this documented
>>>
>> I cannot understand "The value of 0 seems to have a special meaning" ,
>> it will not set value when unuse hls_segment_size, so give it value of 0.
>> is that a problem?
>>
>>> anywhere? In other words: You should also update doc/muxers.texi. (I
>>> can help with the grammar of the wording.)
>>>
>> patch will come soon :-D
>>
>>>
>>>
> patch update
>
>
patch update,
give a warning message when video bitrate large than hls_segment_size.
Michael Niedermayer Sept. 17, 2016, 5:07 p.m. UTC | #14
On Sat, Sep 17, 2016 at 01:09:02PM +0800, Steven Liu wrote:
[...]
> @@ -867,6 +886,16 @@ static int hls_write_header(AVFormatContext *s)
>      for (i = 0; i < s->nb_streams; i++) {
>          AVStream *inner_st;
>          AVStream *outer_st = s->streams[i];
> +
> +        if (hls->max_seg_size > 0) {
> +            if ((outer_st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
> +                outer_st->codecpar->bit_rate > hls->max_seg_size) {
> +                av_log(s, AV_LOG_WARNING, "Your video bitrate is bigger than hls_segment_size, "
> +                       "%lld > %lld ( video birate > hls_segment_size ),the result maybe not you want.",
> +                       outer_st->codecpar->bit_rate, hls->max_seg_size);

%lld is the wrong type for *int64_t

The compiler should produce a warning for this, though probably not
every copiler does
please make sure your changes add no warnings

[...]
Steven Liu Sept. 17, 2016, 11:28 p.m. UTC | #15
2016-09-18 1:07 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:

> On Sat, Sep 17, 2016 at 01:09:02PM +0800, Steven Liu wrote:
> [...]
> > @@ -867,6 +886,16 @@ static int hls_write_header(AVFormatContext *s)
> >      for (i = 0; i < s->nb_streams; i++) {
> >          AVStream *inner_st;
> >          AVStream *outer_st = s->streams[i];
> > +
> > +        if (hls->max_seg_size > 0) {
> > +            if ((outer_st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
> &&
> > +                outer_st->codecpar->bit_rate > hls->max_seg_size) {
> > +                av_log(s, AV_LOG_WARNING, "Your video bitrate is bigger
> than hls_segment_size, "
> > +                       "%lld > %lld ( video birate > hls_segment_size
> ),the result maybe not you want.",
> > +                       outer_st->codecpar->bit_rate, hls->max_seg_size);
>
> %lld is the wrong type for *int64_t
>
> The compiler should produce a warning for this, though probably not
> every copiler does
> please make sure your changes add no warnings
>


Hi Michael,


Bellow is my compile history before i send the last patch mail, maybe i
need cross complie cross any platform:


localhost:xxx StevenLiu$ make
CC libavformat/hlsenc.o
src/libavformat/hlsenc.c:326:14: error: use of undeclared identifier 'st'
        if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
             ^
src/libavformat/hlsenc.c:327:13: error: use of undeclared identifier 'st'
            st->codecpar->bit_rate > hls->max_seg_size) {
            ^
src/libavformat/hlsenc.c:330:20: error: use of undeclared identifier 'st'
                   st->codecpar->bit_rate, hls->max_seg_size);
                   ^
src/libavformat/hlsenc.c:573:27: warning: absolute value function 'abs'
given an argument of type 'long' but has parameter of type 'int' which may
cause truncation of value [-Wabsolute-value]
                tz_min = (abs(wrongsecs - tt) + 30) / 60;
                          ^
src/libavformat/hlsenc.c:573:27: note: use function 'labs' instead
                tz_min = (abs(wrongsecs - tt) + 30) / 60;
                          ^~~
                          labs
1 warning and 3 errors generated.
make: *** [libavformat/hlsenc.o] Error 1
localhost:xxx StevenLiu$ make
CC libavformat/hlsenc.o
src/libavformat/hlsenc.c:564:27: warning: absolute value function 'abs'
given an argument of type 'long' but has parameter of type 'int' which may
cause truncation of value [-Wabsolute-value]
                tz_min = (abs(wrongsecs - tt) + 30) / 60;
                          ^
src/libavformat/hlsenc.c:564:27: note: use function 'labs' instead
                tz_min = (abs(wrongsecs - tt) + 30) / 60;
                          ^~~
                          labs
src/libavformat/hlsenc.c:890:18: error: use of undeclared identifier 'st'
            if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
                 ^
src/libavformat/hlsenc.c:891:17: error: use of undeclared identifier 'st'
                st->codecpar->bit_rate > hls->max_seg_size) {
                ^
src/libavformat/hlsenc.c:894:24: error: use of undeclared identifier 'st'
                       st->codecpar->bit_rate, hls->max_seg_size);
                       ^
1 warning and 3 errors generated.
make: *** [libavformat/hlsenc.o] Error 1
localhost:xxx StevenLiu$
localhost:xxx StevenLiu$
localhost:xxx StevenLiu$ make
CC libavformat/hlsenc.o
src/libavformat/hlsenc.c:564:27: warning: absolute value function 'abs'
given an argument of type 'long' but has parameter of type 'int' which may
cause truncation of value [-Wabsolute-value]
                tz_min = (abs(wrongsecs - tt) + 30) / 60;
                          ^
src/libavformat/hlsenc.c:564:27: note: use function 'labs' instead
                tz_min = (abs(wrongsecs - tt) + 30) / 60;
                          ^~~
                          labs
1 warning generated.
AR libavformat/libavformat.a
LD ffmpeg_g
CP ffmpeg
STRIP ffmpeg
LD ffplay_g
CP ffplay
STRIP ffplay
LD ffprobe_g
CP ffprobe
STRIP ffprobe
LD ffserver_g
CP ffserver
STRIP ffserver
localhost:xxx StevenLiu$
Steven Liu Sept. 18, 2016, 3:40 p.m. UTC | #16
2016-09-18 7:28 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:

>
>
> 2016-09-18 1:07 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:
>
>> On Sat, Sep 17, 2016 at 01:09:02PM +0800, Steven Liu wrote:
>> [...]
>> > @@ -867,6 +886,16 @@ static int hls_write_header(AVFormatContext *s)
>> >      for (i = 0; i < s->nb_streams; i++) {
>> >          AVStream *inner_st;
>> >          AVStream *outer_st = s->streams[i];
>> > +
>> > +        if (hls->max_seg_size > 0) {
>> > +            if ((outer_st->codecpar->codec_type ==
>> AVMEDIA_TYPE_VIDEO) &&
>> > +                outer_st->codecpar->bit_rate > hls->max_seg_size) {
>> > +                av_log(s, AV_LOG_WARNING, "Your video bitrate is
>> bigger than hls_segment_size, "
>> > +                       "%lld > %lld ( video birate > hls_segment_size
>> ),the result maybe not you want.",
>> > +                       outer_st->codecpar->bit_rate,
>> hls->max_seg_size);
>>
>> %lld is the wrong type for *int64_t
>>
>> The compiler should produce a warning for this, though probably not
>> every copiler does
>> please make sure your changes add no warnings
>>
>
>
> Hi Michael,
>
>
> Bellow is my compile history before i send the last patch mail, maybe i
> need cross complie cross any platform:
>
>
> localhost:xxx StevenLiu$ make
> CC libavformat/hlsenc.o
> src/libavformat/hlsenc.c:326:14: error: use of undeclared identifier 'st'
>         if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
>              ^
> src/libavformat/hlsenc.c:327:13: error: use of undeclared identifier 'st'
>             st->codecpar->bit_rate > hls->max_seg_size) {
>             ^
> src/libavformat/hlsenc.c:330:20: error: use of undeclared identifier 'st'
>                    st->codecpar->bit_rate, hls->max_seg_size);
>                    ^
> src/libavformat/hlsenc.c:573:27: warning: absolute value function 'abs'
> given an argument of type 'long' but has parameter of type 'int' which may
> cause truncation of value [-Wabsolute-value]
>                 tz_min = (abs(wrongsecs - tt) + 30) / 60;
>                           ^
> src/libavformat/hlsenc.c:573:27: note: use function 'labs' instead
>                 tz_min = (abs(wrongsecs - tt) + 30) / 60;
>                           ^~~
>                           labs
> 1 warning and 3 errors generated.
> make: *** [libavformat/hlsenc.o] Error 1
> localhost:xxx StevenLiu$ make
> CC libavformat/hlsenc.o
> src/libavformat/hlsenc.c:564:27: warning: absolute value function 'abs'
> given an argument of type 'long' but has parameter of type 'int' which may
> cause truncation of value [-Wabsolute-value]
>                 tz_min = (abs(wrongsecs - tt) + 30) / 60;
>                           ^
> src/libavformat/hlsenc.c:564:27: note: use function 'labs' instead
>                 tz_min = (abs(wrongsecs - tt) + 30) / 60;
>                           ^~~
>                           labs
> src/libavformat/hlsenc.c:890:18: error: use of undeclared identifier 'st'
>             if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
>                  ^
> src/libavformat/hlsenc.c:891:17: error: use of undeclared identifier 'st'
>                 st->codecpar->bit_rate > hls->max_seg_size) {
>                 ^
> src/libavformat/hlsenc.c:894:24: error: use of undeclared identifier 'st'
>                        st->codecpar->bit_rate, hls->max_seg_size);
>                        ^
> 1 warning and 3 errors generated.
> make: *** [libavformat/hlsenc.o] Error 1
> localhost:xxx StevenLiu$
> localhost:xxx StevenLiu$
> localhost:xxx StevenLiu$ make
> CC libavformat/hlsenc.o
> src/libavformat/hlsenc.c:564:27: warning: absolute value function 'abs'
> given an argument of type 'long' but has parameter of type 'int' which may
> cause truncation of value [-Wabsolute-value]
>                 tz_min = (abs(wrongsecs - tt) + 30) / 60;
>                           ^
> src/libavformat/hlsenc.c:564:27: note: use function 'labs' instead
>                 tz_min = (abs(wrongsecs - tt) + 30) / 60;
>                           ^~~
>                           labs
> 1 warning generated.
> AR libavformat/libavformat.a
> LD ffmpeg_g
> CP ffmpeg
> STRIP ffmpeg
> LD ffplay_g
> CP ffplay
> STRIP ffplay
> LD ffprobe_g
> CP ffprobe
> STRIP ffprobe
> LD ffserver_g
> CP ffserver
> STRIP ffserver
> localhost:xxx StevenLiu$
>
>
>
patch update,

    fix warning for complie, from lld to PRId64
Moritz Barsnick Sept. 18, 2016, 4:24 p.m. UTC | #17
On Sun, Sep 18, 2016 at 23:40:34 +0800, Steven Liu wrote:

> +    if (byterange_mode) {
> +        version = 4;
> +        sequence = byterange_mode ? 0 : sequence;

What does the ternary if-then-else operation do here? Two lines above,
byterange_mode was checked for !=0, how can it be anything else here?

> +                av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s', you can try use -use_localtime 1 with it\n", c->basename);

"try to use"

> +            if ((outer_st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
> +                outer_st->codecpar->bit_rate > hls->max_seg_size) {

Inconsistent use of brackets: The "==" comparison has extra brackets,
the ">" comparison doesn't. (Or am I missing something with operator
precedence?)

> +                av_log(s, AV_LOG_WARNING, "Your video bitrate is bigger than hls_segment_size, "
> +                       "%"PRId64 " > %" PRId64" ( video birate > hls_segment_size ),the result maybe not you want.",

Apart from the peculiar placement of brackets in the message, I think
the brackets and their content is not needed, duplicate.

And the sentence should end "the result may not be what you want".

> +            if (hls->start_pos >= hls->max_seg_size ) {

Wrong bracket style (whitespace).

> +    {"hls_segment_size", "set maximum size per segment file, (in bytes)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},           0,       INT_MAX,   E},

You can actually drop the word "set ", as well as the comma before the
brackets.

Moritz
Steven Liu Sept. 18, 2016, 11:01 p.m. UTC | #18
2016-09-19 0:24 GMT+08:00 Moritz Barsnick <barsnick@gmx.net>:

> On Sun, Sep 18, 2016 at 23:40:34 +0800, Steven Liu wrote:
>
> > +    if (byterange_mode) {
> > +        version = 4;
> > +        sequence = byterange_mode ? 0 : sequence;
>
> What does the ternary if-then-else operation do here? Two lines above,
> byterange_mode was checked for !=0, how can it be anything else here?
>
> > +                av_log(oc, AV_LOG_ERROR, "Invalid segment filename
> template '%s', you can try use -use_localtime 1 with it\n", c->basename);
>
> "try to use"
>
> > +            if ((outer_st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
> &&
> > +                outer_st->codecpar->bit_rate > hls->max_seg_size) {
>
> Inconsistent use of brackets: The "==" comparison has extra brackets,
> the ">" comparison doesn't. (Or am I missing something with operator
> precedence?)
>
> > +                av_log(s, AV_LOG_WARNING, "Your video bitrate is bigger
> than hls_segment_size, "
> > +                       "%"PRId64 " > %" PRId64" ( video birate >
> hls_segment_size ),the result maybe not you want.",
>
> Apart from the peculiar placement of brackets in the message, I think
> the brackets and their content is not needed, duplicate.
>
> And the sentence should end "the result may not be what you want".
>
> > +            if (hls->start_pos >= hls->max_seg_size ) {
>
> Wrong bracket style (whitespace).
>
> > +    {"hls_segment_size", "set maximum size per segment file, (in
> bytes)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},
>  0,       INT_MAX,   E},
>
> You can actually drop the word "set ", as well as the comma before the
> brackets.
>
> Moritz
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Steven Liu Sept. 23, 2016, 11:02 a.m. UTC | #19
ping

2016-09-19 7:01 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:

>
>
> 2016-09-19 0:24 GMT+08:00 Moritz Barsnick <barsnick@gmx.net>:
>
>> On Sun, Sep 18, 2016 at 23:40:34 +0800, Steven Liu wrote:
>>
>> > +    if (byterange_mode) {
>> > +        version = 4;
>> > +        sequence = byterange_mode ? 0 : sequence;
>>
>> What does the ternary if-then-else operation do here? Two lines above,
>> byterange_mode was checked for !=0, how can it be anything else here?
>>
>> > +                av_log(oc, AV_LOG_ERROR, "Invalid segment filename
>> template '%s', you can try use -use_localtime 1 with it\n", c->basename);
>>
>> "try to use"
>>
>> > +            if ((outer_st->codecpar->codec_type ==
>> AVMEDIA_TYPE_VIDEO) &&
>> > +                outer_st->codecpar->bit_rate > hls->max_seg_size) {
>>
>> Inconsistent use of brackets: The "==" comparison has extra brackets,
>> the ">" comparison doesn't. (Or am I missing something with operator
>> precedence?)
>>
>> > +                av_log(s, AV_LOG_WARNING, "Your video bitrate is
>> bigger than hls_segment_size, "
>> > +                       "%"PRId64 " > %" PRId64" ( video birate >
>> hls_segment_size ),the result maybe not you want.",
>>
>> Apart from the peculiar placement of brackets in the message, I think
>> the brackets and their content is not needed, duplicate.
>>
>> And the sentence should end "the result may not be what you want".
>>
>> > +            if (hls->start_pos >= hls->max_seg_size ) {
>>
>> Wrong bracket style (whitespace).
>>
>> > +    {"hls_segment_size", "set maximum size per segment file, (in
>> bytes)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},
>>  0,       INT_MAX,   E},
>>
>> You can actually drop the word "set ", as well as the comma before the
>> brackets.
>>
>> Moritz
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
Michael Niedermayer Sept. 24, 2016, 2:28 a.m. UTC | #20
On Mon, Sep 19, 2016 at 07:01:49AM +0800, Steven Liu wrote:
> 2016-09-19 0:24 GMT+08:00 Moritz Barsnick <barsnick@gmx.net>:
> 
> > On Sun, Sep 18, 2016 at 23:40:34 +0800, Steven Liu wrote:
> >
> > > +    if (byterange_mode) {
> > > +        version = 4;
> > > +        sequence = byterange_mode ? 0 : sequence;
> >
> > What does the ternary if-then-else operation do here? Two lines above,
> > byterange_mode was checked for !=0, how can it be anything else here?
> >
> > > +                av_log(oc, AV_LOG_ERROR, "Invalid segment filename
> > template '%s', you can try use -use_localtime 1 with it\n", c->basename);
> >
> > "try to use"
> >
> > > +            if ((outer_st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
> > &&
> > > +                outer_st->codecpar->bit_rate > hls->max_seg_size) {
> >
> > Inconsistent use of brackets: The "==" comparison has extra brackets,
> > the ">" comparison doesn't. (Or am I missing something with operator
> > precedence?)
> >
> > > +                av_log(s, AV_LOG_WARNING, "Your video bitrate is bigger
> > than hls_segment_size, "
> > > +                       "%"PRId64 " > %" PRId64" ( video birate >
> > hls_segment_size ),the result maybe not you want.",
> >
> > Apart from the peculiar placement of brackets in the message, I think
> > the brackets and their content is not needed, duplicate.
> >
> > And the sentence should end "the result may not be what you want".
> >
> > > +            if (hls->start_pos >= hls->max_seg_size ) {
> >
> > Wrong bracket style (whitespace).
> >
> > > +    {"hls_segment_size", "set maximum size per segment file, (in
> > bytes)",  OFFSET(max_seg_size),    AV_OPT_TYPE_INT,    {.i64 = 0},
> >  0,       INT_MAX,   E},
> >
> > You can actually drop the word "set ", as well as the comma before the
> > brackets.
> >
> > Moritz
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >

>  hlsenc.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 46 insertions(+), 3 deletions(-)
> 32c8c1dad25c71a089d1ef4c912de46e8b05f17a  0001-avformat-hlsenc-refine-EXT-X-BYTERANGE-support-for-s.patch
> From 3a8731792d681caec8ff49e01b1b175c00b9e1ee Mon Sep 17 00:00:00 2001
> From: Steven Liu <lingjiujianke@gmail.com>
> Date: Mon, 19 Sep 2016 07:00:42 +0800
> Subject: [PATCH] avformat/hlsenc: refine EXT-X-BYTERANGE support for segments

applied

thanks

[...]
diff mbox

Patch

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;