From a137dfcf366a54634f70d50a66926d982b51d406 Mon Sep 17 00:00:00 2001 From: Reza Mir Date: Wed, 5 Aug 2020 21:00:23 -0400 Subject: [PATCH 1/2] Modify ffmpeg to avoid drifting in ABR segment generation --- libavformat/dashenc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 6fdc295ebf406..4cf570e11f6b7 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -2068,9 +2068,16 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) // 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 0 + /* + * Initializing start_pts with max_pts can cause some problem in very odd cases (RM). + * For example with fry's video transcoding max_pts starts to drift 1001 ts after second segment. + * The following change set forces start_pts of the segment to be pkt->pts of the first packet in the segment. + */ if (os->max_pts != AV_NOPTS_VALUE) os->start_pts = os->max_pts; else +#endif os->start_pts = pkt->pts; } if (os->max_pts == AV_NOPTS_VALUE) From c21b36426b4a40769b883c2a75170e6077eef28e Mon Sep 17 00:00:00 2001 From: Reza Mir Date: Wed, 5 Aug 2020 23:23:03 -0400 Subject: [PATCH 2/2] Add log for setting start_pts --- libavformat/dashenc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 4cf570e11f6b7..02fa36c5f5d25 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -2078,6 +2078,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) os->start_pts = os->max_pts; else #endif + av_log(s, AV_LOG_INFO, "SETTING START_PTS pkt->pts=%"PRId64", max_pts=%"PRId64, pkt->pts, os->max_pts); os->start_pts = pkt->pts; } if (os->max_pts == AV_NOPTS_VALUE)