[PATCH] avformat/hls: Added subtitle support
This patch is a fix for ticket #2833. Each subtitle segment is its own WebVTT file and has to demuxed individually. The timing of the subtitles are not perfect but it is the best I could do and it also does not take into account the X-TIMESTAMP-MAP header in the WebVTT files which is needed to conform to the specification (https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5). Signed-off-by: Franklin Phillips <franklinphillips@gmx.com> --- libavformat/hls.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 159 insertions(+), 19 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 3ae3c7c..bf13be4 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -153,6 +153,8 @@ struct playlist { * playlist, if any. */ int n_init_sections; struct segment **init_sections; + + int is_subtitle; /* Indicates if the playlist is for subtitles */ }; /* @@ -312,6 +314,8 @@ static struct playlist *new_playlist(HLSContext *c, const char *url, pls->is_id3_timestamped = -1; pls->id3_mpegts_timestamp = AV_NOPTS_VALUE; + pls->is_subtitle = 0; + dynarray_add(&c->playlists, &c->n_playlists, pls); return pls; } @@ -482,11 +486,6 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf if (type == AVMEDIA_TYPE_SUBTITLE && !info->uri[0]) return NULL; - /* TODO: handle subtitles (each segment has to parsed separately) */ - if (c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) - if (type == AVMEDIA_TYPE_SUBTITLE) - return NULL; - rend = av_mallocz(sizeof(struct rendition)); if (!rend) return NULL; @@ -501,9 +500,14 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf /* add the playlist if this is an external rendition */ if (info->uri[0]) { rend->playlist = new_playlist(c, info->uri, url_base); - if (rend->playlist) + if (rend->playlist) { dynarray_add(&rend->playlist->renditions, &rend->playlist->n_renditions, rend); + if (type == AVMEDIA_TYPE_SUBTITLE) { + rend->playlist->is_subtitle = 1; + rend->playlist->is_id3_timestamped = 0; + } + } } if (info->assoc_language[0]) { @@ -1349,6 +1353,136 @@ reload: goto restart; } +static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, + int flags, AVDictionary **opts) +{ + av_log(s, AV_LOG_ERROR, + "A HLS playlist item '%s' referred to an external file '%s'. " + "Opening this file was forbidden for security reasons\n", + s->filename, url); + return AVERROR(EPERM); +} + +static int read_data_simple(void *opaque, uint8_t *buf, int buf_size) +{ + struct playlist *v = opaque; + HLSContext *c = v->parent->priv_data; + struct segment *seg; + + if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { + return AVERROR_EOF; + } else { + seg = current_segment(v); + } + + if (!v->input) { + open_input(c, v, seg); + } + + return read_from_url(v, seg, buf, buf_size, READ_NORMAL); +} + +static int read_packet_subtitle(struct playlist *v, AVPacket *pkt) +{ + HLSContext *c = v->parent->priv_data; + int ret, i; + +restart: + if (!v->needed) + return AVERROR_EOF; + + if (!v->input) { + int64_t reload_interval; + + /* Check that the playlist is still needed before opening a new + * segment. */ + if (v->ctx && v->ctx->nb_streams) { + v->needed = 0; + for (i = 0; i < v->n_main_streams; i++) { + if (v->main_streams[i]->discard < AVDISCARD_ALL) { + v->needed = 1; + break; + } + } + } + if (!v->needed) { + av_log(v->parent, AV_LOG_INFO, "No longer receiving playlist %d\n", + v->index); + return AVERROR_EOF; + } + + /* If this is a live stream and the reload interval has elapsed since + * the last playlist reload, reload the playlists now. */ + reload_interval = default_reload_interval(v); + + if (!v->finished && + av_gettime_relative() - v->last_load_time >= reload_interval) { + if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) { + av_log(v->parent, AV_LOG_WARNING, "Failed to reload playlist %d\n", + v->index); + return ret; + } + /* If we need to reload the playlist again below (if + * there's still no more segments), switch to a reload + * interval of half the target duration. */ + reload_interval = v->target_duration / 2; + } + if (v->cur_seq_no < v->start_seq_no) { + av_log(NULL, AV_LOG_WARNING, + "skipping %d segments ahead, expired from subtitle playlists\n", + v->start_seq_no - v->cur_seq_no); + v->cur_seq_no = v->start_seq_no; + } + if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { + return AVERROR_EOF; + } + } + + if (v->ctx == NULL) { + AVInputFormat *in_fmt; + + if (!(v->ctx = avformat_alloc_context())) { + return AVERROR(ENOMEM); + } + + v->read_buffer = av_malloc(INITIAL_BUFFER_SIZE); + if (!v->read_buffer){ + avformat_free_context(v->ctx); + v->ctx = NULL; + return AVERROR(ENOMEM); + } + + ffio_init_context(&v->pb, v->read_buffer, INITIAL_BUFFER_SIZE, 0, v, + read_data_simple, NULL, NULL); + v->pb.seekable = 0; + v->ctx->pb = &v->pb; + v->ctx->io_open = nested_io_open; + + ret = ff_copy_whiteblacklists(v->ctx, v->parent); + if (ret < 0) { + return ret; + } + + in_fmt = av_find_input_format("webvtt"); + ret = avformat_open_input(&v->ctx, current_segment(v)->url, in_fmt, NULL); + if (ret < 0) { + return ret; + } + } + + ret = av_read_frame(v->ctx, pkt); + if (ret < 0) { + ff_format_io_close(v->parent, &v->input); + avformat_close_input(&v->ctx); + if (ret == AVERROR_EOF) { + v->cur_seq_no++; + goto restart; + } + } + + return ret; +} + static void add_renditions_to_variant(HLSContext *c, struct variant *var, enum AVMediaType type, const char *group_id) { @@ -1492,16 +1626,6 @@ static int save_avio_options(AVFormatContext *s) return ret; } -static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, - int flags, AVDictionary **opts) -{ - av_log(s, AV_LOG_ERROR, - "A HLS playlist item '%s' referred to an external file '%s'. " - "Opening this file was forbidden for security reasons\n", - s->filename, url); - return AVERROR(EPERM); -} - static void add_stream_to_programs(AVFormatContext *s, struct playlist *pls, AVStream *stream) { HLSContext *c = s->priv_data; @@ -1744,8 +1868,14 @@ static int hls_read_header(AVFormatContext *s) pls->ctx = NULL; goto fail; } - ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, - read_data, NULL, NULL); + + if (pls->is_subtitle) { + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data_simple, NULL, NULL); + } else { + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data, NULL, NULL); + } pls->pb.seekable = 0; ret = av_probe_input_buffer(&pls->pb, &in_fmt, pls->segments[0]->url, NULL, 0, 0); @@ -1843,6 +1973,8 @@ static int recheck_discard_flags(AVFormatContext *s, int first) } else if (first && !pls->cur_needed && pls->needed) { if (pls->input) ff_format_io_close(pls->parent, &pls->input); + if (pls->is_subtitle) + avformat_close_input(&pls->ctx); pls->needed = 0; changed = 1; av_log(s, AV_LOG_INFO, "No longer receiving playlist %d\n", i); @@ -1909,7 +2041,12 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) while (1) { int64_t ts_diff; AVRational tb; - ret = av_read_frame(pls->ctx, &pls->pkt); + if (pls->is_subtitle) { + ret = read_packet_subtitle(pls, &pls->pkt); + } else { + ret = av_read_frame(pls->ctx, &pls->pkt); + } + if (ret < 0) { if (!avio_feof(&pls->pb) && ret != AVERROR_EOF) return ret; @@ -2087,6 +2224,9 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, /* Flush the packet queue of the subdemuxer. */ ff_read_frame_flush(pls->ctx); + if (pls->is_subtitle) + avformat_close_input(&pls->ctx); + pls->seek_timestamp = seek_timestamp; pls->seek_flags = flags; -- 2.1.4
On Wed, 16 Nov 2016 10:31:10 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
This patch is a fix for ticket #2833.
Each subtitle segment is its own WebVTT file and has to demuxed individually.
The timing of the subtitles are not perfect but it is the best I could
What does this mean?
do and it also does not take into account the X-TIMESTAMP-MAP header in the WebVTT files which is needed to conform to the specification (https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5).
I'm not entirely familiar how HLS works. Shouldn't this be fine as long as the webvtt events have the correct "final" timestamp?
Signed-off-by: Franklin Phillips <franklinphillips@gmx.com> --- libavformat/hls.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 159 insertions(+), 19 deletions(-)
diff --git a/libavformat/hls.c b/libavformat/hls.c index 3ae3c7c..bf13be4 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -153,6 +153,8 @@ struct playlist { * playlist, if any. */ int n_init_sections; struct segment **init_sections; + + int is_subtitle; /* Indicates if the playlist is for subtitles */ };
/* @@ -312,6 +314,8 @@ static struct playlist *new_playlist(HLSContext *c, const char *url, pls->is_id3_timestamped = -1; pls->id3_mpegts_timestamp = AV_NOPTS_VALUE;
+ pls->is_subtitle = 0; + dynarray_add(&c->playlists, &c->n_playlists, pls); return pls; } @@ -482,11 +486,6 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf if (type == AVMEDIA_TYPE_SUBTITLE && !info->uri[0]) return NULL;
- /* TODO: handle subtitles (each segment has to parsed separately) */ - if (c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) - if (type == AVMEDIA_TYPE_SUBTITLE) - return NULL; - rend = av_mallocz(sizeof(struct rendition)); if (!rend) return NULL; @@ -501,9 +500,14 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf /* add the playlist if this is an external rendition */ if (info->uri[0]) { rend->playlist = new_playlist(c, info->uri, url_base); - if (rend->playlist) + if (rend->playlist) { dynarray_add(&rend->playlist->renditions, &rend->playlist->n_renditions, rend); + if (type == AVMEDIA_TYPE_SUBTITLE) { + rend->playlist->is_subtitle = 1; + rend->playlist->is_id3_timestamped = 0; + } + } }
if (info->assoc_language[0]) { @@ -1349,6 +1353,136 @@ reload: goto restart; }
+static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, + int flags, AVDictionary **opts) +{ + av_log(s, AV_LOG_ERROR, + "A HLS playlist item '%s' referred to an external file '%s'. " + "Opening this file was forbidden for security reasons\n", + s->filename, url); + return AVERROR(EPERM); +} + +static int read_data_simple(void *opaque, uint8_t *buf, int buf_size) +{ + struct playlist *v = opaque; + HLSContext *c = v->parent->priv_data; + struct segment *seg; + + if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { + return AVERROR_EOF; + } else { + seg = current_segment(v); + } + + if (!v->input) { + open_input(c, v, seg); + } + + return read_from_url(v, seg, buf, buf_size, READ_NORMAL); +} + +static int read_packet_subtitle(struct playlist *v, AVPacket *pkt) +{ + HLSContext *c = v->parent->priv_data; + int ret, i; + +restart: + if (!v->needed) + return AVERROR_EOF; + + if (!v->input) { + int64_t reload_interval; + + /* Check that the playlist is still needed before opening a new + * segment. */ + if (v->ctx && v->ctx->nb_streams) { + v->needed = 0; + for (i = 0; i < v->n_main_streams; i++) { + if (v->main_streams[i]->discard < AVDISCARD_ALL) { + v->needed = 1; + break; + } + } + } + if (!v->needed) { + av_log(v->parent, AV_LOG_INFO, "No longer receiving playlist %d\n", + v->index); + return AVERROR_EOF; + } + + /* If this is a live stream and the reload interval has elapsed since + * the last playlist reload, reload the playlists now. */ + reload_interval = default_reload_interval(v); + + if (!v->finished && + av_gettime_relative() - v->last_load_time >= reload_interval) { + if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) { + av_log(v->parent, AV_LOG_WARNING, "Failed to reload playlist %d\n", + v->index); + return ret; + } + /* If we need to reload the playlist again below (if + * there's still no more segments), switch to a reload + * interval of half the target duration. */ + reload_interval = v->target_duration / 2; + } + if (v->cur_seq_no < v->start_seq_no) { + av_log(NULL, AV_LOG_WARNING, + "skipping %d segments ahead, expired from subtitle playlists\n", + v->start_seq_no - v->cur_seq_no); + v->cur_seq_no = v->start_seq_no; + } + if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { + return AVERROR_EOF; + } + } + + if (v->ctx == NULL) { + AVInputFormat *in_fmt; + + if (!(v->ctx = avformat_alloc_context())) { + return AVERROR(ENOMEM); + } + + v->read_buffer = av_malloc(INITIAL_BUFFER_SIZE); + if (!v->read_buffer){ + avformat_free_context(v->ctx); + v->ctx = NULL; + return AVERROR(ENOMEM); + } + + ffio_init_context(&v->pb, v->read_buffer, INITIAL_BUFFER_SIZE, 0, v, + read_data_simple, NULL, NULL); + v->pb.seekable = 0; + v->ctx->pb = &v->pb; + v->ctx->io_open = nested_io_open; + + ret = ff_copy_whiteblacklists(v->ctx, v->parent); + if (ret < 0) { + return ret; + } + + in_fmt = av_find_input_format("webvtt"); + ret = avformat_open_input(&v->ctx, current_segment(v)->url, in_fmt, NULL); + if (ret < 0) { + return ret; + } + } + + ret = av_read_frame(v->ctx, pkt); + if (ret < 0) { + ff_format_io_close(v->parent, &v->input); + avformat_close_input(&v->ctx); + if (ret == AVERROR_EOF) { + v->cur_seq_no++; + goto restart; + } + } + + return ret; +} +
That seems to duplicate a lot of code from the normal read path...
static void add_renditions_to_variant(HLSContext *c, struct variant *var, enum AVMediaType type, const char *group_id) { @@ -1492,16 +1626,6 @@ static int save_avio_options(AVFormatContext *s) return ret; }
-static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, - int flags, AVDictionary **opts) -{ - av_log(s, AV_LOG_ERROR, - "A HLS playlist item '%s' referred to an external file '%s'. " - "Opening this file was forbidden for security reasons\n", - s->filename, url); - return AVERROR(EPERM); -} - static void add_stream_to_programs(AVFormatContext *s, struct playlist *pls, AVStream *stream) { HLSContext *c = s->priv_data; @@ -1744,8 +1868,14 @@ static int hls_read_header(AVFormatContext *s) pls->ctx = NULL; goto fail; } - ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, - read_data, NULL, NULL); + + if (pls->is_subtitle) { + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data_simple, NULL, NULL); + } else { + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data, NULL, NULL); + } pls->pb.seekable = 0; ret = av_probe_input_buffer(&pls->pb, &in_fmt, pls->segments[0]->url, NULL, 0, 0); @@ -1843,6 +1973,8 @@ static int recheck_discard_flags(AVFormatContext *s, int first) } else if (first && !pls->cur_needed && pls->needed) { if (pls->input) ff_format_io_close(pls->parent, &pls->input); + if (pls->is_subtitle) + avformat_close_input(&pls->ctx); pls->needed = 0; changed = 1; av_log(s, AV_LOG_INFO, "No longer receiving playlist %d\n", i); @@ -1909,7 +2041,12 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) while (1) { int64_t ts_diff; AVRational tb; - ret = av_read_frame(pls->ctx, &pls->pkt); + if (pls->is_subtitle) { + ret = read_packet_subtitle(pls, &pls->pkt); + } else { + ret = av_read_frame(pls->ctx, &pls->pkt); + } + if (ret < 0) { if (!avio_feof(&pls->pb) && ret != AVERROR_EOF) return ret; @@ -2087,6 +2224,9 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, /* Flush the packet queue of the subdemuxer. */ ff_read_frame_flush(pls->ctx);
+ if (pls->is_subtitle) + avformat_close_input(&pls->ctx); + pls->seek_timestamp = seek_timestamp; pls->seek_flags = flags;
On Wed, Nov 16, 2016 at 11:41:41AM +0100, wm4 wrote:
On Wed, 16 Nov 2016 10:31:10 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
This patch is a fix for ticket #2833.
Each subtitle segment is its own WebVTT file and has to demuxed individually.
The timing of the subtitles are not perfect but it is the best I could
What does this mean?
When I convert a mp4 file with subtitles into hls and then back into mp4, the subtitles are off by a couple 100 milliseconds usually. It seems to be caused by the first audio/video packet not having a 0 timestamp causing ffmpeg to subtract the timestamp of that first packet from all the subsequent packets.
do and it also does not take into account the X-TIMESTAMP-MAP header in the WebVTT files which is needed to conform to the specification (https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5).
I'm not entirely familiar how HLS works. Shouldn't this be fine as long as the webvtt events have the correct "final" timestamp?
Yes, I believe so, the fall back in the specification is to assume the value of that header is 0 meaning no offset and all the examples I've seen have that value set to 0 anyway. I don't think it's a crucial feature that needs to be done ASAP.
Signed-off-by: Franklin Phillips <franklinphillips@gmx.com> --- libavformat/hls.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 159 insertions(+), 19 deletions(-)
diff --git a/libavformat/hls.c b/libavformat/hls.c index 3ae3c7c..bf13be4 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -153,6 +153,8 @@ struct playlist { * playlist, if any. */ int n_init_sections; struct segment **init_sections; + + int is_subtitle; /* Indicates if the playlist is for subtitles */ };
/* @@ -312,6 +314,8 @@ static struct playlist *new_playlist(HLSContext *c, const char *url, pls->is_id3_timestamped = -1; pls->id3_mpegts_timestamp = AV_NOPTS_VALUE;
+ pls->is_subtitle = 0; + dynarray_add(&c->playlists, &c->n_playlists, pls); return pls; } @@ -482,11 +486,6 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf if (type == AVMEDIA_TYPE_SUBTITLE && !info->uri[0]) return NULL;
- /* TODO: handle subtitles (each segment has to parsed separately) */ - if (c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) - if (type == AVMEDIA_TYPE_SUBTITLE) - return NULL; - rend = av_mallocz(sizeof(struct rendition)); if (!rend) return NULL; @@ -501,9 +500,14 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf /* add the playlist if this is an external rendition */ if (info->uri[0]) { rend->playlist = new_playlist(c, info->uri, url_base); - if (rend->playlist) + if (rend->playlist) { dynarray_add(&rend->playlist->renditions, &rend->playlist->n_renditions, rend); + if (type == AVMEDIA_TYPE_SUBTITLE) { + rend->playlist->is_subtitle = 1; + rend->playlist->is_id3_timestamped = 0; + } + } }
if (info->assoc_language[0]) { @@ -1349,6 +1353,136 @@ reload: goto restart; }
+static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, + int flags, AVDictionary **opts) +{ + av_log(s, AV_LOG_ERROR, + "A HLS playlist item '%s' referred to an external file '%s'. " + "Opening this file was forbidden for security reasons\n", + s->filename, url); + return AVERROR(EPERM); +} + +static int read_data_simple(void *opaque, uint8_t *buf, int buf_size) +{ + struct playlist *v = opaque; + HLSContext *c = v->parent->priv_data; + struct segment *seg; + + if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { + return AVERROR_EOF; + } else { + seg = current_segment(v); + } + + if (!v->input) { + open_input(c, v, seg); + } + + return read_from_url(v, seg, buf, buf_size, READ_NORMAL); +} + +static int read_packet_subtitle(struct playlist *v, AVPacket *pkt) +{ + HLSContext *c = v->parent->priv_data; + int ret, i; + +restart: + if (!v->needed) + return AVERROR_EOF; + + if (!v->input) { + int64_t reload_interval; + + /* Check that the playlist is still needed before opening a new + * segment. */ + if (v->ctx && v->ctx->nb_streams) { + v->needed = 0; + for (i = 0; i < v->n_main_streams; i++) { + if (v->main_streams[i]->discard < AVDISCARD_ALL) { + v->needed = 1; + break; + } + } + } + if (!v->needed) { + av_log(v->parent, AV_LOG_INFO, "No longer receiving playlist %d\n", + v->index); + return AVERROR_EOF; + } + + /* If this is a live stream and the reload interval has elapsed since + * the last playlist reload, reload the playlists now. */ + reload_interval = default_reload_interval(v); + + if (!v->finished && + av_gettime_relative() - v->last_load_time >= reload_interval) { + if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) { + av_log(v->parent, AV_LOG_WARNING, "Failed to reload playlist %d\n", + v->index); + return ret; + } + /* If we need to reload the playlist again below (if + * there's still no more segments), switch to a reload + * interval of half the target duration. */ + reload_interval = v->target_duration / 2; + } + if (v->cur_seq_no < v->start_seq_no) { + av_log(NULL, AV_LOG_WARNING, + "skipping %d segments ahead, expired from subtitle playlists\n", + v->start_seq_no - v->cur_seq_no); + v->cur_seq_no = v->start_seq_no; + } + if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { + return AVERROR_EOF; + } + } + + if (v->ctx == NULL) { + AVInputFormat *in_fmt; + + if (!(v->ctx = avformat_alloc_context())) { + return AVERROR(ENOMEM); + } + + v->read_buffer = av_malloc(INITIAL_BUFFER_SIZE); + if (!v->read_buffer){ + avformat_free_context(v->ctx); + v->ctx = NULL; + return AVERROR(ENOMEM); + } + + ffio_init_context(&v->pb, v->read_buffer, INITIAL_BUFFER_SIZE, 0, v, + read_data_simple, NULL, NULL); + v->pb.seekable = 0; + v->ctx->pb = &v->pb; + v->ctx->io_open = nested_io_open; + + ret = ff_copy_whiteblacklists(v->ctx, v->parent); + if (ret < 0) { + return ret; + } + + in_fmt = av_find_input_format("webvtt"); + ret = avformat_open_input(&v->ctx, current_segment(v)->url, in_fmt, NULL); + if (ret < 0) { + return ret; + } + } + + ret = av_read_frame(v->ctx, pkt); + if (ret < 0) { + ff_format_io_close(v->parent, &v->input); + avformat_close_input(&v->ctx); + if (ret == AVERROR_EOF) { + v->cur_seq_no++; + goto restart; + } + } + + return ret; +} +
That seems to duplicate a lot of code from the normal read path...
I don't think there is a lot of duplication, and the duplication that there is, I don't think can be factored out cleanly due to the different ways the two methods are called and the difference in behaviour of the two methods.
static void add_renditions_to_variant(HLSContext *c, struct variant *var, enum AVMediaType type, const char *group_id) { @@ -1492,16 +1626,6 @@ static int save_avio_options(AVFormatContext *s) return ret; }
-static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, - int flags, AVDictionary **opts) -{ - av_log(s, AV_LOG_ERROR, - "A HLS playlist item '%s' referred to an external file '%s'. " - "Opening this file was forbidden for security reasons\n", - s->filename, url); - return AVERROR(EPERM); -} - static void add_stream_to_programs(AVFormatContext *s, struct playlist *pls, AVStream *stream) { HLSContext *c = s->priv_data; @@ -1744,8 +1868,14 @@ static int hls_read_header(AVFormatContext *s) pls->ctx = NULL; goto fail; } - ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, - read_data, NULL, NULL); + + if (pls->is_subtitle) { + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data_simple, NULL, NULL); + } else { + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data, NULL, NULL); + } pls->pb.seekable = 0; ret = av_probe_input_buffer(&pls->pb, &in_fmt, pls->segments[0]->url, NULL, 0, 0); @@ -1843,6 +1973,8 @@ static int recheck_discard_flags(AVFormatContext *s, int first) } else if (first && !pls->cur_needed && pls->needed) { if (pls->input) ff_format_io_close(pls->parent, &pls->input); + if (pls->is_subtitle) + avformat_close_input(&pls->ctx); pls->needed = 0; changed = 1; av_log(s, AV_LOG_INFO, "No longer receiving playlist %d\n", i); @@ -1909,7 +2041,12 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) while (1) { int64_t ts_diff; AVRational tb; - ret = av_read_frame(pls->ctx, &pls->pkt); + if (pls->is_subtitle) { + ret = read_packet_subtitle(pls, &pls->pkt); + } else { + ret = av_read_frame(pls->ctx, &pls->pkt); + } + if (ret < 0) { if (!avio_feof(&pls->pb) && ret != AVERROR_EOF) return ret; @@ -2087,6 +2224,9 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, /* Flush the packet queue of the subdemuxer. */ ff_read_frame_flush(pls->ctx);
+ if (pls->is_subtitle) + avformat_close_input(&pls->ctx); + pls->seek_timestamp = seek_timestamp; pls->seek_flags = flags;
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On Wed, 16 Nov 2016 11:21:59 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
On Wed, Nov 16, 2016 at 11:41:41AM +0100, wm4 wrote:
On Wed, 16 Nov 2016 10:31:10 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
This patch is a fix for ticket #2833.
Each subtitle segment is its own WebVTT file and has to demuxed individually.
The timing of the subtitles are not perfect but it is the best I could
What does this mean?
When I convert a mp4 file with subtitles into hls and then back into mp4, the subtitles are off by a couple 100 milliseconds usually. It seems to be caused by the first audio/video packet not having a 0 timestamp causing ffmpeg to subtract the timestamp of that first packet from all the subsequent packets.
FFmpeg determines a global start_time, which is probably used in transcoding to offset all streams or so. But that shouldn't lead to timestamp mismatches because it's the same offset. Can you check the timestamps with ffprobe? Also make sure you return subtitle packets ideally before audio/video packets with the same or a higher timestamp. Otherwise it could happen that a subtitle packet is too late to be rendered on video. (Though I don't know what happens when remuxing subtitles in this scenario.)
do and it also does not take into account the X-TIMESTAMP-MAP header in the WebVTT files which is needed to conform to the specification (https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5).
I'm not entirely familiar how HLS works. Shouldn't this be fine as long as the webvtt events have the correct "final" timestamp?
Yes, I believe so, the fall back in the specification is to assume the value of that header is 0 meaning no offset and all the examples I've seen have that value set to 0 anyway. I don't think it's a crucial feature that needs to be done ASAP.
[...] +
That seems to duplicate a lot of code from the normal read path...
I don't think there is a lot of duplication, and the duplication that there is, I don't think can be factored out cleanly due to the different ways the two methods are called and the difference in behaviour of the two methods.
Well, if you say so. Still hurts a bit.
On Wed, Nov 16, 2016 at 12:33:32PM +0100, wm4 wrote:
On Wed, 16 Nov 2016 11:21:59 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
On Wed, Nov 16, 2016 at 11:41:41AM +0100, wm4 wrote:
On Wed, 16 Nov 2016 10:31:10 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
This patch is a fix for ticket #2833.
Each subtitle segment is its own WebVTT file and has to demuxed individually.
The timing of the subtitles are not perfect but it is the best I could
What does this mean?
When I convert a mp4 file with subtitles into hls and then back into mp4, the subtitles are off by a couple 100 milliseconds usually. It seems to be caused by the first audio/video packet not having a 0 timestamp causing ffmpeg to subtract the timestamp of that first packet from all the subsequent packets.
FFmpeg determines a global start_time, which is probably used in transcoding to offset all streams or so. But that shouldn't lead to timestamp mismatches because it's the same offset.
Can you check the timestamps with ffprobe? Also make sure you return subtitle packets ideally before audio/video packets with the same or a higher timestamp. Otherwise it could happen that a subtitle packet is too late to be rendered on video. (Though I don't know what happens when remuxing subtitles in this scenario.)
I think you are implying the subtitles are delayed, but that is not the case, in most cases I've found them to be early. I just double checked what was happening and it is as follows: demuxer -> ist_index:0 type:subtitle next_dts:NOPTS next_dts_time:NOPTS next_pts:NOPTS next_pts_time:NOPTS pkt_pts:127 pkt_pts_time:0.127 pkt_dts:127 pkt_dts_time:0.127 off:-1401000 off_time:-1.401 demuxer+ffmpeg -> ist_index:0 type:subtitle pkt_pts:-1274 pkt_pts_time:-1.274 pkt_dts:-1274 pkt_dts_time:-1.274 off:-1401000 off_time:-1.401 muxer <- type:subtitle pkt_pts:-1274 pkt_pts_time:-1.274 pkt_dts:-1274 pkt_dts_time:-1.274 size:45 demuxer -> ist_index:2 type:audio next_dts:NOPTS next_dts_time:NOPTS next_pts:NOPTS next_pts_time:NOPTS pkt_pts:126090 pkt_pts_time:1.401 pkt_dts:126090 pkt_dts_time:1.401 off:-1401000 off_time:-1.401 demuxer+ffmpeg -> ist_index:2 type:audio pkt_pts:0 pkt_pts_time:0 pkt_dts:0 pkt_dts_time:0 off:-1401000 off_time:-1.401 muxer <- type:audio pkt_pts:0 pkt_pts_time:0 pkt_dts:0 pkt_dts_time:0 size:407 This is showing the first two packets of a hls playlist, first one is the subtitle packet which has a timestamp of 0.127 (this is the timestamp that appears in the .vtt segment file so the demuxer appears to be working correctly), it is being offset by -1.401 which is the timestamp of the first audio packet. The problem is that the subtitle should appear 0.127 seconds from the start of the video and the offset is not needed. Now that I think about it, the issue may be with the hls muxer which was used to create these hls segments because the timestamps of the subtitles do not have the same point of reference as the audio/video packets.
do and it also does not take into account the X-TIMESTAMP-MAP header in the WebVTT files which is needed to conform to the specification (https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5).
I'm not entirely familiar how HLS works. Shouldn't this be fine as long as the webvtt events have the correct "final" timestamp?
Yes, I believe so, the fall back in the specification is to assume the value of that header is 0 meaning no offset and all the examples I've seen have that value set to 0 anyway. I don't think it's a crucial feature that needs to be done ASAP.
[...] +
That seems to duplicate a lot of code from the normal read path...
I don't think there is a lot of duplication, and the duplication that there is, I don't think can be factored out cleanly due to the different ways the two methods are called and the difference in behaviour of the two methods.
Well, if you say so. Still hurts a bit. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Hi, If there are no more comments can we look at merging this please? Thanks
On Tue, 29 Nov 2016 17:44:15 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
Hi,
If there are no more comments can we look at merging this please?
I think your previous post implied that subtitles are actually timed correctly, right? If so, I don't mind it being applied as-is.
On Tue, Nov 29, 2016 at 07:10:52PM +0100, wm4 wrote:
On Tue, 29 Nov 2016 17:44:15 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
Hi,
If there are no more comments can we look at merging this please?
I think your previous post implied that subtitles are actually timed correctly, right? The timing is correct as long as the X-TIMESTAMP-MAP header in the subtitle files is 0 because I haven't implemented that. If I encounter situations where that header contains a value other than 0 outside of the sample files from Apple I will consider implementing it.
If so, I don't mind it being applied as-is. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
WebVTT subtitle files in HLS streams contain a header to synchronize the subtitles with the MPEG TS timestamps of the HLS stream. Add an AVOption to prefer MPEG TS style timestamps generated according to the mapping header, if available. Signed-off-by: Franklin Phillips <franklinphillips@gmx.com> --- libavformat/webvttdec.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/libavformat/webvttdec.c b/libavformat/webvttdec.c index 0aeb8a6..329b25e 100644 --- a/libavformat/webvttdec.c +++ b/libavformat/webvttdec.c @@ -35,6 +35,7 @@ typedef struct { const AVClass *class; FFDemuxSubtitlesQueue q; int kind; + int prefer_hls_mpegts_pts; } WebVTTContext; static int webvtt_probe(AVProbeData *p) @@ -57,12 +58,19 @@ static int64_t read_ts(const char *s) return AV_NOPTS_VALUE; } +static int64_t convert_to_hls_mpegts_ts(int64_t timestamp, int64_t offset) +{ + return (timestamp * 90 + offset) & ((1LL << 33) - 1); +} + static int webvtt_read_header(AVFormatContext *s) { WebVTTContext *webvtt = s->priv_data; AVBPrint header, cue; int res = 0; AVStream *st = avformat_new_stream(s, NULL); + int has_hls_timestamp_map = 0; + int64_t hls_ts_offset; if (!st) return AVERROR(ENOMEM); @@ -93,8 +101,36 @@ static int webvtt_read_header(AVFormatContext *s) /* ignore header chunk */ if (!strncmp(p, "\xEF\xBB\xBFWEBVTT", 9) || !strncmp(p, "WEBVTT", 6) || - !strncmp(p, "NOTE", 4)) + !strncmp(p, "NOTE", 4)) { + + if (webvtt->prefer_hls_mpegts_pts) { + /* + * WebVTT files in HLS streams contain a timestamp offset for + * syncing with the main stream: + * + * X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000 + * (LOCAL and MPEGTS can be reversed even though HLS spec + * does not say so) + */ + + char *hls_timestamp_map = strstr(p, "\nX-TIMESTAMP-MAP="); + if (hls_timestamp_map) { + char *native_str = strstr(hls_timestamp_map, "LOCAL:"); + char *mpegts_str = strstr(hls_timestamp_map, "MPEGTS:"); + if (native_str && mpegts_str) { + int64_t native_ts = read_ts(native_str + 6); + int64_t mpegts_ts = strtoll(mpegts_str + 7, NULL, 10); + + if (native_ts != AV_NOPTS_VALUE) { + hls_ts_offset = mpegts_ts - native_ts * 90; + has_hls_timestamp_map = 1; + avpriv_set_pts_info(st, 33, 1, 90000); + } + } + } + } continue; + } /* optional cue identifier (can be a number like in SRT or some kind of * chaptering id) */ @@ -125,6 +161,12 @@ static int webvtt_read_header(AVFormatContext *s) if ((ts_end = read_ts(p)) == AV_NOPTS_VALUE) break; + if (has_hls_timestamp_map) { + /* convert and truncate to MPEG TS timestamps */ + ts_start = convert_to_hls_mpegts_ts(ts_start, hls_ts_offset); + ts_end = convert_to_hls_mpegts_ts(ts_end, hls_ts_offset); + } + /* optional cue settings */ p += strcspn(p, "\n\t "); while (*p == '\t' || *p == ' ') @@ -200,6 +242,7 @@ static const AVOption options[] = { { "captions", "WebVTT captions kind", 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, INT_MIN, INT_MAX, 0, "webvtt_kind" }, { "descriptions", "WebVTT descriptions kind", 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, INT_MIN, INT_MAX, 0, "webvtt_kind" }, { "metadata", "WebVTT metadata kind", 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, INT_MIN, INT_MAX, 0, "webvtt_kind" }, + { "prefer_hls_mpegts_pts", "Use WebVTT embedded HLS MPEGTS timestamps if available.", OFFSET(prefer_hls_mpegts_pts), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM }, { NULL } }; -- 2.1.4
Each subtile segment is a WebVTT file and needs to be demuxed separately. These segments also contain a header to synchronize their timing with the MPEG TS stream so those timestamps are requested from the WebVTT demuxer through an AVOption. Signed-off-by: Franklin Phillips <franklinphillips@gmx.com> --- libavformat/hls.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 177 insertions(+), 20 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 3ae3c7c..7f1a55e 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -153,6 +153,8 @@ struct playlist { * playlist, if any. */ int n_init_sections; struct segment **init_sections; + + int is_subtitle; /* Indicates if the playlist is for subtitles */ }; /* @@ -203,6 +205,7 @@ typedef struct HLSContext { char *headers; ///< holds HTTP headers set as an AVOption to the HTTP protocol context char *http_proxy; ///< holds the address of the HTTP proxy server AVDictionary *avio_opts; + AVDictionary *demuxer_opts; int strict_std_compliance; } HLSContext; @@ -312,6 +315,8 @@ static struct playlist *new_playlist(HLSContext *c, const char *url, pls->is_id3_timestamped = -1; pls->id3_mpegts_timestamp = AV_NOPTS_VALUE; + pls->is_subtitle = 0; + dynarray_add(&c->playlists, &c->n_playlists, pls); return pls; } @@ -482,11 +487,6 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf if (type == AVMEDIA_TYPE_SUBTITLE && !info->uri[0]) return NULL; - /* TODO: handle subtitles (each segment has to parsed separately) */ - if (c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) - if (type == AVMEDIA_TYPE_SUBTITLE) - return NULL; - rend = av_mallocz(sizeof(struct rendition)); if (!rend) return NULL; @@ -501,9 +501,14 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf /* add the playlist if this is an external rendition */ if (info->uri[0]) { rend->playlist = new_playlist(c, info->uri, url_base); - if (rend->playlist) + if (rend->playlist) { dynarray_add(&rend->playlist->renditions, &rend->playlist->n_renditions, rend); + if (type == AVMEDIA_TYPE_SUBTITLE) { + rend->playlist->is_subtitle = 1; + rend->playlist->is_id3_timestamped = 0; + } + } } if (info->assoc_language[0]) { @@ -1349,6 +1354,146 @@ reload: goto restart; } +static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, + int flags, AVDictionary **opts) +{ + av_log(s, AV_LOG_ERROR, + "A HLS playlist item '%s' referred to an external file '%s'. " + "Opening this file was forbidden for security reasons\n", + s->filename, url); + return AVERROR(EPERM); +} + +static int read_data_simple(void *opaque, uint8_t *buf, int buf_size) +{ + struct playlist *v = opaque; + HLSContext *c = v->parent->priv_data; + struct segment *seg; + + if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { + return AVERROR_EOF; + } else { + seg = current_segment(v); + } + + if (!v->input) { + int ret = open_input(c, v, seg); + if (ret < 0) { + if (ff_check_interrupt(c->interrupt_callback)) + return AVERROR_EXIT; + av_log(v->parent, AV_LOG_WARNING, "Failed to open segment of playlist %d\n", + v->index); + return ret; + } + } + + return read_from_url(v, seg, buf, buf_size, READ_NORMAL); +} + +static int read_packet_subtitle(struct playlist *v, AVPacket *pkt) +{ + HLSContext *c = v->parent->priv_data; + int ret, i; + +restart: + if (!v->needed) + return AVERROR_EOF; + + if (!v->input) { + int64_t reload_interval; + + /* Check that the playlist is still needed before opening a new + * segment. */ + if (v->ctx && v->ctx->nb_streams) { + v->needed = 0; + for (i = 0; i < v->n_main_streams; i++) { + if (v->main_streams[i]->discard < AVDISCARD_ALL) { + v->needed = 1; + break; + } + } + } + if (!v->needed) { + av_log(v->parent, AV_LOG_INFO, "No longer receiving playlist %d\n", + v->index); + return AVERROR_EOF; + } + + /* If this is a live stream and the reload interval has elapsed since + * the last playlist reload, reload the playlists now. */ + reload_interval = default_reload_interval(v); + + if (!v->finished && + av_gettime_relative() - v->last_load_time >= reload_interval) { + if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) { + av_log(v->parent, AV_LOG_WARNING, "Failed to reload playlist %d\n", + v->index); + return ret; + } + /* If we need to reload the playlist again below (if + * there's still no more segments), switch to a reload + * interval of half the target duration. */ + reload_interval = v->target_duration / 2; + } + if (v->cur_seq_no < v->start_seq_no) { + av_log(NULL, AV_LOG_WARNING, + "skipping %d segments ahead, expired from subtitle playlists\n", + v->start_seq_no - v->cur_seq_no); + v->cur_seq_no = v->start_seq_no; + } + if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { + return AVERROR_EOF; + } + } + + if (v->ctx == NULL) { + AVInputFormat *in_fmt; + AVDictionary *opts = NULL; + + if (!(v->ctx = avformat_alloc_context())) { + return AVERROR(ENOMEM); + } + + v->read_buffer = av_malloc(INITIAL_BUFFER_SIZE); + if (!v->read_buffer){ + avformat_free_context(v->ctx); + v->ctx = NULL; + return AVERROR(ENOMEM); + } + + ffio_init_context(&v->pb, v->read_buffer, INITIAL_BUFFER_SIZE, 0, v, + read_data_simple, NULL, NULL); + v->pb.seekable = 0; + v->ctx->pb = &v->pb; + v->ctx->io_open = nested_io_open; + + ret = ff_copy_whiteblacklists(v->ctx, v->parent); + if (ret < 0) { + return ret; + } + + in_fmt = av_find_input_format("webvtt"); + av_dict_copy(&opts, c->demuxer_opts, 0); + ret = avformat_open_input(&v->ctx, current_segment(v)->url, in_fmt, &opts); + av_dict_free(&opts); + if (ret < 0) { + return ret; + } + } + + ret = av_read_frame(v->ctx, pkt); + if (ret < 0) { + ff_format_io_close(v->parent, &v->input); + avformat_close_input(&v->ctx); + if (ret == AVERROR_EOF) { + v->cur_seq_no++; + goto restart; + } + } + + return ret; +} + static void add_renditions_to_variant(HLSContext *c, struct variant *var, enum AVMediaType type, const char *group_id) { @@ -1492,16 +1637,6 @@ static int save_avio_options(AVFormatContext *s) return ret; } -static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, - int flags, AVDictionary **opts) -{ - av_log(s, AV_LOG_ERROR, - "A HLS playlist item '%s' referred to an external file '%s'. " - "Opening this file was forbidden for security reasons\n", - s->filename, url); - return AVERROR(EPERM); -} - static void add_stream_to_programs(AVFormatContext *s, struct playlist *pls, AVStream *stream) { HLSContext *c = s->priv_data; @@ -1602,6 +1737,7 @@ static int hls_close(AVFormatContext *s) free_rendition_list(c); av_dict_free(&c->avio_opts); + av_dict_free(&c->demuxer_opts); return 0; } @@ -1708,10 +1844,13 @@ static int hls_read_header(AVFormatContext *s) highest_cur_seq_no = FFMAX(highest_cur_seq_no, pls->cur_seq_no); } + av_dict_set(&c->demuxer_opts, "prefer_hls_mpegts_pts", "1", 0); + /* Open the demuxer for each playlist */ for (i = 0; i < c->n_playlists; i++) { struct playlist *pls = c->playlists[i]; AVInputFormat *in_fmt = NULL; + AVDictionary *opts = NULL; if (!(pls->ctx = avformat_alloc_context())) { ret = AVERROR(ENOMEM); @@ -1744,8 +1883,14 @@ static int hls_read_header(AVFormatContext *s) pls->ctx = NULL; goto fail; } - ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, - read_data, NULL, NULL); + + if (pls->is_subtitle) { + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data_simple, NULL, NULL); + } else { + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data, NULL, NULL); + } pls->pb.seekable = 0; ret = av_probe_input_buffer(&pls->pb, &in_fmt, pls->segments[0]->url, NULL, 0, 0); @@ -1765,7 +1910,9 @@ static int hls_read_header(AVFormatContext *s) if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0) goto fail; - ret = avformat_open_input(&pls->ctx, pls->segments[0]->url, in_fmt, NULL); + av_dict_copy(&opts, c->demuxer_opts, 0); + ret = avformat_open_input(&pls->ctx, pls->segments[0]->url, in_fmt, &opts); + av_dict_free(&opts); if (ret < 0) goto fail; @@ -1843,6 +1990,8 @@ static int recheck_discard_flags(AVFormatContext *s, int first) } else if (first && !pls->cur_needed && pls->needed) { if (pls->input) ff_format_io_close(pls->parent, &pls->input); + if (pls->is_subtitle) + avformat_close_input(&pls->ctx); pls->needed = 0; changed = 1; av_log(s, AV_LOG_INFO, "No longer receiving playlist %d\n", i); @@ -1909,7 +2058,12 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) while (1) { int64_t ts_diff; AVRational tb; - ret = av_read_frame(pls->ctx, &pls->pkt); + if (pls->is_subtitle) { + ret = read_packet_subtitle(pls, &pls->pkt); + } else { + ret = av_read_frame(pls->ctx, &pls->pkt); + } + if (ret < 0) { if (!avio_feof(&pls->pb) && ret != AVERROR_EOF) return ret; @@ -2087,6 +2241,9 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, /* Flush the packet queue of the subdemuxer. */ ff_read_frame_flush(pls->ctx); + if (pls->is_subtitle) + avformat_close_input(&pls->ctx); + pls->seek_timestamp = seek_timestamp; pls->seek_flags = flags; -- 2.1.4
Assuming the reason why my patch wasn't being merged was because it didn't use the X-TIMESTAMP-MAP, I have included the changes for that. Those changes were basically a merge of work done by anssi.hannula@iki.fi which is why I've cc'd them.
Hi, 07.12.2016, 00:04, Franklin Phillips kirjoitti:
Assuming the reason why my patch wasn't being merged was because it didn't use the X-TIMESTAMP-MAP, I have included the changes for that.
Those changes were basically a merge of work done by anssi.hannula@iki.fi which is why I've cc'd them.
I'm sorry about the lack of response. I should be able to take a closer look by Friday this week, but with a quick look your read_packet_subtitle() seems to contain quite a lot of duplicated code with other parts of hls.c (unless I'm missing something), so some refactoring should be done. -- Anssi Hannula
Hi, I tested this code by converting HLS streams into mp4 files and it seemed to work fine. However I recently compiled mpv with these changes and when I play back the Apple example stream given in ticket #2833, it seems to skip a lot of subtitles. It works fine for the real world streams I'm using it for but it's probably worth holding off with this change until that's worked out. Also I tried to make minimal changes to the existing code path because there don't seem to be any tests for HLS making it hard to know when something is broken which I guess is why there is the duplication. However I think you are right and it should be refactored, I had a further look at how it could be done and will continue working on it. If you have any advice for testing the current HLS functionality so I can be confident that there are no regressions, I would appreciate that. Thanks
On Thu, 15 Dec 2016 22:01:46 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
Hi,
I tested this code by converting HLS streams into mp4 files and it seemed to work fine. However I recently compiled mpv with these changes and when I play back the Apple example stream given in ticket #2833, it seems to skip a lot of subtitles. It works fine for the real world streams I'm using it for but it's probably worth holding off with this change until that's worked out.
Could be a mpv-specific issue, maybe report it there.
Also I tried to make minimal changes to the existing code path because there don't seem to be any tests for HLS making it hard to know when something is broken which I guess is why there is the duplication. However I think you are right and it should be refactored, I had a further look at how it could be done and will continue working on it.
I wonder why not. Couldn't we put a small HLS stream on disk for FATE and let libavformat demux it? This still wouldn't test HTTP interaction of course.
If you have any advice for testing the current HLS functionality so I can be confident that there are no regressions, I would appreciate that.
WebVTT subtitle files in HLS streams contain a header to synchronize the subtitles with the MPEG TS timestamps of the HLS stream. Add an AVOption to prefer MPEG TS style timestamps generated according to the mapping header, if available. Signed-off-by: Franklin Phillips <franklinphillips@gmx.com> --- libavformat/webvttdec.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/libavformat/webvttdec.c b/libavformat/webvttdec.c index 0aeb8a6..329b25e 100644 --- a/libavformat/webvttdec.c +++ b/libavformat/webvttdec.c @@ -35,6 +35,7 @@ typedef struct { const AVClass *class; FFDemuxSubtitlesQueue q; int kind; + int prefer_hls_mpegts_pts; } WebVTTContext; static int webvtt_probe(AVProbeData *p) @@ -57,12 +58,19 @@ static int64_t read_ts(const char *s) return AV_NOPTS_VALUE; } +static int64_t convert_to_hls_mpegts_ts(int64_t timestamp, int64_t offset) +{ + return (timestamp * 90 + offset) & ((1LL << 33) - 1); +} + static int webvtt_read_header(AVFormatContext *s) { WebVTTContext *webvtt = s->priv_data; AVBPrint header, cue; int res = 0; AVStream *st = avformat_new_stream(s, NULL); + int has_hls_timestamp_map = 0; + int64_t hls_ts_offset; if (!st) return AVERROR(ENOMEM); @@ -93,8 +101,36 @@ static int webvtt_read_header(AVFormatContext *s) /* ignore header chunk */ if (!strncmp(p, "\xEF\xBB\xBFWEBVTT", 9) || !strncmp(p, "WEBVTT", 6) || - !strncmp(p, "NOTE", 4)) + !strncmp(p, "NOTE", 4)) { + + if (webvtt->prefer_hls_mpegts_pts) { + /* + * WebVTT files in HLS streams contain a timestamp offset for + * syncing with the main stream: + * + * X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000 + * (LOCAL and MPEGTS can be reversed even though HLS spec + * does not say so) + */ + + char *hls_timestamp_map = strstr(p, "\nX-TIMESTAMP-MAP="); + if (hls_timestamp_map) { + char *native_str = strstr(hls_timestamp_map, "LOCAL:"); + char *mpegts_str = strstr(hls_timestamp_map, "MPEGTS:"); + if (native_str && mpegts_str) { + int64_t native_ts = read_ts(native_str + 6); + int64_t mpegts_ts = strtoll(mpegts_str + 7, NULL, 10); + + if (native_ts != AV_NOPTS_VALUE) { + hls_ts_offset = mpegts_ts - native_ts * 90; + has_hls_timestamp_map = 1; + avpriv_set_pts_info(st, 33, 1, 90000); + } + } + } + } continue; + } /* optional cue identifier (can be a number like in SRT or some kind of * chaptering id) */ @@ -125,6 +161,12 @@ static int webvtt_read_header(AVFormatContext *s) if ((ts_end = read_ts(p)) == AV_NOPTS_VALUE) break; + if (has_hls_timestamp_map) { + /* convert and truncate to MPEG TS timestamps */ + ts_start = convert_to_hls_mpegts_ts(ts_start, hls_ts_offset); + ts_end = convert_to_hls_mpegts_ts(ts_end, hls_ts_offset); + } + /* optional cue settings */ p += strcspn(p, "\n\t "); while (*p == '\t' || *p == ' ') @@ -200,6 +242,7 @@ static const AVOption options[] = { { "captions", "WebVTT captions kind", 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, INT_MIN, INT_MAX, 0, "webvtt_kind" }, { "descriptions", "WebVTT descriptions kind", 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, INT_MIN, INT_MAX, 0, "webvtt_kind" }, { "metadata", "WebVTT metadata kind", 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, INT_MIN, INT_MAX, 0, "webvtt_kind" }, + { "prefer_hls_mpegts_pts", "Use WebVTT embedded HLS MPEGTS timestamps if available.", OFFSET(prefer_hls_mpegts_pts), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM }, { NULL } }; -- 2.1.4
Each subtile segment is a WebVTT file and needs to be demuxed separately. These segments also contain a header to synchronize their timing with the MPEG TS stream so those timestamps are requested from the WebVTT demuxer through an AVOption. Signed-off-by: Franklin Phillips <franklinphillips@gmx.com> --- libavformat/hls.c | 196 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 138 insertions(+), 58 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 3ae3c7c..278c3b2 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -153,6 +153,8 @@ struct playlist { * playlist, if any. */ int n_init_sections; struct segment **init_sections; + + int is_subtitle; /* Indicates if it's a subtitle playlist */ }; /* @@ -203,6 +205,7 @@ typedef struct HLSContext { char *headers; ///< holds HTTP headers set as an AVOption to the HTTP protocol context char *http_proxy; ///< holds the address of the HTTP proxy server AVDictionary *avio_opts; + AVDictionary *demuxer_opts; int strict_std_compliance; } HLSContext; @@ -309,6 +312,8 @@ static struct playlist *new_playlist(HLSContext *c, const char *url, ff_make_absolute_url(pls->url, sizeof(pls->url), base, url); pls->seek_timestamp = AV_NOPTS_VALUE; + pls->is_subtitle = 0; + pls->is_id3_timestamped = -1; pls->id3_mpegts_timestamp = AV_NOPTS_VALUE; @@ -482,11 +487,6 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf if (type == AVMEDIA_TYPE_SUBTITLE && !info->uri[0]) return NULL; - /* TODO: handle subtitles (each segment has to parsed separately) */ - if (c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) - if (type == AVMEDIA_TYPE_SUBTITLE) - return NULL; - rend = av_mallocz(sizeof(struct rendition)); if (!rend) return NULL; @@ -501,9 +501,14 @@ static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf /* add the playlist if this is an external rendition */ if (info->uri[0]) { rend->playlist = new_playlist(c, info->uri, url_base); - if (rend->playlist) + if (rend->playlist) { dynarray_add(&rend->playlist->renditions, &rend->playlist->n_renditions, rend); + if (type == AVMEDIA_TYPE_SUBTITLE) { + rend->playlist->is_subtitle = 1; + rend->playlist->is_id3_timestamped = 0; + } + } } if (info->assoc_language[0]) { @@ -1241,8 +1246,103 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size) { struct playlist *v = opaque; HLSContext *c = v->parent->priv_data; - int ret, i; - int just_opened = 0; + int ret, just_opened = 0; + struct segment *seg; + + if (v->cur_seq_no - v->start_seq_no >= v->n_segments) { + return AVERROR_EOF; + } else { + seg = current_segment(v); + } + + if (!v->input) { + /* load/update Media Initialization Section, if any */ + ret = update_init_section(v, seg); + if (ret < 0) + return ret; + + ret = open_input(c, v, seg); + if (ret < 0) { + if (ff_check_interrupt(c->interrupt_callback)) + return AVERROR_EXIT; + av_log(v->parent, AV_LOG_WARNING, "Failed to open segment of playlist %d\n", + v->index); + return ret; + } + just_opened = 1; + } + + if (v->init_sec_buf_read_offset < v->init_sec_data_len) { + /* Push init section out first before first actual segment */ + int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size); + memcpy(buf, v->init_sec_buf, copy_size); + v->init_sec_buf_read_offset += copy_size; + return copy_size; + } + + ret = read_from_url(v, seg, buf, buf_size, READ_NORMAL); + if (ret > 0) { + if (just_opened && v->is_id3_timestamped != 0) { + /* Intercept ID3 tags here, elementary audio streams are required + * to convey timestamps using them in the beginning of each segment. */ + intercept_id3(v, buf, buf_size, &ret); + } + } + + return ret; +} + +static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, + int flags, AVDictionary **opts) +{ + av_log(s, AV_LOG_ERROR, + "A HLS playlist item '%s' referred to an external file '%s'. " + "Opening this file was forbidden for security reasons\n", + s->filename, url); + return AVERROR(EPERM); +} + +static int init_subtitle_context(struct playlist *pls) +{ + HLSContext *c = pls->parent->priv_data; + AVInputFormat *in_fmt; + AVDictionary *opts = NULL; + int ret = 0; + + if (!(pls->ctx = avformat_alloc_context())) + return AVERROR(ENOMEM); + + pls->read_buffer = av_malloc(INITIAL_BUFFER_SIZE); + if (!pls->read_buffer) { + avformat_free_context(pls->ctx); + pls->ctx = NULL; + return AVERROR(ENOMEM); + } + + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data, NULL, NULL); + pls->pb.seekable = 0; + pls->ctx->pb = &pls->pb; + pls->ctx->io_open = nested_io_open; + + ret = ff_copy_whiteblacklists(pls->ctx, pls->parent); + if (ret < 0) + return ret; + + in_fmt = av_find_input_format("webvtt"); + av_dict_copy(&opts, c->demuxer_opts, 0); + ret = avformat_open_input(&pls->ctx, current_segment(pls)->url, in_fmt, &opts); + av_dict_free(&opts); + if (ret < 0) + return ret; + + return ret; +} + +static int read_packet(struct playlist *v, AVPacket *pkt) +{ + HLSContext *c = v->parent->priv_data; + int ret; restart: if (!v->needed) @@ -1250,11 +1350,11 @@ restart: if (!v->input) { int64_t reload_interval; - struct segment *seg; /* Check that the playlist is still needed before opening a new * segment. */ - if (v->ctx && v->ctx->nb_streams) { + if ((v->ctx && v->ctx->nb_streams) || v->is_subtitle) { + int i; v->needed = 0; for (i = 0; i < v->n_main_streams; i++) { if (v->main_streams[i]->discard < AVDISCARD_ALL) { @@ -1270,7 +1370,7 @@ restart: } /* If this is a live stream and the reload interval has elapsed since - * the last playlist reload, reload the playlists now. */ + * the last playlist reload, reload the playlists now. */ reload_interval = default_reload_interval(v); reload: @@ -1293,7 +1393,7 @@ reload: v->cur_seq_no = v->start_seq_no; } if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { - if (v->finished) + if (v->finished || v->is_subtitle) return AVERROR_EOF; while (av_gettime_relative() - v->last_load_time < reload_interval) { if (ff_check_interrupt(c->interrupt_callback)) @@ -1304,48 +1404,26 @@ reload: goto reload; } - seg = current_segment(v); - - /* load/update Media Initialization Section, if any */ - ret = update_init_section(v, seg); - if (ret) - return ret; - - ret = open_input(c, v, seg); - if (ret < 0) { - if (ff_check_interrupt(c->interrupt_callback)) - return AVERROR_EXIT; - av_log(v->parent, AV_LOG_WARNING, "Failed to open segment of playlist %d\n", - v->index); - v->cur_seq_no += 1; - goto reload; + if (!v->ctx && v->is_subtitle) { + ret = init_subtitle_context(v); + if (ret < 0) + return ret; } - just_opened = 1; } - if (v->init_sec_buf_read_offset < v->init_sec_data_len) { - /* Push init section out first before first actual segment */ - int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size); - memcpy(buf, v->init_sec_buf, copy_size); - v->init_sec_buf_read_offset += copy_size; - return copy_size; - } - - ret = read_from_url(v, current_segment(v), buf, buf_size, READ_NORMAL); - if (ret > 0) { - if (just_opened && v->is_id3_timestamped != 0) { - /* Intercept ID3 tags here, elementary audio streams are required - * to convey timestamps using them in the beginning of each segment. */ - intercept_id3(v, buf, buf_size, &ret); - } - + /* EOF flag may get set when the end of a segment is reached */ + v->pb.eof_reached = 0; + ret = av_read_frame(v->ctx, &v->pkt); + if (!ret) { return ret; } ff_format_io_close(v->parent, &v->input); v->cur_seq_no++; - c->cur_seq_no = v->cur_seq_no; + if (v->is_subtitle) + avformat_close_input(&v->ctx); + goto restart; } @@ -1492,16 +1570,6 @@ static int save_avio_options(AVFormatContext *s) return ret; } -static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, - int flags, AVDictionary **opts) -{ - av_log(s, AV_LOG_ERROR, - "A HLS playlist item '%s' referred to an external file '%s'. " - "Opening this file was forbidden for security reasons\n", - s->filename, url); - return AVERROR(EPERM); -} - static void add_stream_to_programs(AVFormatContext *s, struct playlist *pls, AVStream *stream) { HLSContext *c = s->priv_data; @@ -1602,6 +1670,7 @@ static int hls_close(AVFormatContext *s) free_rendition_list(c); av_dict_free(&c->avio_opts); + av_dict_free(&c->demuxer_opts); return 0; } @@ -1708,10 +1777,13 @@ static int hls_read_header(AVFormatContext *s) highest_cur_seq_no = FFMAX(highest_cur_seq_no, pls->cur_seq_no); } + av_dict_set(&c->demuxer_opts, "prefer_hls_mpegts_pts", "1", 0); + /* Open the demuxer for each playlist */ for (i = 0; i < c->n_playlists; i++) { struct playlist *pls = c->playlists[i]; AVInputFormat *in_fmt = NULL; + AVDictionary *opts = NULL; if (!(pls->ctx = avformat_alloc_context())) { ret = AVERROR(ENOMEM); @@ -1765,7 +1837,9 @@ static int hls_read_header(AVFormatContext *s) if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0) goto fail; - ret = avformat_open_input(&pls->ctx, pls->segments[0]->url, in_fmt, NULL); + av_dict_copy(&opts, c->demuxer_opts, 0); + ret = avformat_open_input(&pls->ctx, pls->segments[0]->url, in_fmt, &opts); + av_dict_free(&opts); if (ret < 0) goto fail; @@ -1843,6 +1917,8 @@ static int recheck_discard_flags(AVFormatContext *s, int first) } else if (first && !pls->cur_needed && pls->needed) { if (pls->input) ff_format_io_close(pls->parent, &pls->input); + if (pls->is_subtitle) + avformat_close_input(&pls->ctx); pls->needed = 0; changed = 1; av_log(s, AV_LOG_INFO, "No longer receiving playlist %d\n", i); @@ -1909,7 +1985,7 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) while (1) { int64_t ts_diff; AVRational tb; - ret = av_read_frame(pls->ctx, &pls->pkt); + ret = read_packet(pls, &pls->pkt); if (ret < 0) { if (!avio_feof(&pls->pb) && ret != AVERROR_EOF) return ret; @@ -2085,7 +2161,11 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, /* Reset the pos, to let the mpegts demuxer know we've seeked. */ pls->pb.pos = 0; /* Flush the packet queue of the subdemuxer. */ - ff_read_frame_flush(pls->ctx); + if (pls->ctx) + ff_read_frame_flush(pls->ctx); + + if (pls->is_subtitle) + avformat_close_input(&pls->ctx); pls->seek_timestamp = seek_timestamp; pls->seek_flags = flags; -- 2.1.4
On Fri, Dec 16, 2016 at 05:13:50PM +0100, wm4 wrote:
On Thu, 15 Dec 2016 22:01:46 +0000 Franklin Phillips <franklinphillips@gmx.com> wrote:
Hi,
I tested this code by converting HLS streams into mp4 files and it seemed to work fine. However I recently compiled mpv with these changes and when I play back the Apple example stream given in ticket #2833, it seems to skip a lot of subtitles. It works fine for the real world streams I'm using it for but it's probably worth holding off with this change until that's worked out.
Could be a mpv-specific issue, maybe report it there. I think you might be right, I could not reproduce it with ffmpeg alone but I also cannot report it until these changes have been merged.
Also I tried to make minimal changes to the existing code path because there don't seem to be any tests for HLS making it hard to know when something is broken which I guess is why there is the duplication. However I think you are right and it should be refactored, I had a further look at how it could be done and will continue working on it.
I wonder why not. Couldn't we put a small HLS stream on disk for FATE and let libavformat demux it? This still wouldn't test HTTP interaction of course. This sounds like a good idea.
I have refactored the code to reduce duplication of code and sent the new patches.
On Fri, Dec 30, 2016 at 08:10:05PM +0000, Franklin Phillips wrote:
Each subtile segment is a WebVTT file and needs to be demuxed separately. These segments also contain a header to synchronize their timing with the MPEG TS stream so those timestamps are requested from the WebVTT demuxer through an AVOption.
Signed-off-by: Franklin Phillips <franklinphillips@gmx.com>
this breaks fate --- ./tests/ref/fate/segment-mp4-to-ts 2016-12-30 00:31:20.420965026 +0100 +++ tests/data/fate/segment-mp4-to-ts 2017-01-01 02:49:40.011075738 +0100 @@ -24,7 +24,7 @@ 0, 54000, 72000, 0, 4755, 0x2f642b58, F=0x0, S=1, 1, 0x00e000e0 0, 57600, 64800, 0, 1182, 0xbe1a4847, F=0x0, S=1, 1, 0x00e000e0 0, 61200, 61200, 0, 809, 0x8d948a4e, F=0x0, S=1, 1, 0x00e000e0 -0, 64800, 68400, 0, 656, 0x4fa03c2b, F=0x0, S=1, 1, 0x00e000e0 +0, 64800, 68400, 0, 656, 0x4fa03c2b, F=0x0 0, 68400, 86400, 0, 26555, 0x5629b584, S=1, 1, 0x00e000e0 0, 72000, 79200, 0, 1141, 0x761b31e8, F=0x0, S=1, 1, 0x00e000e0 0, 75600, 75600, 0, 717, 0x57746351, F=0x0, S=1, 1, 0x00e000e0 @@ -48,7 +48,7 @@ 0, 140400, 158400, 3600, 5328, 0xd2c55ac6, F=0x0, S=1, 1, 0x00e000e0 0, 144000, 151200, 3600, 1271, 0x46006870, F=0x0, S=1, 1, 0x00e000e0 0, 147600, 147600, 3600, 849, 0x94dc99c7, F=0x0, S=1, 1, 0x00e000e0 -0, 151200, 154800, 3600, 753, 0xf4236cab, F=0x0, S=1, 1, 0x00e000e0 +0, 151200, 154800, 3600, 753, 0xf4236cab, F=0x0 0, 154800, 172800, 3600, 25825, 0xd5464dee, S=1, 1, 0x00e000e0 0, 158400, 165600, 3600, 1206, 0x8ce84344, F=0x0, S=1, 1, 0x00e000e0 0, 162000, 162000, 3600, 867, 0x312fa07d, F=0x0, S=1, 1, 0x00e000e0 @@ -96,7 +96,7 @@ 0, 313200, 331200, 3600, 5352, 0x59997996, F=0x0, S=1, 1, 0x00e000e0 0, 316800, 324000, 3600, 1501, 0xb3b8f001, F=0x0, S=1, 1, 0x00e000e0 0, 320400, 320400, 3600, 941, 0x92b0cb18, F=0x0, S=1, 1, 0x00e000e0 -0, 324000, 327600, 3600, 823, 0x3d548355, F=0x0, S=1, 1, 0x00e000e0 +0, 324000, 327600, 3600, 823, 0x3d548355, F=0x0 0, 327600, 345600, 3600, 24042, 0x441e94fb, S=1, 1, 0x00e000e0 0, 331200, 338400, 3600, 1582, 0x4f5d1049, F=0x0, S=1, 1, 0x00e000e0 0, 334800, 334800, 3600, 945, 0x4f3cc9e8, F=0x0, S=1, 1, 0x00e000e0 @@ -120,7 +120,7 @@ 0, 399600, 417600, 3600, 1862, 0x22a2a06c, F=0x0, S=1, 1, 0x00e000e0 0, 403200, 410400, 3600, 359, 0x11bdae52, F=0x0, S=1, 1, 0x00e000e0 0, 406800, 406800, 3600, 235, 0xbec26964, F=0x0, S=1, 1, 0x00e000e0 -0, 410400, 414000, 3600, 221, 0x8380682c, F=0x0, S=1, 1, 0x00e000e0 +0, 410400, 414000, 3600, 221, 0x8380682c, F=0x0 0, 414000, 432000, 3600, 22588, 0xf0ecf072, S=1, 1, 0x00e000e0 0, 417600, 424800, 3600, 383, 0x4f3bb571, F=0x0, S=1, 1, 0x00e000e0 0, 421200, 421200, 3600, 257, 0x22e87802, F=0x0, S=1, 1, 0x00e000e0 Test segment-mp4-to-ts failed. Look at tests/data/fate/segment-mp4-to-ts.err for details. make: *** [fate-segment-mp4-to-ts] Error 1 TEST segment-adts-to-mkv --- ./tests/ref/fate/segment-adts-to-mkv-header-all 2016-12-30 00:31:20.420965026 +0100 +++ tests/data/fate/segment-adts-to-mkv 2017-01-01 02:49:40.047075739 +0100 @@ -21,21 +21,3 @@ 0, 832, 832, 64, 147, 0x226043d7 0, 896, 896, 64, 119, 0x8ad931ed 0, 960, 960, 64, 153, 0xbb6e432f -0, 1024, 1024, 64, 185, 0xa01f4ff3 -0, 1088, 1088, 64, 126, 0x85503ce6 -0, 1152, 1152, 64, 246, 0x652c7b59 -0, 1216, 1216, 64, 162, 0xc9f04da0 -0, 1280, 1280, 64, 135, 0x71fa3be0 -0, 1344, 1344, 64, 246, 0x7a6f7788 -0, 1408, 1408, 64, 262, 0xd3097781 -0, 1472, 1472, 64, 60, 0x09a118f5 -0, 1536, 1536, 64, 255, 0xbab5793c -0, 1600, 1600, 64, 153, 0x6b6a44fb -0, 1664, 1664, 64, 160, 0x550e4530 -0, 1728, 1728, 64, 215, 0x7fe66144 -0, 1792, 1792, 64, 144, 0xcd723f7d -0, 1856, 1856, 64, 187, 0x2a0b5c1b -0, 1920, 1920, 64, 177, 0xb8c355d5 -0, 1984, 1984, 64, 156, 0x867d4f3a -0, 2048, 2048, 64, 201, 0x62745ff9 -0, 2112, 2112, 64, 137, 0x90c639e0 Test segment-adts-to-mkv failed. Look at tests/data/fate/segment-adts-to-mkv.err for details. make: *** [fate-segment-adts-to-mkv] Error 1 GEN tests/data/adts-to-mkv-cated-000.mkv GEN tests/data/adts-to-mkv-cated-001.mkv [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The misfortune of the wise is better than the prosperity of the fool. -- Epicurus
Sorry for the test failure, I didn't realise there were tests for HLS demuxer because the tests don't have HLS in their names. I am sending new patches which don't break the tests.
participants (4)
-
Anssi Hannula -
Franklin Phillips -
Michael Niedermayer -
wm4