[FFmpeg-devel] [PATCH] add append_list flag into hlsenc

Steven Liu lingjiujianke at gmail.com
Sat Aug 20 16:48:49 EEST 2016


2016-08-20 19:51 GMT+08:00 Michael Niedermayer <michael at niedermayer.cc>:

> On Thu, Aug 11, 2016 at 11:04:43PM +0800, Steven Liu wrote:
> > When ffmpeg exit by exception, start a new ffmpeg will cover the old
> > segment list, add this flag can continue append the new segments into old
> > hls segment list
> [...]
>
> > +static int parse_playlist(AVFormatContext *s, const char *url)
> > +{
> > +    HLSContext *hls = s->priv_data;
> > +    AVIOContext *in;
> > +    int ret = 0, is_segment = 0;
> > +    int64_t new_start_pos;
> > +    int64_t duration = 0;
> > +    char line[1024];
> > +    const char *ptr;
> > +
> > +    if ((ret = ffio_open_whitelist(&in, url, AVIO_FLAG_READ,
> > +                                   &s->interrupt_callback, NULL,
> > +                                   s->protocol_whitelist,
> s->protocol_blacklist)) < 0)
> > +        return ret;
> > +
> > +    read_chomp_line(in, line, sizeof(line));
> > +    if (strcmp(line, "#EXTM3U")) {
> > +        ret = AVERROR_INVALIDDATA;
> > +        goto fail;
> > +    }
> > +
> > +    while (!avio_feof(in)) {
> > +        read_chomp_line(in, line, sizeof(line));
> > +        if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
>
> > +            duration = atoi(ptr);
>
> the set duration here is never used
>
ok, I'll remove this duration, and ignore this TAG and  EXT-X-ENDLIST

>
>
> > +        } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
> > +            hls->sequence = atoi(ptr);
> > +        } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) {
> > +        } else if (av_strstart(line, "#EXTINF:", &ptr)) {
> > +            is_segment = 1;
>
> > +            hls->duration = atof(ptr);
>
> this here is used
> is that intended ?
>
Yes, create the hls info when parsing the old list, write the info looks
like hls_write_packet.


>
>
> > +        } else if (av_strstart(line, "#", NULL)) {
> > +            continue;
> > +        } else if (line[0]) {
> > +            if (is_segment) {
> > +                new_start_pos = avio_tell(hls->avf->pb);
> > +                hls->size = new_start_pos - hls->start_pos;
> > +                av_strlcpy(hls->avf->filename, line, sizeof(line));
> > +                hls_append_segment(s, hls, hls->duration,
> hls->start_pos, hls->size);
> > +                is_segment = 0;
> > +            }
> > +        }
> > +    }
> > +
> > +fail:
> > +    avio_close(in);
> > +    return ret;
> > +}
> > +
> >  static void hls_free_segments(HLSSegment *p)
> >  {
> >      HLSSegment *en;
> > @@ -752,6 +810,10 @@ static int hls_write_header(AVFormatContext *s)
> >      if ((ret = hls_mux_init(s)) < 0)
> >          goto fail;
> >
> > +    if (hls->flags & HLS_APPEND_LIST) {
> > +        parse_playlist(s, s->filename);
> > +    }
> > +
> >      if ((ret = hls_start(s)) < 0)
> >          goto fail;
> >
> > @@ -927,6 +989,7 @@ static const AVOption options[] = {
> >      {"discont_start", "start the playlist with a discontinuity tag", 0,
> AV_OPT_TYPE_CONST, {.i64 = HLS_DISCONT_START }, 0, UINT_MAX,   E, "flags"},
> >      {"omit_endlist", "Do not append an endlist when ending stream", 0,
> AV_OPT_TYPE_CONST, {.i64 = HLS_OMIT_ENDLIST }, 0, UINT_MAX,   E, "flags"},
> >      {"split_by_time", "split the hls segment by time which user set by
> hls_time", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SPLIT_BY_TIME }, 0, UINT_MAX,
>  E, "flags"},
> > +    {"append_list", "append the new segments into old hls segment
> list", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_APPEND_LIST }, 0, UINT_MAX,   E,
> "flags"},
> >      {"use_localtime", "set filename expansion with strftime at segment
> creation", OFFSET(use_localtime), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
> >      {"use_localtime_mkdir", "create last directory component in
> strftime-generated filename", OFFSET(use_localtime_mkdir),
> AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
> >      {"hls_playlist_type", "set the HLS playlist type", OFFSET(pl_type),
> AV_OPT_TYPE_INT, {.i64 = PLAYLIST_TYPE_NONE }, 0, PLAYLIST_TYPE_NB-1, E,
> "pl_type" },
> > --
> > 2.7.4 (Apple Git-66)
> >
>
>
>
I will resend a new patch fix the above problem.


More information about the ffmpeg-devel mailing list