From patchwork Wed Dec 12 07:18:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jeyapal, Karthick" X-Patchwork-Id: 11376 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C7855440597 for ; Wed, 12 Dec 2018 09:18:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1D1B968A6E1; Wed, 12 Dec 2018 09:18:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from a2i252.smtp2go.com (a2i252.smtp2go.com [103.47.204.252]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1E26E68A688 for ; Wed, 12 Dec 2018 09:18:24 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1544600021; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=R5CDg0bvieGf+yIZxOvJs1/NKEfNYoEyAh40CJE50L0=; b=dRhDGKlQ J5JlWdMVXYTMJpN5n584p0p5EEdAeRwQFqU+JGCcgRAw5rO0SjSY+p4P3IotmGbnfIh1EYV0L49+5 i1tVAXNC6mQ+PV6OoXmWNVA2X/jsreOjvQilXDyAs9YmiJJtj3UbPZVRKOTsp6ZPopmJHUaSDMT01 BkTZLVady9vi5hf/9Lzfo0ZNOiEBQP1JEg+kYrgM8x0zeRX9fwpB2fIm6ymx3npaZJg9k/coFiB5W pa2Vc11lwmeAvPpm65nq0GJC94BQQ852KGPd0Gab4FpgqB9QmBp3HpzVLmLyzCiAW/QZhQCbhLmhy If5n343vCr5vxN/fMdkYrLF2Ww==; Received: from [10.45.33.53] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1gWymw-095HiX-P4; Wed, 12 Dec 2018 07:18:34 +0000 Received: from [10.106.51.21] (helo=blr-mp4tf.bangalore.corp.akamai.com) by smtpcorp.com with esmtpa (Exim 4.91) (envelope-from ) id 1gWymv-rlZ9hm-IK; Wed, 12 Dec 2018 07:18:34 +0000 From: Karthick J To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Dec 2018 12:48:21 +0530 Message-Id: <20181212071821.27106-2-kjeyapal@akamai.com> X-Mailer: git-send-email 2.17.1 (Apple Git-112) In-Reply-To: <20181212071821.27106-1-kjeyapal@akamai.com> References: <20181212071821.27106-1-kjeyapal@akamai.com> X-Smtpcorp-Track: 1gWyXvr_Z9hXmK.EeZmazCBs Feedback-ID: 337386m:337386asVRLGB:337386s2Q-KLXdm0 X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH 2/2] avformat/dashenc: Added support for Low-latency HLS(LHLS) X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Karthick J MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Apple doesn't have an official spec for LHLS. Meanwhile hls.js player folks are trying to standardize a open LHLS spec. The draft spec is available in https://github.com/video-dev/hlsjs-rfcs/blob/lhls-spec/proposals/0001-lhls.md This option will also try to comply with the above open spec, till Apple's spec officially supports it. Applicable only when @var{streaming} and @var{hls_playlist} options are enabled. --- doc/muxers.texi | 7 +++++++ libavformat/dashenc.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 809f88662e..f09a89db82 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -305,6 +305,13 @@ If this flag is set, the dash segment files will be in in WebM format. @item -ignore_io_errors @var{ignore_io_errors} Ignore IO errors during open and write. Useful for long-duration runs with network output. +@item -lhls @var{lhls} +Enable Low-latency HLS(LHLS). Adds #EXT-X-PREFETCH tag with current segment's URI. +Apple doesn't have an official spec for LHLS. Meanwhile hls.js player folks are +trying to standardize a open LHLS spec. The draft spec is available in https://github.com/video-dev/hlsjs-rfcs/blob/lhls-spec/proposals/0001-lhls.md +This option will also try to comply with the above open spec, till Apple's spec officially supports it. +Applicable only when @var{streaming} and @var{hls_playlist} options are enabled. + @end table @anchor{framecrc} diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index f797b7bd1c..8685642437 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -139,6 +139,7 @@ typedef struct DASHContext { char *format_options_str; SegmentType segment_type_option; /* segment type as specified in options */ int ignore_io_errors; + int lhls; } DASHContext; static struct codec_string { @@ -418,7 +419,8 @@ static void get_start_index_number(OutputStream *os, DASHContext *c, } static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, - int representation_id, int final) { + int representation_id, int final, + char *prefetch_url) { DASHContext *c = s->priv_data; int timescale = os->ctx->streams[0]->time_base.den; char temp_filename_hls[1024]; @@ -431,6 +433,11 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, int i, start_index, start_number; get_start_index_number(os, c, &start_index, &start_number); + + if (!c->hls_playlist || start_index >= os->nb_segments || + os->segment_type != SEGMENT_TYPE_MP4) + return; + get_hls_playlist_name(filename_hls, sizeof(filename_hls), c->dirname, representation_id); @@ -468,6 +475,9 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, } } + if (prefetch_url) + avio_printf(c->m3u8_out, "#EXT-X-PREFETCH:%s\n", prefetch_url); + if (final) ff_hls_write_end_list(c->m3u8_out); @@ -594,9 +604,8 @@ static void output_segment_list(OutputStream *os, AVIOContext *out, AVFormatCont } avio_printf(out, "\t\t\t\t\n"); } - if (c->hls_playlist && start_index < os->nb_segments && os->segment_type == SEGMENT_TYPE_MP4) - { - write_hls_media_playlist(os, s, representation_id, final); + if (!c->lhls || final) { + write_hls_media_playlist(os, s, representation_id, final, NULL); } } @@ -1054,6 +1063,15 @@ static int dash_init(AVFormatContext *s) c->seg_duration = c->min_seg_duration; } #endif + if (c->lhls && !c->streaming) { + av_log(s, AV_LOG_WARNING, "LHLS option will be ignored as streaming is not enabled\n"); + c->lhls = 0; + } + + if (c->lhls && !c->hls_playlist) { + av_log(s, AV_LOG_WARNING, "LHLS option will be ignored as hls_playlist is not enabled\n"); + c->lhls = 0; + } av_strlcpy(c->dirname, s->url, sizeof(c->dirname)); ptr = strrchr(c->dirname, '/'); @@ -1635,6 +1653,10 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) { return handle_io_open_error(s, ret, os->temp_path); } + if (c->lhls) { + char *prefetch_url = use_rename ? NULL : os->filename; + write_hls_media_playlist(os, s, pkt->stream_index, 0, prefetch_url); + } } //write out the data immediately in streaming mode @@ -1760,6 +1782,7 @@ static const AVOption options[] = { { "mp4", "make segment file in ISOBMFF format", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_MP4 }, 0, UINT_MAX, E, "segment_type"}, { "webm", "make segment file in WebM format", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_WEBM }, 0, UINT_MAX, E, "segment_type"}, { "ignore_io_errors", "Ignore IO errors during open and write. Useful for long-duration runs with network output", OFFSET(ignore_io_errors), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E }, + { "lhls", "Enable Low-latency HLS(LHLS). Adds #EXT-X-PREFETCH tag with current segment's URI", OFFSET(lhls), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E }, { NULL }, };