Expand description
Bytes shared between readers without copying: a buffer in memory, or a file mapped into it.
A 4K or 8K film runs to gigabytes. Reading one whole into a Vec before
the first picture means waiting for all of it and holding all of it.
Mapped, the operating system pages in what the demuxer and decoder touch,
as they touch it, and drops it again under memory pressure; the first
picture is ready after reading the index and one sample. Everything here
that takes a whole file (VideoReader,
demux, the audio decoders) takes a slice, so a
mapping slots in anywhere a Vec did.
use threers_codec::bytes::Bytes;
let file = Bytes::map("film.mp4").unwrap();
println!("{} bytes, mapped: {}", file.len(), file.is_mapped());