From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 6D24E44AD8
	for <ffmpegdev@gitmailbox.com>; Mon, 21 Apr 2025 18:30:08 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7A314687DE9;
	Mon, 21 Apr 2025 21:30:04 +0300 (EEST)
Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com
 [209.85.208.46])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E2F2C687C1E
 for <ffmpeg-devel@ffmpeg.org>; Mon, 21 Apr 2025 21:29:58 +0300 (EEST)
Received: by mail-ed1-f46.google.com with SMTP id
 4fb4d7f45d1cf-5e8be1c6ff8so7663827a12.1
 for <ffmpeg-devel@ffmpeg.org>; Mon, 21 Apr 2025 11:29:58 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1745260198; x=1745864998; darn=ffmpeg.org;
 h=user-agent:in-reply-to:content-disposition:mime-version:references
 :mail-followup-to:message-id:subject:to:from:date:from:to:cc:subject
 :date:message-id:reply-to;
 bh=yJ76pNEUHjz0B6KiduPbKURsf6vHeEtpasIa/RiD7vo=;
 b=kb1/1kaNMAmVrel770u7+qprhMENK0Io3JxyIEb8NpfIlcAclxQRdNxzVEQ242WboG
 i3Ow/nBGxdf58LMSiYHQ9Q99pyciwZdD5cXQSSnt8DuZeXY0JFTCiC0khZuFEYN5QJuw
 UiZgEQr+PocOxgFBoZ5NFCmsAvH4rx8qGcfnj3wd7Ay2+uYWvHq0ltIXesHJe/rGl4js
 GxxvO+ua/FQij09ONi62Z/U7jQ8bkhOCvO9Fi9HJUMELJhzHSVd59uJbd5P4wV8mNUTP
 LJhPJN0PHFX/GsxxZwZH4ZUibbH/uJQDc/kdwXFvS+bzuMcLSwIITdF/N+EsQ0Bb4oYl
 1b/Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1745260198; x=1745864998;
 h=user-agent:in-reply-to:content-disposition:mime-version:references
 :mail-followup-to:message-id:subject:to:from:date:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=yJ76pNEUHjz0B6KiduPbKURsf6vHeEtpasIa/RiD7vo=;
 b=VxivBMzp8okRWfz4WL6CAL3/AP4nMvYh3y7Xp705Aw00rvIwc+W1vJJAeVat/QJ6V6
 MaHfZDdyQCowxJxJKEmTCsz7CyQI0o5vjcIbNfgHBA8l+TBsPhcRBuD5Ui8fwJypMkRH
 gBTc5N9K1edtXmsd4RgvfinbWeelgyS0vJhwdWpq0SaMOAys3mXoLulV0QDkoAEaHNQw
 GSyyR0iXFz3K/+8WWROt8ksodkSyOIVKkyad/87Af0Gu+/0B+s29kEf8Up9iP5zLg29n
 KQSK9d759ra1syiJHOV+9v2tEVTs4Cfn28WK/qF0Ra7HiaJ9Rk555deR4FIvNXDcV2ch
 6QFA==
X-Gm-Message-State: AOJu0Yy3q06MnCwgmHahWf+vb75Re+NaZuCgfvj6Gtv921zDvdnqBvIs
 YiI5H5aXjR4wzB/DvDHX+BWV4DzphfYfLgiSMC+WJTjOVVC1/s2ZUc5tBg==
X-Gm-Gg: ASbGnct9kUye77wlNNBTAU/LxxE+OPaYA6KNIF/1HaKjqoNCPaRIoi6rkL/8pAdBfIV
 t8TtPmX4q0QJ1i724OYmUz9aadPrj84KnJdn+bV81A91MOqy+cX2kM5tXxHFicOp5tgW1pEL51H
 uENMCL/yY1KVeaxjZwnFuLk15pxzXPq5XRckQYEpq7GIxL1fK5Q4/nisYQbFjcyl7zUVILuQgIx
 g0/rgk8tkQF+aZ741R3a3f6Yw5+yL4Yhu9pJH70eOZZK0a3tNpC+3dvcZ0gwzYA/jT2oQGIvMHb
 W5CztNr93F4pFvIISF3jpv/cw22aeDMF0eZO8UOCmNPgCTgGomNEGg4t+0eQwyLquvYBPxpV8hh
 sUh/9utDXoXUBORU=
X-Google-Smtp-Source: AGHT+IHtAU0bLe2qAydhh948DGVJRGMouNqH34DR9IAaWnU0Z+/aEhLhhyvxcPnFmo19oQB5ygw/rA==
X-Received: by 2002:a05:6402:27d4:b0:5f5:a27f:6845 with SMTP id
 4fb4d7f45d1cf-5f628563a1amr12661234a12.18.1745260197660; 
 Mon, 21 Apr 2025 11:29:57 -0700 (PDT)
Received: from mariano (dynamic-adsl-84-220-189-10.clienti.tiscali.it.
 [84.220.189.10]) by smtp.gmail.com with ESMTPSA id
 4fb4d7f45d1cf-5f625a5ec5bsm4794309a12.81.2025.04.21.11.29.56
 for <ffmpeg-devel@ffmpeg.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 21 Apr 2025 11:29:57 -0700 (PDT)
Received: by mariano (Postfix, from userid 1000)
 id 6A22FBFCE8; Mon, 21 Apr 2025 20:29:55 +0200 (CEST)
Date: Mon, 21 Apr 2025 20:29:55 +0200
From: Stefano Sabatini <stefasab@gmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Message-ID: <aAaOo/EIFF0O9lJG@mariano>
Mail-Followup-To: FFmpeg development discussions and patches
 <ffmpeg-devel@ffmpeg.org>
References: <20250415104439.13431-1-ffmpeg@gyani.pro>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <20250415104439.13431-1-ffmpeg@gyani.pro>
User-Agent: Mutt/2.1.4 (2021-12-11)
Subject: Re: [FFmpeg-devel] [PATCH v2 1/2] avformat: add
 avformat_query_seekable
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/aAaOo%2FEIFF0O9lJG@mariano/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

On date Tuesday 2025-04-15 16:09:56 +0530, Gyan Doshi wrote:
> Utility function to report seekability features for a given input.
> 
> Useful for ffprobe and to extend seek possibilities in fftools.
> ---
> v2:
>    made constants more descriptive
>    add exception for rtsp false negative seekability
> 
>  doc/APIchanges         |  3 +++
>  libavformat/avformat.h | 22 ++++++++++++++++++
>  libavformat/seek.c     | 53 ++++++++++++++++++++++++++++++++++++++++++
>  libavformat/version.h  |  2 +-
>  4 files changed, 79 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 65bf5a9419..879f56b572 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28
>  
>  API changes, most recent first:
>  
> +2025-04-xx - xxxxxxxxxx - lavf 62.1.100 - avformat.h
> +  Add avformat_query_seekable().
> +
>  2025-04-07 - 19e9a203b7 - lavu 60.01.100 - dict.h
>    Add AV_DICT_DEDUP.
>  
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 498c3020a5..f9da5e9e79 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -2338,6 +2338,28 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
>   */
>  int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
>  
> +#define AVSEEKABLE_IO_NORMAL       0x00000001 ///< I/O is seekable like a local file
> +#define AVSEEKABLE_IO_PROTOCOL     0x00000002 ///< I/O seek is through protocol request via avio_seek_time
> +#define AVSEEKABLE_VIA_DEMUXER     0x00000004 ///< demuxer has a seek function
> +#define AVSEEKABLE_VIA_PKTSCAN     0x00000008 ///< seek is performed by consuming and scanning packet timestamps
> +#define AVSEEKABLE_BY_TIME         0x00000100 ///< seek target can be a timestamp
> +#define AVSEEKABLE_BY_BYTE         0x00000200 ///< seek target can be in bytes
> +#define AVSEEKABLE_BY_FRAME        0x00000400 ///< seek target can be a frame index
> +#define AVSEEKABLE_PROP_PTS        0x00010000 ///< seek target timestamp is expected to be PTS
> +#define AVSEEKABLE_PROP_FAST       0x00020000 ///< demuxer allows fast but inaccurate seeking

> +#define AVSEEKABLE_PROP_FWDONLY    0x00040000 ///< set seek will be equal or forward of specified seek point

Not sure I get this, can you clarify/expand?

> +/**
> + * Report if and how a seek can be performed in a given input.

I don't like the "can be performed in a given input" part, I'd use a
terminology closer to the function name: "for this format context".

Also, probably we want to specify that the method should be used after
the open operation or whatever.

> + *
> + * @param s            media file handle
> + *
> + * @return 0 if no seek can be performed on input,
> + *         -1 if the fmt ctx is NULL or is not an input
> + *         else return AVSEEKABLE_ bitflags indicating seekability features.
> + */
> +int avformat_query_seekable(AVFormatContext *s);
> +
>  /**
>   * Discard all internally buffered data. This can be useful when dealing with
>   * discontinuities in the byte stream. Generally works only with formats that
> diff --git a/libavformat/seek.c b/libavformat/seek.c
> index c0d94371e6..8be1bdec30 100644
> --- a/libavformat/seek.c
> +++ b/libavformat/seek.c
> @@ -712,6 +712,59 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts,
>      return ret;
>  }
>  
> +int avformat_query_seekable(AVFormatContext *s)
> +{
> +    int ret = 0;
> +
> +    if (!s || !s->iformat)
> +        return -1;
> +
> +    if ( strcmp(s->iformat->name, "rtsp") && (!(s->pb && s->pb->seekable) || s->ctx_flags & AVFMTCTX_UNSEEKABLE) )
> +        return 0;
> +
> +    if (s->pb->seekable & AVIO_SEEKABLE_NORMAL)
> +        ret |= AVSEEKABLE_IO_NORMAL;
> +
> +    if (s->pb->seekable & AVIO_SEEKABLE_TIME)
> +        ret |= AVSEEKABLE_IO_PROTOCOL;
> +
> +    if (ffifmt(s->iformat)->read_seek || ffifmt(s->iformat)->read_seek2)
> +        ret |= AVSEEKABLE_VIA_DEMUXER;
> +
> +    if (ffifmt(s->iformat)->read_timestamp && !(s->iformat->flags & AVFMT_NOBINSEARCH))
> +        ret |= AVSEEKABLE_VIA_PKTSCAN;
> +
> +    if (!(s->iformat->flags & AVFMT_NOTIMESTAMPS))
> +        ret |= AVSEEKABLE_BY_TIME;
> +
> +    // TODO: incomplete, a few demuxers don't set flag but error out on byte seek
> +    if (!(s->iformat->flags & AVFMT_NO_BYTE_SEEK))
> +        ret |= AVSEEKABLE_BY_BYTE;
> +
> +    // TODO: no flag for frame seeking. Add flag and enable this check
> +    if (s->iformat->flags & 0)
> +        ret |= AVSEEKABLE_BY_FRAME;
> +
> +    if (s->iformat->flags & AVFMT_SEEK_TO_PTS)
> +        ret |= AVSEEKABLE_PROP_PTS;
> +
> +    // TODO: flag exists but not added to the demuxers which support it
> +    if (s->iformat->flags & AVFMT_FLAG_FAST_SEEK)
> +        ret |= AVSEEKABLE_PROP_FAST;
> +
> +    if (!(ret & AVSEEKABLE_VIA_DEMUXER) && ret & AVSEEKABLE_VIA_PKTSCAN)
> +        ret |= AVSEEKABLE_PROP_FWDONLY;
> +
> +    if ( !(ret & AVSEEKABLE_VIA_DEMUXER) &&
> +         !(ret & AVSEEKABLE_VIA_PKTSCAN) &&
> +         !(ret & AVSEEKABLE_BY_BYTE) &&
> +         !(ret & AVSEEKABLE_IO_PROTOCOL) &&
> +         (s->iformat->flags & AVFMT_NOGENSEARCH) )
> +        ret = 0;
> +
> +    return ret;
> +}
> +
>  /** Flush the frame reader. */
>  void ff_read_frame_flush(AVFormatContext *s)
>  {
> diff --git a/libavformat/version.h b/libavformat/version.h
> index 752aac16f7..a7c80dc564 100644
> --- a/libavformat/version.h
> +++ b/libavformat/version.h
> @@ -31,7 +31,7 @@
>  
>  #include "version_major.h"
>  
> -#define LIBAVFORMAT_VERSION_MINOR   0
> +#define LIBAVFORMAT_VERSION_MINOR   1
>  #define LIBAVFORMAT_VERSION_MICRO 100
>  
>  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
> -- 
> 2.49.0
> 
> _______________________________________________
> 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".
_______________________________________________
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".