From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A31FF40A21 for ; Wed, 2 Feb 2022 16:31:41 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D171868B0AC; Wed, 2 Feb 2022 18:31:39 +0200 (EET) Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 154A768A569 for ; Wed, 2 Feb 2022 18:31:33 +0200 (EET) Received: by mail-qt1-f181.google.com with SMTP id j12so17509754qtr.2 for ; Wed, 02 Feb 2022 08:31:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Wda4q9LtFPVt1g4lCAj7a5c+jDQy3NRMXR76f4hCpLg=; b=H3n9+1+Yo/oHladZ5SuMoQ6heAxzErCKhnYgpsnEwO8VjQggJdZZJv6jN2Dx52KgFv /IghjxHafLNDv7c12N0kexY32wWHsNtj0pUoiTiX8DkPbWVmacA5aq0dk5/9LBD2rSDr lxBr9V6djE+XdBiz1TxBnAk4J8AccJuPIUhYc6elq9JpZt+msiOn55UAOzwjV4N1CoAO eHyeCOdS4HnyEKLb8tBrylPaQ29O8jS/JgOI9guEFQqP77bWAhUf/mD5mV/0EocDkvD2 KAyhmZ2cgoW1UoIxP6YUMNmgxX+/dvLVuf3dHOy0/aqsA/sma1DW/4PYcOgLfyWc+2+/ lfAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Wda4q9LtFPVt1g4lCAj7a5c+jDQy3NRMXR76f4hCpLg=; b=oZAFVx/Z1FJedzLN+4bzWBkUvlaCQHZzcSAI+4GlX7MPlkf5hDKCZ5SbxoEF7v3PFo 59YyaNBoz2afmoDOTTMzto0vKHePebfKAcLAzOkiF6TuhiCNC+C5nnIJxyzCnCyfpKoA bM6w+w79td4JgygrvytNbHiY1jP7IwK5G/oXujfCvVR5zgqwRNKc4pAQKquRRKs93+7w cTHRfK3LM0gRJbhVpDEWuARR2XNyJlat9qDT8Mk2toZvJp8lKVHz+FM4e/JgzLluoY9E PQdUWW8z6hBINX8q3PNK1QUBxwNttpsdbs5OCdZM9aBaNSCh+Y8QtkTeVo2bPynySRxA 97Mw== X-Gm-Message-State: AOAM530kQ8CUEzG7D6/NFtQtu7/6BOal/RSK3E8Kv15YTMWCmEFT4zIV he3XemWyOBokEyaMFBzoyp/1sGgxnTYe0i78+rskcUFQ X-Google-Smtp-Source: ABdhPJwwwV/5y6cx1qrangUUuwJ4Nc/htH3jFDZ7+IVusOJbYUu/2htQT3PneHYApG357yZ8DXZO+N/kdRt8bjenbZI= X-Received: by 2002:a05:622a:1b15:: with SMTP id bb21mr23661582qtb.358.1643819491484; Wed, 02 Feb 2022 08:31:31 -0800 (PST) MIME-Version: 1.0 References: <20220128185254.1662873-1-gustav.grusell@gmail.com> <20220128202320.1711694-1-gustav.grusell@gmail.com> In-Reply-To: <20220128202320.1711694-1-gustav.grusell@gmail.com> From: Gustav Grusell Date: Wed, 2 Feb 2022 17:31:20 +0100 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] [PATCH v4] avformat/hls: Implement support for using AVSEEK_FLAG_BACKWARD when seeking X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Any comments on this? cheers, Gustav On Fri, Jan 28, 2022 at 9:24 PM Gustav Grusell wrote: > Before, seeking in hls streams would always seek to the next keyframe > after the given timestamp. With this fix, if seeking in videostream and > AVSEEK_FLAG_BACKWARD is set, seeking will be to the first keyframe of > the segment containing the given timestamp. This fixes #7485. > > Signed-off-by: Gustav Grusell > --- > libavformat/hls.c | 24 +++++++++++++++++------- > 1 file changed, 17 insertions(+), 7 deletions(-) > > diff --git a/libavformat/hls.c b/libavformat/hls.c > index 4568e72cb2..44afdaab42 100644 > --- a/libavformat/hls.c > +++ b/libavformat/hls.c > @@ -1653,7 +1653,8 @@ static void > add_metadata_from_renditions(AVFormatContext *s, struct playlist *pl > /* if timestamp was in valid range: returns 1 and sets seq_no > * if not: returns 0 and sets seq_no to closest segment */ > static int find_timestamp_in_playlist(HLSContext *c, struct playlist *pls, > - int64_t timestamp, int64_t *seq_no) > + int64_t timestamp, int64_t *seq_no, > + int64_t *seg_start_ts) > { > int i; > int64_t pos = c->first_timestamp == AV_NOPTS_VALUE ? > @@ -1668,6 +1669,9 @@ static int find_timestamp_in_playlist(HLSContext *c, > struct playlist *pls, > int64_t diff = pos + pls->segments[i]->duration - timestamp; > if (diff > 0) { > *seq_no = pls->start_seq_no + i; > + if (seg_start_ts) { > + *seg_start_ts = pos; > + } > return 1; > } > pos += pls->segments[i]->duration; > @@ -1691,7 +1695,7 @@ static int64_t select_cur_seq_no(HLSContext *c, > struct playlist *pls) > * playlist) and this is a complete file, find the matching segment > * by counting durations. */ > if (pls->finished && c->cur_timestamp != AV_NOPTS_VALUE) { > - find_timestamp_in_playlist(c, pls, c->cur_timestamp, &seq_no); > + find_timestamp_in_playlist(c, pls, c->cur_timestamp, &seq_no, > NULL); > return seq_no; > } > > @@ -2362,7 +2366,7 @@ static int hls_read_seek(AVFormatContext *s, int > stream_index, > int i, j; > int stream_subdemuxer_index; > int64_t first_timestamp, seek_timestamp, duration; > - int64_t seq_no; > + int64_t seq_no, seg_start_ts; > > if ((flags & AVSEEK_FLAG_BYTE) || (c->ctx->ctx_flags & > AVFMTCTX_UNSEEKABLE)) > return AVERROR(ENOSYS); > @@ -2372,8 +2376,7 @@ static int hls_read_seek(AVFormatContext *s, int > stream_index, > > seek_timestamp = av_rescale_rnd(timestamp, AV_TIME_BASE, > > s->streams[stream_index]->time_base.den, > - flags & AVSEEK_FLAG_BACKWARD ? > - AV_ROUND_DOWN : AV_ROUND_UP); > + AV_ROUND_DOWN); > > duration = s->duration == AV_NOPTS_VALUE ? > 0 : s->duration; > @@ -2394,9 +2397,16 @@ static int hls_read_seek(AVFormatContext *s, int > stream_index, > } > /* check if the timestamp is valid for the playlist with the > * specified stream index */ > - if (!seek_pls || !find_timestamp_in_playlist(c, seek_pls, > seek_timestamp, &seq_no)) > + if (!seek_pls || !find_timestamp_in_playlist(c, seek_pls, > seek_timestamp, &seq_no, &seg_start_ts)) > return AVERROR(EIO); > > + if (s->streams[stream_index]->codecpar->codec_type == > AVMEDIA_TYPE_VIDEO && > + flags & AVSEEK_FLAG_BACKWARD && !(flags & AVSEEK_FLAG_ANY)) { > + /* Seeking to start of segment ensures we seek to a keyframe > located > + * before the given timestamp. */ > + seek_timestamp = seg_start_ts; > + } > + > /* set segment now so we do not need to search again below */ > seek_pls->cur_seq_no = seq_no; > seek_pls->seek_stream_index = stream_subdemuxer_index; > @@ -2423,7 +2433,7 @@ static int hls_read_seek(AVFormatContext *s, int > stream_index, > > if (pls != seek_pls) { > /* set closest segment seq_no for playlists not handled above > */ > - find_timestamp_in_playlist(c, pls, seek_timestamp, > &pls->cur_seq_no); > + find_timestamp_in_playlist(c, pls, seek_timestamp, > &pls->cur_seq_no, NULL); > /* seek the playlist to the given position without taking > * keyframes into account since this playlist does not have > the > * specified stream where we should look for the keyframes */ > -- > 2.25.1 > > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".