[FFmpeg-devel] [PATCH 1/2] avformat hls fix to seek logic

vectronic hello.vectronic at gmail.com
Fri Apr 24 18:20:41 EEST 2020


ensure a keyframe is returned if AVSEEK_FLAG_ANY is not specified

Signed-off-by: vectronic <hello.vectronic at gmail.com>
---
 libavformat/hls.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index fc45719d1c..4e59142c99 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -2146,8 +2146,10 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
                     ts_diff = av_rescale_rnd(pls->pkt.dts, AV_TIME_BASE,
                                             tb.den, AV_ROUND_DOWN) -
                             pls->seek_timestamp;
-                    if (ts_diff >= 0 && (pls->seek_flags  & AVSEEK_FLAG_ANY ||
-                                        pls->pkt.flags & AV_PKT_FLAG_KEY)) {
+                    /* If AVSEEK_FLAG_ANY, keep reading until ts_diff is greater than 0
+                     * otherwise return the first keyframe encountered */
+                    if ((ts_diff >= 0 && (pls->seek_flags & AVSEEK_FLAG_ANY)) ||
+                        (!(pls->seek_flags & AVSEEK_FLAG_ANY) && (pls->pkt.flags & AV_PKT_FLAG_KEY)))  {
                         pls->seek_timestamp = AV_NOPTS_VALUE;
                         break;
                     }
@@ -2291,7 +2293,7 @@ static int hls_read_seek(AVFormatContext *s, int stream_index,
         pls->pb.eof_reached = 0;
         /* Clear any buffered data */
         pls->pb.buf_end = pls->pb.buf_ptr = pls->pb.buffer;
-        /* Reset the pos, to let the mpegts demuxer know we've seeked. */
+        /* Reset the pos, to let the mpegts/mov demuxer know we've seeked. */
         pls->pb.pos = 0;
         /* Flush the packet queue of the subdemuxer. */
         ff_read_frame_flush(pls->ctx);
-- 
2.24.2 (Apple Git-127)



More information about the ffmpeg-devel mailing list