This avoids that the mp4 muxer does a similar heuristic, adjusting
the timestamps in a way that the dash muxer doesn't know the actual
timestamps written to the file in the end. By making sure that the
mp4 muxer internal heuristic isn't applied, we know the exact
timestamps written to file, so that the timestamps in manifest match
the files.
---
 libavformat/dashenc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 1d32cdf..69a8f11 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -868,6 +868,16 @@ static int dash_write_packet(AVFormatContext *s, AVPacket 
*pkt)
         pkt->dts  = 0;
     }
 
+    // Fill in a heuristic guess of the packet duration, if none is available.
+    // The mp4 muxer will do something similar (for the last packet in a 
fragment)
+    // if nothing is set (setting it for the other packets doesn't hurt).
+    // By setting a nonzero duration here, we can be sure that the mp4 muxer 
won't
+    // invoke its heuristic (this doesn't have to be identical to that 
algorithm),
+    // so that we know the exact timestamps of fragments.
+    if (!pkt->duration && os->packets_written > 0) {
+        pkt->duration = (os->max_pts - os->start_pts) / os->packets_written;
+    }
+
     if (os->first_pts == AV_NOPTS_VALUE)
         os->first_pts = pkt->pts;
 
-- 
1.9.3 (Apple Git-50)

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to