From: Zhao Zhili <quinkblack-at-foxmail.com@ffmpeg.org> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH v2 1/2] avformat: add avformat_query_seekable Date: Tue, 15 Apr 2025 19:49:47 +0800 Message-ID: <tencent_C7932C1C7B0B982627D0B7E6CCE7C1EA9D06@qq.com> (raw) In-Reply-To: <20250415104439.13431-1-ffmpeg@gyani.pro> > On Apr 15, 2025, at 18:39, Gyan Doshi <ffmpeg@gyani.pro> 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 > + > +/** > + * 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..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; dvdvideo is also seekable. How about check AVFMT_NOFILE flag and seek method in FFInputFormat. For rtsp, I think there is no way to query whether it’s really seeable or not until try to do that, at least no such information is exported for now. > + > + 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".
next prev parent reply other threads:[~2025-04-15 11:50 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-04-15 10:39 Gyan Doshi 2025-04-15 10:39 ` [FFmpeg-devel] [PATCH v2 2/2] ffprobe: show seekability details in format section Gyan Doshi 2025-04-15 11:49 ` Zhao Zhili [this message] 2025-04-16 5:07 ` [FFmpeg-devel] [PATCH v2 1/2] avformat: add avformat_query_seekable Andreas Rheinhardt 2025-04-16 12:25 ` Gyan Doshi 2025-04-21 18:29 ` Stefano Sabatini 2025-04-22 4:54 ` Gyan Doshi 2025-04-23 23:15 ` Stefano Sabatini
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=tencent_C7932C1C7B0B982627D0B7E6CCE7C1EA9D06@qq.com \ --to=quinkblack-at-foxmail.com@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git