Switch cameras through the API and keep program audio
Switch the program picture between two live video inputs without changing the audio input, audio encoder, or sink. Start with the shared fixtures and setup and the complete download below. Connect the SRT receiver. The initial picture is camera A (red) with the separate 220 Hz program audio. Camera A's 440 Hz and camera B's 880 Hz tracks are deliberately excluded.
Cut to camera B
Connect the receiver and wait for both decoders, switcher, both output
transcoders and the sink to start.
Then send:
curl --fail-with-body -X POST \
http://127.0.0.1:4040/api/compositors/switcher/camera-switch/command \
-H 'Content-Type: application/json' -d '{"x":"0","y":"0"}'
The picture becomes blue. The 220 Hz tone must continue unchanged. Return to A:
curl --fail-with-body -X POST \
http://127.0.0.1:4040/api/compositors/switcher/camera-switch/command \
-H 'Content-Type: application/json' -d '{"x":"W","y":"0"}'
Allow for SRT and player buffering. Inspect actual frames and listen across both cuts; HTTP 200 acknowledges command dispatch, not media application.
How the switch works
This uses the supported CPU overlay filter as a full-frame cut. A is the base;
B is an opaque overlay with the same 640×360 size. With x = "W", B sits outside
the base frame, revealing A. With x = "0", B covers A. W is the base width.
Both video branches remain decoded and active throughout the switch.
The API call changes only the overlay coordinates. The audio-output transcoder
continues reading the fixed program-audio source, and the sink keeps both output
tasks. To use a camera's embedded audio as the fixed program audio, point only
audio-output.source_ids at that camera and keep its audio selector; camera cuts
still target only the compositor.
For SDI or SRT cameras, replace the input source definitions, keep video-only
selectors, and normalize both inputs to the same dimensions and frame rate.
Check lip sync against the independent audio feed using the
synchronization guide. Both cameras are required and
must remain live; this is not a source-loss failover mechanism. The filter command
is transient, so graph recreation returns to camera A as configured. This API
technique uses CPU overlay; overlay_cuda does not expose these runtime commands.
Complete configuration
Download camera-switching.toml.
# Vindral Bridge Packager example
# Switch between two cameras through the API, with separate program audio, sent over SRT.
version = "3"
[api]
bind = "0.0.0.0:4040"
[[sources]]
id = "camera-a"
source_type = "file"
realtime_pacing = true
protocol_options = { url = "/media/camera-a.mp4" }
[[transcoders]]
id = "decode-a"
source_ids = ["camera-a"]
device = "cpu"
[[transcoders.tracks]]
id = "a-video"
type = "video"
track_selector = { type = "track-kind", kind = "video", is_required = true }
[[transcoders.tracks.renditions]]
id = "a-raw"
codec = "wrapped_avframe"
format = "yuv420p"
size = { width = 640, height = 360 }
[[sources]]
id = "camera-b"
source_type = "file"
realtime_pacing = true
protocol_options = { url = "/media/camera-b.mp4" }
[[transcoders]]
id = "decode-b"
source_ids = ["camera-b"]
device = "cpu"
[[transcoders.tracks]]
id = "b-video"
type = "video"
track_selector = { type = "track-kind", kind = "video", is_required = true }
[[transcoders.tracks.renditions]]
id = "b-raw"
codec = "wrapped_avframe"
format = "yuv420p"
size = { width = 640, height = 360 }
[[sources]]
id = "program-audio"
source_type = "file"
realtime_pacing = true
protocol_options = { url = "/media/program-audio.m4a" }
[[compositors]]
id = "switcher"
[[compositors.video.sources]]
id = "camera-a-frame"
source_id = "decode-a"
track_selector = { type = "track-kind", kind = "video", is_required = true }
[[compositors.video.sources]]
id = "camera-b-frame"
source_id = "decode-b"
track_selector = { type = "track-kind", kind = "video", is_required = true }
[[compositors.video.nodes]]
id = "camera-switch"
type = "overlay"
source_ids = ["camera-a-frame", "camera-b-frame"]
x = "W"
y = "0"
format = "auto"
output_format = "yuv420p"
[[transcoders]]
id = "video-output"
source_ids = ["switcher"]
device = "cpu"
[[transcoders.tracks]]
id = "video"
type = "video"
track_selector = { type = "track-kind", kind = "video", is_required = true }
[[transcoders.tracks.renditions]]
id = "video-output"
codec = "h264"
encoder_name = "libx264"
bit_rate = 1_000_000
gop_size_ms = 1000
max_b_frames = 0
format = "yuv420p"
size = { width = 640, height = 360 }
[[transcoders]]
id = "audio-output"
source_ids = ["program-audio"]
device = "cpu"
[[transcoders.tracks]]
id = "fixed-audio"
type = "audio"
track_selector = { type = "track-kind", kind = "audio", is_required = true }
[[transcoders.tracks.renditions]]
id = "audio-output"
codec = "aac"
sample_rate = 48_000
channels = 2
bit_rate = 128_000
[[sinks]]
id = "srt"
sink_type = "srt"
source_ids = ["video-output", "audio-output"]
wait_for_all_sources = true
protocol_options = { url = "srt://0.0.0.0:10000?mode=listener&latency=120000" }