diff mbox

[FFmpeg-devel,2/2] avformat/dashenc: Added support for Low-latency HLS(LHLS)

Message ID 20181212071821.27106-2-kjeyapal@akamai.com
State New
Headers show

Commit Message

Jeyapal, Karthick Dec. 12, 2018, 7:18 a.m. UTC
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(-)

Comments

Moritz Barsnick Dec. 12, 2018, 3:40 p.m. UTC | #1
On Wed, Dec 12, 2018 at 12:48:21 +0530, Karthick J wrote:
> 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.

Doesn't this imply it should be guarded under "-strict experimental" /
FF_COMPLIANCE_EXPERIMENTAL? You will be creating streams which may
later not conform to the spec anymore (?).

Moritz
Jeyapal, Karthick Dec. 12, 2018, 3:43 p.m. UTC | #2
On 12/12/18 9:10 PM, Moritz Barsnick wrote:
> On Wed, Dec 12, 2018 at 12:48:21 +0530, Karthick J wrote:

>> 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.

>

> Doesn't this imply it should be guarded under "-strict experimental" /

> FF_COMPLIANCE_EXPERIMENTAL? You will be creating streams which may

> later not conform to the spec anymore (?).

Yes, that makes sense. Thanks for pointing it out.

Regards,
Karthick
>

> Moritz

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

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</SegmentList>\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 },
 };