LocalVideoTrack represents a local video track that captures video from device cameras or other video sources like screen sharing. It manages video capture through a VideoCapturer and provides methods for muting/unmuting and video processing.
Creating a Track
Create a local video track using static factory methods for different video sources:Camera Track
createCameraTrack
Static factory method to create a camera video track.The name of the video track. Defaults to
"camera".Camera capture configuration options. If
nil, default options are used.See CameraCaptureOptions for settings:position: Camera position (.frontor.back)preferredFormat: Preferred capture formatdimensions: Capture dimensionsfps: Target frames per second
Whether to collect and report statistics for this track
Optional video processor for effects like background blur, virtual backgrounds, etc.
LocalVideoTrack instance configured for camera capture.
Properties
capturer
VideoCapturer instance managing video capture for this track. This could be a CameraCapturer, ScreenCapturer, or custom capturer implementation.
processor
publishOptions
nil if not yet published.
publishState
.unpublished: Track has not been published.published: Track is currently published
Inherited Properties
From the baseTrack class:
name: The track namesid: The server-assigned track ID (available after publishing)kind: Always.videofor video trackssource: Track source (.camera,.screenShareVideo, etc.)isMuted: Whether the track is currently mutedtrackState: Current state (.startedor.stopped)dimensions: Current video dimensionsvideoFrame: The last captured video framestatistics: Real-time statistics ifreportStatisticsis enabled
Methods
mute()
Mutes the video track by stopping video capture.unmute()
Unmutes the video track by resuming video capture.add(videoRenderer:)
Adds aVideoRenderer to receive video frames from this track.
An object conforming to the
VideoRenderer protocol that will receive video framesVideoView for display, but can also be custom renderers for processing or recording.
Example:
remove(videoRenderer:)
Removes a previously addedVideoRenderer.
The renderer to remove
clone()
Creates a clone of this video track sharing the sameVideoCapturer.
LocalVideoTrack instance sharing the same capturer.
Example:
start()
Starts video capture. Inherited fromTrack.
VideoCapturer and is typically called automatically when publishing.
stop()
Stops video capture. Inherited fromTrack.
set(reportStatistics:)
Enables or disables statistics reporting at runtime.true to enable statistics collection, false to disableTrack Lifecycle
- Creation: Create track using
createCameraTrack()or other factory methods - Publishing: Publish track via
LocalParticipant.publish(track:options:) - Capturing: Track automatically starts capturing when published
- Muting/Unmuting: Use
mute()andunmute()to control video transmission - Processing: Optionally set a
processorfor video effects - Unpublishing: Unpublish via
LocalParticipant.unpublish(track:) - Cleanup: Track stops capturing when deallocated
Camera Control
For camera tracks, access camera-specific controls through thecapturer:
Video Processing
Add video processing by setting theprocessor property:
Thread Safety
LocalVideoTrack is @unchecked Sendable and thread-safe. All public methods can be called from any thread.
Example Usage
See Also
- RemoteVideoTrack - Receiving remote video
- CameraCapturer - Camera capture management
- VideoCapturer - Base capturer class
- VideoProcessor - Video processing interface
- Publishing - Publishing tracks to the room