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 D29B84CBB6 for <ffmpegdev@gitmailbox.com>; Sun, 13 Apr 2025 11:16:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A3E63687C77; Sun, 13 Apr 2025 14:16:12 +0300 (EEST) Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4501F680B20 for <ffmpeg-devel@ffmpeg.org>; Sun, 13 Apr 2025 14:16:05 +0300 (EEST) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4Zb7C60mM2z9spL for <ffmpeg-devel@ffmpeg.org>; Sun, 13 Apr 2025 13:16:02 +0200 (CEST) From: Gyan Doshi <ffmpeg@gyani.pro> To: ffmpeg-devel@ffmpeg.org Date: Sun, 13 Apr 2025 16:45:31 +0530 Message-ID: <20250413111545.4619-1-ffmpeg@gyani.pro> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4Zb7C60mM2z9spL Subject: [FFmpeg-devel] [PATCH 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/20250413111545.4619-1-ffmpeg@gyani.pro/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> Utility function to report seekability features for a given input. Useful for ffprobe and to extend seek possibilities in fftools. --- 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..e00f1ed0d9 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_NORMAL 0x01 ///< I/O is seekable like a local file +#define AVSEEKABLE_PROTOCOL 0x02 ///< I/O seek is through protocol request via avio_seek_time +#define AVSEEKABLE_DEMUXER 0x04 ///< demuxer has a seek function +#define AVSEEKABLE_PKTSCAN 0x08 ///< seek is performed by consuming and scanning packet timestamps +#define AVSEEKABLE_TIME 0x10 ///< seek target can be a timestamp +#define AVSEEKABLE_BYTE 0x20 ///< seek target can be in bytes +#define AVSEEKABLE_FRAME 0x40 ///< seek target can be a frame index +#define AVSEEKABLE_PTS 0x100 ///< seek target timestamp is expected to be PTS +#define AVSEEKABLE_FAST 0x200 ///< demuxer allows fast but inaccurate seeking +#define AVSEEKABLE_FWDONLY 0x400 ///< set seek will be equal or forward of specified seek point + +/** + * Report if and how a seek can be performed in a given input. + * + * @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..776a09744a 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 (!(s->pb && s->pb->seekable) || s->ctx_flags & AVFMTCTX_UNSEEKABLE) + return 0; + + if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) + ret |= AVSEEKABLE_NORMAL; + + if (s->pb->seekable & AVIO_SEEKABLE_TIME) + ret |= AVSEEKABLE_PROTOCOL; + + if (ffifmt(s->iformat)->read_seek || ffifmt(s->iformat)->read_seek2) + ret |= AVSEEKABLE_DEMUXER; + + if (ffifmt(s->iformat)->read_timestamp && !(s->iformat->flags & AVFMT_NOBINSEARCH)) + ret |= AVSEEKABLE_PKTSCAN; + + if (!(s->iformat->flags & AVFMT_NOTIMESTAMPS)) + ret |= AVSEEKABLE_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_BYTE; + + // TODO: no flag for frame seeking. Add flag and update this check + if (s->iformat->flags & 0) + ret |= AVSEEKABLE_FRAME; + + if (s->iformat->flags & AVFMT_SEEK_TO_PTS) + ret |= AVSEEKABLE_PTS; + + // TODO: flag exists but not added to the demuxers which support it + if (s->iformat->flags & AVFMT_FLAG_FAST_SEEK) + ret |= AVSEEKABLE_FAST; + + if (!(ret & AVSEEKABLE_DEMUXER) && ret & AVSEEKABLE_PKTSCAN) + ret |= AVSEEKABLE_FWDONLY; + + if ( !(ret & AVSEEKABLE_DEMUXER) && + !(ret & AVSEEKABLE_PKTSCAN) && + !(ret & AVSEEKABLE_BYTE) && + !(ret & AVSEEKABLE_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".