These desktop examples show how to publish a local camera track and attach packet-trailer frame metadata from Python.
export LIVEKIT_URL=https://your-livekit-host
export LIVEKIT_API_KEY=your-api-key
export LIVEKIT_API_SECRET=your-api-secretRun these examples from the repository root with uv run --project examples/local_video.
LiveKit connection settings can also be passed with --url, --api-key, and --api-secret.
Publish a camera track:
uv run --project examples/local_video python examples/local_video/publisher.py \
--room-name demo \
--identity py-cam \
--camera-index 0Attach packet-trailer metadata:
uv run --project examples/local_video python examples/local_video/publisher.py \
--room-name demo \
--identity py-cam \
--attach-timestamp \
--attach-frame-idUseful flags:
--camera-index <n>: OpenCV camera index to publish.--width <px>/--height <px>: requested camera resolution.--fps <n>: requested publish frame rate.--attach-timestamp: attach wall-clock microseconds since Unix epoch asFrameMetadata.user_timestamp.--attach-frame-id: attach a monotonically increasingFrameMetadata.frame_id.
Render the first video track in the room:
uv run --project examples/local_video python examples/local_video/subscriber.py \
--room-name demo \
--identity py-viewerDisplay packet-trailer metadata over the video:
uv run --project examples/local_video python examples/local_video/subscriber.py \
--room-name demo \
--identity py-viewer \
--display-timestampUse --participant py-cam to only subscribe to video from a specific participant identity.
The subscriber keeps running across unpublish/republish cycles and will attach to the next matching video track.
Press q in the video window or Ctrl+C in the terminal to exit.