[FFmpeg-devel] [PATCH v2] avformat/hls Implement support for using AVSEEK_FLAG_BACKWARD when seeking

Gustav Grusell gustav.grusell at gmail.com
Fri Jun 11 09:33:52 EEST 2021


On Sat, Jun 5, 2021 at 10:41 PM Gustav Grusell <gustav.grusell at gmail.com>
wrote:

> Before, seeking in hls streams would always seek to the next keyframe
> after the given timestamp.
> With this fix, if 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 <gustav.grusell at gmail.com>
> ---
>  libavformat/hls.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index 8fc6924c90..fb8c9b071a 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -2197,6 +2197,15 @@ static int hls_read_packet(AVFormatContext *s,
> AVPacket *pkt)
>                          break;
>                      }
>
> +                    /* If AVSEEK_FLAG_BACKWARD set and not
> AVSEEK_FLAG_ANY,
> +                     * we return the first keyframe encountered */
> +                    if (pls->seek_flags & AVSEEK_FLAG_BACKWARD &&
> +                        !(pls->seek_flags & AVSEEK_FLAG_ANY) &&
> +                        pls->pkt->flags & AV_PKT_FLAG_KEY) {
> +                        pls->seek_timestamp = AV_NOPTS_VALUE;
> +                        break;
> +                    }
> +
>                      tb = get_timebase(pls);
>                      ts_diff = av_rescale_rnd(pls->pkt->dts, AV_TIME_BASE,
>                                              tb.den, AV_ROUND_DOWN) -
> --
> 2.25.1
>
>
Any further comments on this?

Btw, it seems the v2 patch got picked up as a separate patch by patchwork.
Is this how it is supposed to work or did I miss something when doing git
send-email ?

cheers,
Gustav


More information about the ffmpeg-devel mailing list