Controlling the Playback Rate

Sequential playback relies on the interaction of four IDLffMJPEG2000 methods, described in Sequential Motion JPEG2000 Playback. When you call StartSequentialReading, a background processing thread is started, and the selected data is decompressed and added to the frame buffer. Within a timer event, you must call the GetSequentialData and ReleaseSequentialData methods as a pair. These methods work cooperatively to access and then to release the frame data so that there is room for the decompression of the next frame.

Tip
If playback is delayed because there are not frame buffer slots available, you can modify the size of the frame buffer using the FRAME_BUFFER_LENGTH property. See High Speed MJ2 Reading and Writing for details.

The timer mechanism can access the decompressed data from the frame buffer at intervals specified by a combination of the FRAME_PERIOD and TIMESCALE properties. The number of seconds allotted each frame is equal to the FRAME_PERIOD divided by the TIME_SCALE property (see the discussion under "FRAME_PERIOD" (IDL Reference Guide) for details). Access the required properties from an IDLffMJPEG2000 object (oMJ2) as follows:

oMJ2->GetProperty,N_FRAMES=nFrames, DIMENSIONS=dims, $ 
   FRAME_PERIOD=vFramePeriod, TIMESCALE=vTimeScale 
       
; Compute seconds per frame. 
vFrameRate = FLOAT(vFramePeriod)/vTimeScale 

In the previous line, the FLOAT function ensures the return of a floating point frame rate value and avoids errors caused by attempting to divide by zero. This frame rate value can then be passed to the timer mechanism to control playback rate. For an MJ2 file that has frames with varied FRAME_PERIOD property values, computing the frame rate for each frame and passing it to the timer mechanism will alter the playback speed. The following example creates an MJ2 file with varied frame period values and then uses these values to compute a value to be passed to a widget timer event, which alters the playback rate to reflect the frame period of each frame.

Example Code
This example mj2_timer_doc.pro, is located in the examples/doc/objects subdirectory of the IDL distribution. Run this example procedure by entering mj2_timer_doc at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT mj2_timer_doc.pro.

Timer Mechanisms

There are two primary options for timer mechanisms that can be used to control the playback rate of an MJ2 animation in an IDL application:

Table 6-3: Timer Mechanisms Options for MJ2 Playback

Option
Description

IDLitWindow

A number of IDLitWindow methods work in concert to control what happens during a timer event:

The sample MJ2 player, mj2_player.pro, located in the IDL_DIR\examples\mjpeg2000 directory uses an IDLitWindow timer mechanism. See Sample Motion JPEG2000 Player and Writer for more information.

Widget Timer

A timer event can be associated with a number of widgets although it is typically associated with one that has no events of its own such as a base or label. The WIDGET_CONTROL procedure associates a timer with a widget and sets the rate.

The mj2_timer_doc.pro example, located in the examples/doc/objects subdirectory of the IDL distribution, shows how to control playback rate with a widget timer. See Timer Events (User Interface Programming) for more information on these events.

Of the two options listed above, the IDLitWindow timer will more accurately reflect true frame rates. The widget timer will show rate changes, but may not have the same degree of accuracy as the IDLitWindow timer mechanism.