[FFmpeg-devel] [PATCH 06/11] avformat/dashenc: addition of @availabilityTimeOffset in MPD

vdixit at akamai.com vdixit at akamai.com
Fri Mar 23 07:27:05 EET 2018


From: Vishwanath Dixit <vdixit at akamai.com>

availability time of Nth segment = availabilityStartTime + (N*segment duration) - availabilityTimeOffset.
This field helps to reduce the latency by about a segment duration in streaming mode.
---
 libavformat/dashenc.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index b62cb3e..d20bdba 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -85,6 +85,7 @@ typedef struct OutputStream {
     char filename[1024];
     char full_path[1024];
     char temp_path[1024];
+    int64_t chunk_duration;
 } OutputStream;
 
 typedef struct DASHContext {
@@ -343,8 +344,12 @@ static void output_segment_list(OutputStream *os, AVIOContext *out, AVFormatCont
     if (c->use_template) {
         int timescale = c->use_timeline ? os->ctx->streams[0]->time_base.den : AV_TIME_BASE;
         avio_printf(out, "\t\t\t\t<SegmentTemplate timescale=\"%d\" ", timescale);
-        if (!c->use_timeline)
+        if (!c->use_timeline) {
             avio_printf(out, "duration=\"%d\" ", c->seg_duration);
+            if (c->streaming && os->chunk_duration)
+                avio_printf(out, "availabilityTimeOffset=\"%.3f\" ",
+                            ((double) c->seg_duration - os->chunk_duration) / AV_TIME_BASE);
+        }
         avio_printf(out, "initialization=\"%s\" media=\"%s\" startNumber=\"%d\">\n", c->init_seg_name, c->media_seg_name, c->use_timeline ? start_number : 1);
         if (c->use_timeline) {
             int64_t cur_time = 0;
@@ -1283,6 +1288,10 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
         format_date_now(c->availability_start_time,
                         sizeof(c->availability_start_time));
 
+    if (!os->chunk_duration && pkt->duration)
+        os->chunk_duration = av_rescale_q(pkt->duration, st->time_base,
+                                          AV_TIME_BASE_Q);
+
     if (c->use_template && !c->use_timeline) {
         elapsed_duration = pkt->pts - os->first_pts;
         seg_end_duration = (int64_t) os->segment_index * c->seg_duration;
-- 
1.9.1



More information about the ffmpeg-devel mailing list