[FFmpeg-cvslog] dashenc: Adjust the start time of a segment to the end of the previous segment

Martin Storsjö git at videolan.org
Wed Dec 17 14:04:37 CET 2014


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Fri Nov 28 10:43:53 2014 +0200| [456e93bfdd4cbc5e995dea415019abd0703d0e16] | committer: Martin Storsjö

dashenc: Adjust the start time of a segment to the end of the previous segment

This is the same adjustment that the mp4 muxer does to the start
timestamp of fragments, since the timestamp of a sample in an mp4
file is implicit from the sum of earlier sample durations.

This avoids gaps in the timeline (which can stop dash.js from
playing it back), and makes sure the timestamp on the segmenter
level matches what the mp4 muxer actually writes into the segments.

This is only an issue if the AVPacket duration of the last
packet of a segment doesn't point to the actual start timestamp
of the next packet (the first in the next segment).

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=456e93bfdd4cbc5e995dea415019abd0703d0e16
---

 libavformat/dashenc.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index a55cd67..b4fd194 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -652,6 +652,7 @@ static int dash_write_header(AVFormatContext *s)
 
         set_codec_str(s, os->ctx->streams[0]->codec, os->codec_str, sizeof(os->codec_str));
         os->first_dts = AV_NOPTS_VALUE;
+        os->end_dts = AV_NOPTS_VALUE;
         os->segment_index = 1;
     }
 
@@ -861,8 +862,15 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
             return ret;
     }
 
-    if (!os->packets_written)
-        os->start_dts = pkt->dts;
+    if (!os->packets_written) {
+        // If we wrote a previous segment, adjust the start time of the segment
+        // to the end of the previous one (which is the same as the mp4 muxer
+        // does). This avoids gaps in the timeline.
+        if (os->end_dts != AV_NOPTS_VALUE)
+            os->start_dts = os->end_dts;
+        else
+            os->start_dts = pkt->dts;
+    }
     os->end_dts = pkt->dts + pkt->duration;
     os->packets_written++;
     return ff_write_chained(os->ctx, 0, pkt, s);



More information about the ffmpeg-cvslog mailing list