Guides
Publish a camera, screen or file
Publish your camera, screen or a video file, and share the ticket so that others can watch.
In short
irl publish
use iroh_live::media::{LocalBroadcast, MediaEncoding, spec::MediaSpec};
use iroh_live::{Node, layout::LiveLayout};
async fn run(node: &Node, layout: &LiveLayout) -> Result<(), Box<dyn std::error::Error>> {
// Published while `broadcast` lives.
let broadcast: LocalBroadcast = layout.publish(node, "hello")?;
broadcast.set_spec(&MediaSpec::camera(), MediaEncoding::default()).await?;
println!("{}", layout.ticket(node.id(), "hello")?);
Ok(())
}
The Rust quickstart has the complete program.
Publish the camera
irl publish publishes the default camera and microphone, and prints a
ticket. Without a camera, publish a test pattern instead:
irl publish --test-source
In Rust, MediaSpec::camera() and MediaSpec::test() name the same
sources. MediaEncoding::default() encodes one rendition at the source’s
size.
Publish the screen
irl publish --video screen
use iroh_live::media::{LocalBroadcast, MediaEncoding, spec::MediaSpec};
async fn run(broadcast: &LocalBroadcast) -> Result<(), Box<dyn std::error::Error>> {
broadcast.set_spec(&MediaSpec::screen(), MediaEncoding::default()).await?;
Ok(())
}
On Wayland, the desktop portal asks which screen to share, and a Rust
program needs the pipewire feature for it. MediaSpec::screen() adds no
audio.
Publish a file
file: plays an MP4 file in real time, with its audio, and :loop repeats
it.
irl publish --video file:talk.mp4:loop
use iroh_live::media::{LocalBroadcast, MediaEncoding, spec::MediaSpec};
async fn run(broadcast: &LocalBroadcast) -> Result<(), Box<dyn std::error::Error>> {
let spec = MediaSpec::new("file:talk.mp4:loop".parse()?);
broadcast.set_spec(&spec, MediaEncoding::default()).await?;
Ok(())
}
The file’s H.264 and AAC go out as they are, in one rendition and at no CPU
cost. --reencode and MediaSpec::with_reencode(true) encode it like a
camera instead. Convert other codecs first, for example with
ffmpeg -i in.mp4 -c:v libx264 -c:a aac out.mp4. In Rust, files need the
file feature.
Turn the audio on or off
--audio picks the sound, and none turns it off. For audio alone, see
Stream audio.
irl publish --audio none
irl publish --video screen --audio file:music.mp3:loop
In Rust, with_audio sets the audio:
use iroh_live::media::{LocalBroadcast, MediaEncoding, spec::{AudioSourceSpec, MediaSpec}};
async fn run(broadcast: &LocalBroadcast) -> Result<(), Box<dyn std::error::Error>> {
let spec = MediaSpec::camera().with_audio(AudioSourceSpec::None);
broadcast.set_spec(&spec, MediaEncoding::default()).await?;
Ok(())
}
Choose a device
irl devices lists the devices and their ids:
irl devices
irl publish --video cam:<id> --audio mic:<id>
Rust programs parse the same specifiers:
use iroh_live::media::{LocalBroadcast, MediaEncoding, spec::MediaSpec};
async fn run(broadcast: &LocalBroadcast) -> Result<(), Box<dyn std::error::Error>> {
let spec = MediaSpec::new("cam:1".parse()?).with_audio("mic".parse()?);
broadcast.set_spec(&spec, MediaEncoding::default()).await?;
Ok(())
}
The irl reference lists them all.
Going further
- Tune quality and latency: renditions, bitrate and keyframes.
- Open and switch sources: device configs, switching while live, your own frames, file passthrough.
- Publish through a media relay, for browsers and large audiences.
- Publish from a Raspberry Pi.
- Publishing internals.