seek

expect fun seek(micros: Long, direction: SeekDirection = SeekDirection.Backward, notEarlierThan: Long? = null)

Moves the demuxer cursor without flushing decoders or clearing caller-owned queues. The caller must discard the old packet/frame generation and flush every decoder itself.

A backward seek on an indexless container may otherwise land arbitrarily early, so notEarlierThan can bound that search.

A backward seek lands on the last keyframe that shows at or before micros, and no earlier than notEarlierThan, in the source's first video stream that is not a cover picture, when this reader selects it; the first packet of that stream it reads is that keyframe. FFmpeg finds a keyframe by when it decodes, which with B-frames is earlier than when it shows, so the seek reads on to the keyframe it landed on and aims earlier when that one shows too late, and read then hands out what the seek read before it reads anything new. Keyframes more than 32 MB of input apart are not checked. The other selected streams start where the container puts them beside that keyframe. A SeekDirection.Forward or SeekDirection.Any seek is FFmpeg's own and is not checked. Check the first decoded timestamp when the exact landing matters.

Parameters

micros

target on the content-relative timeline

notEarlierThan

optional lower bound for a backward seek

actual fun seek(micros: Long, direction: SeekDirection, notEarlierThan: Long?)

Moves the demuxer cursor without flushing decoders or clearing caller-owned queues. The caller must discard the old packet/frame generation and flush every decoder itself.

A backward seek on an indexless container may otherwise land arbitrarily early, so notEarlierThan can bound that search.

A backward seek lands on the last keyframe that shows at or before micros, and no earlier than notEarlierThan, in the source's first video stream that is not a cover picture, when this reader selects it; the first packet of that stream it reads is that keyframe. FFmpeg finds a keyframe by when it decodes, which with B-frames is earlier than when it shows, so the seek reads on to the keyframe it landed on and aims earlier when that one shows too late, and read then hands out what the seek read before it reads anything new. Keyframes more than 32 MB of input apart are not checked. The other selected streams start where the container puts them beside that keyframe. A SeekDirection.Forward or SeekDirection.Any seek is FFmpeg's own and is not checked. Check the first decoded timestamp when the exact landing matters.

Parameters

micros

target on the content-relative timeline

notEarlierThan

optional lower bound for a backward seek

actual fun seek(micros: Long, direction: SeekDirection, notEarlierThan: Long?)

Moves the read cursor.

This moves the cursor and nothing else. It does not flush the decoders and it does not clear anything the caller has queued, because only the caller knows which generation those belong to. Flushing here would let a packet read before the seek reach a decoder that was just reset.

The window matters. SeekDirection.Backward with an unbounded lower limit lets libavformat land arbitrarily early on a container without an index, and MPEG-TS resolves a seek by searching byte positions, so it can also land after the target. Passing notEarlierThan bounds the first case; the caller detects the second from the first decoded frame and retries.

Parameters

micros

where to seek to, on the content-relative timeline the rest of the API uses.

notEarlierThan

a lower bound on where the seek may land. Null means no bound.

actual fun seek(micros: Long, direction: SeekDirection, notEarlierThan: Long?)

Moves the demuxer cursor without flushing decoders or clearing caller-owned queues. The caller must discard the old packet/frame generation and flush every decoder itself.

A backward seek on an indexless container may otherwise land arbitrarily early, so notEarlierThan can bound that search.

A backward seek lands on the last keyframe that shows at or before micros, and no earlier than notEarlierThan, in the source's first video stream that is not a cover picture, when this reader selects it; the first packet of that stream it reads is that keyframe. FFmpeg finds a keyframe by when it decodes, which with B-frames is earlier than when it shows, so the seek reads on to the keyframe it landed on and aims earlier when that one shows too late, and read then hands out what the seek read before it reads anything new. Keyframes more than 32 MB of input apart are not checked. The other selected streams start where the container puts them beside that keyframe. A SeekDirection.Forward or SeekDirection.Any seek is FFmpeg's own and is not checked. Check the first decoded timestamp when the exact landing matters.

Parameters

micros

target on the content-relative timeline

notEarlierThan

optional lower bound for a backward seek

actual fun seek(micros: Long, direction: SeekDirection, notEarlierThan: Long?)

Moves the demuxer cursor without flushing decoders or clearing caller-owned queues. The caller must discard the old packet/frame generation and flush every decoder itself.

A backward seek on an indexless container may otherwise land arbitrarily early, so notEarlierThan can bound that search.

A backward seek lands on the last keyframe that shows at or before micros, and no earlier than notEarlierThan, in the source's first video stream that is not a cover picture, when this reader selects it; the first packet of that stream it reads is that keyframe. FFmpeg finds a keyframe by when it decodes, which with B-frames is earlier than when it shows, so the seek reads on to the keyframe it landed on and aims earlier when that one shows too late, and read then hands out what the seek read before it reads anything new. Keyframes more than 32 MB of input apart are not checked. The other selected streams start where the container puts them beside that keyframe. A SeekDirection.Forward or SeekDirection.Any seek is FFmpeg's own and is not checked. Check the first decoded timestamp when the exact landing matters.

Parameters

micros

target on the content-relative timeline

notEarlierThan

optional lower bound for a backward seek