1 diff --git a/libavformat/avformat.h b/libavformat/avformat.h
2 index e91e7f1d33..0f9b26a6d3 100644
3 --- a/libavformat/avformat.h
4 +++ b/libavformat/avformat.h
5 @@ -480,6 +480,9 @@ typedef struct AVProbeData {
6 The user or muxer can override this through
7 AVFormatContext.avoid_negative_ts
9 +#define AVFMT_SEEK_NOSTREAMS 0x80000 /**< Stream index ignored by seek,
10 + or some streams fail to seek
13 #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */
15 @@ -650,7 +653,8 @@ typedef struct AVInputFormat {
17 * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
18 * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
19 - * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
20 + * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS,
21 + * AVFMT_SEEK_NOSTREAMS
25 diff --git a/libavformat/dv.c b/libavformat/dv.c
26 index e99422d4b5..58ce1bbb5f 100644
27 --- a/libavformat/dv.c
28 +++ b/libavformat/dv.c
29 @@ -642,6 +642,7 @@ static int dv_probe(const AVProbeData *p)
30 AVInputFormat ff_dv_demuxer = {
32 .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
33 + .flags = AVFMT_SEEK_NOSTREAMS,
34 .priv_data_size = sizeof(RawDVContext),
35 .read_probe = dv_probe,
36 .read_header = dv_read_header,
37 diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
38 index cff7f0cb54..8b6d22aff2 100644
39 --- a/libavformat/matroskadec.c
40 +++ b/libavformat/matroskadec.c
41 @@ -4251,6 +4251,7 @@ static const AVClass webm_dash_class = {
42 AVInputFormat ff_matroska_demuxer = {
43 .name = "matroska,webm",
44 .long_name = NULL_IF_CONFIG_SMALL("Matroska / WebM"),
45 + .flags = AVFMT_SEEK_NOSTREAMS,
46 .extensions = "mkv,mk3d,mka,mks",
47 .priv_data_size = sizeof(MatroskaDemuxContext),
48 .read_probe = matroska_probe,
49 @@ -4264,6 +4265,7 @@ AVInputFormat ff_matroska_demuxer = {
50 AVInputFormat ff_webm_dash_manifest_demuxer = {
51 .name = "webm_dash_manifest",
52 .long_name = NULL_IF_CONFIG_SMALL("WebM DASH Manifest"),
53 + .flags = AVFMT_SEEK_NOSTREAMS,
54 .priv_data_size = sizeof(MatroskaDemuxContext),
55 .read_header = webm_dash_manifest_read_header,
56 .read_packet = webm_dash_manifest_read_packet,
57 diff --git a/libavformat/utils.c b/libavformat/utils.c
58 index 807d9f10cb..55a444e7b6 100644
59 --- a/libavformat/utils.c
60 +++ b/libavformat/utils.c
61 @@ -2486,6 +2486,13 @@ static int seek_frame_internal(AVFormatContext *s, int stream_index,
62 return seek_frame_byte(s, stream_index, timestamp, flags);
65 + if (stream_index != -1 && (s->iformat->flags & AVFMT_SEEK_NOSTREAMS)) {
66 + timestamp = av_rescale_q(timestamp,
67 + s->streams[stream_index]->time_base,
72 if (stream_index < 0) {
73 stream_index = av_find_default_stream_index(s);