Skip to main content

Overview

Backpressure occurs when frames are enqueued faster than they can be encoded, leading to:
  • Memory buildup (queue grows unbounded)
  • Out of memory errors (heap exhausted)
  • Slow performance (system thrashing)
Proper backpressure management ensures stable, efficient encoding.

The Problem

The Solution

Monitoring Queue Size

The encodeQueueSize property shows pending frames:

Simple Throttling

Wait when queue exceeds threshold:

Event-Based Backpressure

Use dequeue events for precise control:

Adaptive Throttling

Adjust queue size based on system load:

Batch Processing

Process frames in manageable batches:

Memory Monitoring

Track memory usage during encoding:

Best Practices

Closing frames late increases memory pressure.
For thousands of frames, process in batches of 100-1000.

Next Steps

Worker Threads

Parallel encoding

Hardware Acceleration

Faster encoding

Troubleshooting

Memory leak solutions

API Reference

Encoder documentation