Skip to content

Encode video on demand (Rust) #1170

@kixelated

Description

@kixelated

Problem

The drone demo (and any real-time rendering publisher) encodes every frame at 30fps regardless of whether anyone is watching. This wastes CPU on the H.264 encoder when there are no subscribers.

Proposal

Add an API to detect when a track has active subscribers, so the publisher can skip encoding when nobody is watching. Something like the inverse of unused().await:

// Wait until at least one subscriber exists
track.demanded().await;

// Or check non-blocking
if track.has_subscribers() {
    // encode and publish
}

This would allow the game loop to still run (physics/state updates) but skip the expensive RGBA→YUV→H.264 encode pipeline when no viewer is connected.

Context

In dev/drone/src/video.rs, the encoder thread processes every frame unconditionally. With multiple drone instances and dual rendition (720p + 360p), this is 2x H.264 encodes per drone at 30fps even when idle.

Scope

Rust only — this would be an addition to moq_lite::TrackProducer or the moq_mux catalog/import layer.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    rustPull requests that update Rust code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions