I have to read a large file containing many animation frames from CD/DVDrom and display it into screen as an animation. When reading from hard disk, the strategy of reading a frame into memory, processing, displaying and then reading next frame works good, but when I read from optical device, access time kills the animation.
I use C and winapi OpenFile/ReadFile methods.
How should I read contents of a file stored on an optical device to achieve realtime speed of animation ( I have seen a program that does it even in double speed, for sure it does not buffer the whole file before animation start ) ?
Two techniques:
LARGE buffer or cache, as in multiple MB. CD/DVD has reasonable sequential I/O but very slow seek/access speeds (as you have noted), so it’s fast to refill the buffer. You just need the buffer to be large enough that it covers a few seconds to allow the disk to spin up if needed, and seek if already spun up.
Multi-threading: keep one thread continuously reading and a separate thread decoding animation. Reader thread should block if it gets too far ahead of decoding.
These techniques apply to any programming language, and can be combined for best effect. One reading buffer and one decoded frame buffer protects you twice as well against the decoding time and the access time.
EDIT:
These are the techniques MPlayer uses. In addition, you should consider your encoding format if you can — different formats can trade off CPU time on decoding for less data to read from disk. A couple pieces of info for estimating how much video should be compressed.
Edit2: additional info