[FFmpeg-devel] [PATCH] avformat/hlsenc: check the segment duration valid

Steven Liu lq at chinaffmpeg.org
Mon Aug 17 10:11:46 EEST 2020


Output a warning message if the target duration of the segment is negative.
Suggest user increase the hls_time value,
and modify the target duration to one packet duration,
because there maybe have bframe and then split not by keyframe,
and the segment is very very small.

Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
---
 libavformat/hlsenc.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index cb31d6aed7..79ee39aa23 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2512,6 +2512,12 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
 
         if (vs->start_pos || hls->segment_type != SEGMENT_TYPE_FMP4) {
             double cur_duration =  (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den;
+            if (cur_duration < 0) {
+                av_log(s, AV_LOG_WARNING, "The target duration incorrect, maybe you splited a too short segment, "
+                                        "you should increase the hls_time, "
+                                        "now the duration will set to 1 packet duration, but maybe incorrect too.\n");
+                cur_duration = vs->duration;
+            }
             ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, vs->size);
             vs->end_pts = pkt->pts;
             vs->duration = 0;
-- 
2.25.0





More information about the ffmpeg-devel mailing list