emit_block(), Reactor buffers your frames and delivers them
smoothly to the client, spacing them evenly based on your model’s actual generation speed. You do
not need to worry about timing or frame pacing. Just generate frames and emit them.
Using emit_block()
Call get_ctx().emit_block() with your frame tensor:
Required Format
Your frames must be a NumPy array with the following specification:| Property | Requirement |
|---|---|
| Shape | (N, H, W, 3) for N frames, or (H, W, 3) for a single frame |
| Dtype | np.uint8 |
| Range | 0 to 255 |
| Channels | RGB (not BGR) |
N is the number of frames in the block, H is height, W is width, and 3 is the RGB
channel dimension.
Converting from PyTorch
Most pipelines output tensors in(B, C, T, H, W) or (B, T, C, H, W) format with float values in
[-1, 1] or [0, 1]. Here is how to convert:
[0, 1] range:
Special Cases
Emitting Black Frames
PassNone to emit a black frame:
Stopping Emission
If you stop callingemit_block(), Reactor holds the last emitted frame on screen. This maintains
visual continuity if your model temporarily pauses, though at the cost of a frozen image.
Frame Monitoring
Reactor tracks your emission rate to adapt playback speed. If your pipeline stops emitting frames (for example, while waiting for user input), Reactor interprets this as slow performance and lowers the target framerate. To prevent this, usedisable_monitoring() when you intentionally pause generation, and
enable_monitoring() when you resume:
disable_monitoring(), Reactor would think your model is struggling and degrade the stream quality.
Sending Messages
Beyond video frames, you can send JSON messages to the frontend usingget_ctx().send(). This is
useful for progress updates, state synchronization, or custom events:
Block Size and Reactivity
Each block is generated from a single set of conditions. If a user changes their input mid-block, that change will not affect frames already being generated. It will only apply to the next block. This means smaller block sizes provide more reactivity. A block size of 1 frame means every frame can respond to the latest input. A block size of 12 frames means users wait up to 12 frames before seeing their input reflected. Choose your block size based on your model’s architecture and the level of interactivity you need. Some models only support specific block sizes based on their temporal attention patterns.Now that you understand how to emit frames, the final step is learning how to clean up session state so your model can serve multiple users efficiently.
Model Cleanup
Learn how to prepare your model for the next user.
