High Speed MJ2 Reading and Writing
Animation playback or creation can be delayed due to the time required to decompress or compress frame data. The following sections describe ways to avoid such delays during file reading or writing.
High Speed Sequential Playback
If the desired playback speed exceeds the rate at which frames can be decompressed (as described in Sequential Motion JPEG2000 Playback), you can decompress all of the frames before starting the playback. To do so, you need to set the FRAME_BUFFER_LENGTH property to the total number of frames to be played back before calling IDLffMJPEG2000::StartSequentialReading.
When you call StartSequentialReading, the background processing thread will begin decompressing the frames and storing them in the frame buffer. Before calling the GetSequentialData/ReleaseSequentialData pair of methods, make sure that all frames have been read into the frame buffer. You can check this using one of the following:
- Check the STATE property—if frames are still being decompressed by the processing thread, the property returns 1 (running). When all frames have been decompressed, the background processing thread shuts down and the STATE property returns to 0 (idle).
- Check the FRAMES_IN_BUFFER property—if the number of frames in the buffer equals the FRAME_BUFFER_LENGTH property you set prior to starting the decompression, then all of the desired frames have been decompressed.
Note
This technique, decompressing all the desired frames prior to playback, can consume large amounts of memory depending on the number and size of the frames. Also, remember that the decompressed frames will remain in the frame buffer until you call the StopSequentialReading method.
High Speed MJ2 File Writing
In some situations, the desired write speed may exceed the rate at which frames can be compressed. When you call SetData, the data is added to the frame buffer where it is compressed by a background processing thread. If compression cannot keep up with the SetData calls, the frame buffer fills up and SetData must wait for an available frame buffer slot before it can return.
To avoid such a delay, you can make sure there is always a slot available for the SetData call by increasing the FRAME_BUFFER_LENGTH property value. This technique ensures there is no delay caused by file compression, but can consume large amounts of memory depending on the number and size of the frames.