Keyboard shortcuts

Press ← or → to go to the previous or next page

Press S or / to search the docs

Press ? to show this help

Press Esc to hide this help

Advanced

Tune quality and latency

Quality and latency are set on both sides. The publisher decides which renditions exist and how they are encoded. Each player decides how much to buffer and which rendition to play.

In short

irl publish --renditions 360p,720p --keyframe-interval 1
irl watch <TICKET> --latency smooth
use std::time::Duration;
use iroh_live::media::{Delay, PlayerConfig, VideoEncoding, VideoRendition};
// The publisher offers two renditions.
let ladder = VideoEncoding::ladder([VideoRendition::p360(), VideoRendition::p720()]);
// The player holds each frame longer, for Wi-Fi or mobile links.
let config = PlayerConfig::default().with_latency(Delay {
    min: Some(Duration::from_millis(400)),
    max: Some(Duration::from_millis(600)),
});
drop((ladder, config));

Choose a starting point

UsePublisherPlayer
A call or a live demo--keyframe-interval 1--latency realtime
Watching on a good linkthe defaultsthe defaults
Viewers on Wi-Fi or mobile linksa ladder, such as --renditions 360p,720p--latency smooth
A slow device, such as a Pi Zeroone small rendition, such as --renditions 360pa hardware decoder

On the publisher

irl publish takes these flags, and the irl reference has the details:

  • --renditions <LIST> sets the ladder. A rendition is <height>p, <width>x<height> or <name>:<width>x<height>, with an optional @<fps>. A ladder lets each viewer drop to a smaller rendition when its link is slow, and an unwatched rendition costs nothing.
  • --bitrate <BITS_PER_SECOND> sets the bitrate of the largest rendition, and the smaller renditions get a share by pixel count. Without it, the encoder derives a bitrate from the size and frame rate.
  • --keyframe-interval <SECONDS> (default 2) sets how long a new viewer waits for its first picture, and how long a rendition switch takes. A shorter interval costs bitrate.
  • --codec h265 and --encoder pick the codec and backend. H.265 needs a hardware encoder.

From Rust, each VideoRendition carries moq-video’s encoder config:

use std::time::Duration;

use iroh_live::media::{Rate, VideoEncoding, VideoRendition, video};

fn ladder() -> VideoEncoding {
    let mut high = VideoRendition::p720();
    high.config.bitrate = Some(Rate::from_kbps(2_500));
    // A keyframe every second: faster joins and switches.
    high.config.join = Duration::from_secs(1);

    let mut low = VideoRendition::new("low");
    low.size = Some(video::Size::new(320, 180));
    low.config.join = Duration::from_secs(1);

    VideoEncoding::ladder([low, high])
}

VideoRendition::p360() is 640x360 at 500 kbit/s, and p720() is 1280x720 at 1.8 Mbit/s. A rendition’s frame rate follows the source unless rate is set. LocalBroadcast::set_spec takes a ladder in place of MediaEncoding::default().

Each audio group carries 100 ms by default. Shorter groups lose less audio when a packet is lost and let a viewer join a little closer to live. Longer groups mean fewer streams at a media relay. This sets one Opus frame per group:

use std::time::Duration;
use iroh_live::media::{AudioSource, LocalBroadcast, audio_encoding};
fn run(broadcast: &LocalBroadcast, microphone: AudioSource) -> Result<(), Box<dyn std::error::Error>> {
broadcast.set_audio(
    microphone,
    audio_encoding::voice().with_group_span(Duration::from_millis(20)),
)?;
Ok(())
}

On the player

The player holds each frame for a short time before it shows it, so it can absorb jitter and keep audio and video in step. --latency sets how long, and how far behind it may fall before it skips ahead to the live edge. realtime suits conversations, balanced is the default, and smooth suits Wi-Fi or mobile links. The irl reference lists the values.

The hold rises above the minimum when the catalog or the measured audio jitter asks for more, and returns to it on a clean link.

From Rust, PlayerConfig takes the same settings through its with_* builders, and setters change a running player without a gap:

use std::time::Duration;

use iroh_live::media::{Delay, Player, PlayerConfig, RenditionMode, video::decode};

fn smooth() -> PlayerConfig {
    PlayerConfig::default().with_latency(Delay {
        min: Some(Duration::from_millis(400)),
        max: Some(Duration::from_millis(600)),
    })
}

fn pin(player: &Player) {
    // Plays only `720p`, and falls back to automatic choice while it cannot.
    player.set_rendition(RenditionMode::pinned("720p"));
    player.set_decoder(decode::Backend::Software);
}
  • irl watch --rendition <NAME> and RenditionMode::Pinned play one rendition. RenditionMode::Off stops video while audio plays, for a tile off screen.
  • irl watch --decoder and PlayerConfig::decoder pick a decoder. A Raspberry Pi 4 needs this, see Publish from a Raspberry Pi.
  • PlayerConfig::adaptation holds the thresholds and timers of automatic choice. The player reference lists them.

See what happens

The stats overlay of irl watch shows the rendition, the frame rate, the decode time, the latency, and the link’s round trip and loss. To see why the player switched, turn on its logs, as RUST_LOG shows. A program reads the same values from the player:

  • Player::stats() returns the frame rate, decode time, latency and the link’s round trip and loss, cheap enough for every redraw. Its audio.rms is the level of the last 100 ms of audio, also in AudioMode::Decode, for a level meter or a speaking indicator.
  • Player::status() returns a watcher of the rendition on screen, the decoder, and the reason the last switch failed.
  • Player::video_timing(frame.timestamp) returns a picture’s FrameTiming: when its data arrived, when it left the decoder and when it was presented. decode_time() and queued() are the spans between them.
  • RemoteBroadcast::closed() resolves when the broadcast ends.

Where to go next