--- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -499,6 +499,9 @@ The user or muxer can override this through AVFormatContext.avoid_negative_ts */ +#define AVFMT_SEEK_NOSTREAMS 0x80000 /**< Stream index ignored by seek, + or some streams fail to seek + */ #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */ @@ -562,7 +565,8 @@ /** * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH, - * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS. + * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS, + * AVFMT_SEEK_NOSTREAMS */ int flags; --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -713,6 +713,7 @@ 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, --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -4794,6 +4794,7 @@ 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, @@ -4806,6 +4807,7 @@ 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), --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -605,6 +605,13 @@ 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)