diff --git a/libavformat/avformat.h b/libavformat/avformat.h index ef2b08c4f3..1464ec220e 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -499,6 +499,8 @@ typedef struct AVProbeData { #define AVFMT_FIXED_FRAMESIZE 0x80000 /**< Format wants @ref AVCodecParameters.frame_size "fixed size audio frames." */ #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */ +#define AVFMT_SEEK_NOSTREAMS 0x200000 /**< Stream index ignored by seek, + or some streams fail to seek */ /** * @addtogroup lavf_encoding @@ -561,7 +563,7 @@ typedef struct AVInputFormat { * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_EXPERIMENTAL, * AVFMT_SHOW_IDS, AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, * AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH, AVFMT_NOGENSEARCH, - * AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS. + * AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS, AVFMT_SEEK_NOSTREAMS. */ int flags; diff --git a/libavformat/dv.c b/libavformat/dv.c index 84677284bd..2194b63893 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -716,6 +716,7 @@ static int dv_probe(const AVProbeData *p) const FFInputFormat ff_dv_demuxer = { .p.name = "dv", .p.long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"), + .p.flags = AVFMT_SEEK_NOSTREAMS, .p.extensions = "dv,dif", .priv_data_size = sizeof(RawDVContext), .read_probe = dv_probe, diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 18849af689..791a6fcd06 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -5024,6 +5024,7 @@ static const AVClass webm_dash_class = { const FFInputFormat ff_webm_dash_manifest_demuxer = { .p.name = "webm_dash_manifest", .p.long_name = NULL_IF_CONFIG_SMALL("WebM DASH Manifest"), + .p.flags = AVFMT_SEEK_NOSTREAMS, .p.priv_class = &webm_dash_class, .priv_data_size = sizeof(MatroskaDemuxContext), .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP, @@ -5036,6 +5037,7 @@ const FFInputFormat ff_webm_dash_manifest_demuxer = { const FFInputFormat ff_matroska_demuxer = { .p.name = "matroska,webm", .p.long_name = NULL_IF_CONFIG_SMALL("Matroska / WebM"), + .p.flags = AVFMT_SEEK_NOSTREAMS, .p.extensions = "mkv,mk3d,mka,mks,webm", .p.mime_type = "audio/webm,audio/x-matroska,video/webm,video/x-matroska", .priv_data_size = sizeof(MatroskaDemuxContext), diff --git a/libavformat/seek.c b/libavformat/seek.c index c0d94371e6..f287ecefc5 100644 --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -607,6 +607,13 @@ static int seek_frame_internal(AVFormatContext *s, int stream_index, return seek_frame_byte(s, stream_index, timestamp, flags); } + if (stream_index != -1 && (s->iformat->flags & AVFMT_SEEK_NOSTREAMS)) { + timestamp = av_rescale_q(timestamp, + s->streams[stream_index]->time_base, + AV_TIME_BASE_Q); + stream_index = -1; + } + if (stream_index < 0) { stream_index = av_find_default_stream_index(s); if (stream_index < 0)