Symphonia icon indicating copy to clipboard operation
Symphonia copied to clipboard

Optimize loading of MP4 on slow media sources

Open pdeljanov opened this issue 1 year ago • 10 comments

The initial scan of top-level atoms in IsoMp4Reader::try_new can be slow if the MediaSource is slow to read and seek. This is particularly bad with fragmented MP4s where there are many MOOF + MDAT pairs. This issue tracks possible optimizations:

  1. AtomIterator::next calls ignore_bytes to skip the body of an unread atom. It should be possible to replace ignore_bytes with an explicit seek if the reader is seekable. However, there will still be a lot of seek + small read operations as all the atoms are skipped over.
  2. If the MOOV and FTYP atoms were already encountered, it may be reasonable to terminate scanning of the top-level atoms at the first MOOF or MDAT atom. There'd need to be some documentation (i.e., standards, etc.) or proof that this is a good general optimization that won't break anything. However, this would still defer loading the fragments to the first seek.
  3. Use the SIDX atom (segment index) to avoid the scanning that would happen on a seek if the 2nd point was implemented.

This issue was promoted by the discussion in #153.

pdeljanov avatar Jan 20 '23 03:01 pdeljanov