IP camera to Vindral Live
Pull an IP camera's stream over RTSP, encode it into 720p and 360p H.264 with a keyframe every second, convert its audio to AAC, and publish the ladder to your Vindral Live channel over MoQ. The Packager connects out to the camera and to Vindral, so the host needs no inbound ports.
Set the camera URL
Put the camera's RTSP URL in sources.protocol_options.url, with its user name and password
before the host: rtsp://user:[email protected]:554/stream1. Percent-encode reserved
characters in the password, such as @ as %40. The path differs between camera makers;
use the one for the camera's main stream. rtsps:// connects over TLS.
rtsp_transport = "tcp" keeps the media on the RTSP connection, which works through
firewalls and NAT. To use UDP, set rtsp_transport = "udp" and open the ports the camera
negotiates. Removing the option does not select UDP, because the Packager prefers TCP.
Set url and channel_id in the sink to your channel's MoQ publish URL and channel ID.
Run it
Save the download as config.toml and select your release image as in
Usage:
docker run --rm --name packager-camera \
-p 127.0.0.1:4040:4040 \
-v "$(pwd)/config.toml:/etc/packager/config.toml:ro" \
"${PACKAGER_IMAGE:?Set PACKAGER_IMAGE to your release image}" start
Check that camera, encode and vindral start with curl http://127.0.0.1:4040/api/sources
and the matching transcoders and sinks routes, then open the channel in a Vindral player.
Keyframes and passthrough
Many cameras send a keyframe only every few seconds. A player can start only at a keyframe,
so the example re-encodes the video with gop_size_ms = 1000. If the camera sends H.264
with a keyframe at least every second, you can pass its video through instead and save the
encoding: set passthrough = true on the video track and remove its renditions. Most
cameras set the keyframe interval in their web interface, often named I-frame interval or
GOP.
Timeouts
connect_timeout_ms and idle_timeout_ms are 10 seconds here, so a camera that stops
sending is reconnected after 10 seconds of silence. Raise both for a camera that pauses
its stream. The audio track is optional: a camera without audio also starts, and the
channel then has no audio. See RTSP for the socket
timeout and the other RTSP options.
Complete configuration
Download rtsp-camera-to-vindral.toml.
# Vindral Bridge Packager example
# Pull an IP camera over RTSP and publish a two-rung ladder to Vindral Live over MoQ.
version = "3"
# Pull the camera's main stream over TCP. Put the camera's user name and
# password in the URL and percent-encode reserved characters.
[[sources]]
id = "camera"
source_type = "rtsp"
connect_timeout_ms = 10_000
idle_timeout_ms = 10_000
demuxer_options = { rtsp_transport = "tcp" }
[sources.protocol_options]
url = "rtsp://YOUR_CAMERA_USER:YOUR_CAMERA_PASSWORD@YOUR_CAMERA_HOST:554/stream1"
# Re-encode the video so that every rendition has a keyframe each second.
# Cameras often send one only every few seconds, which delays playback start.
[[transcoders]]
id = "encode"
source_ids = ["camera"]
device = "cpu"
[[transcoders.tracks]]
id = "video"
type = "video"
track_selector = { type = "track-kind", kind = "video", is_required = true }
[[transcoders.tracks.renditions]]
id = "720p"
codec = "h264"
encoder_name = "libx264"
bit_rate = 2_500_000
gop_size_ms = 1000
max_b_frames = 0
format = "yuv420p"
size = { width = 1280, height = 720 }
[[transcoders.tracks.renditions]]
id = "360p"
codec = "h264"
encoder_name = "libx264"
bit_rate = 800_000
gop_size_ms = 1000
max_b_frames = 0
format = "yuv420p"
size = { width = 640, height = 360 }
# Cameras send G.711, AAC or no audio. The track is optional, so a camera
# without audio also starts.
[[transcoders.tracks]]
id = "audio"
type = "audio"
track_selector = { type = "track-kind", kind = "audio" }
[[transcoders.tracks.renditions]]
id = "aac"
codec = "aac"
sample_rate = 48_000
channels = 2
bit_rate = 128_000
# Publish to your Vindral Live channel over MoQ.
[[sinks]]
id = "vindral"
sink_type = "moq"
source_ids = ["encode"]
[sinks.protocol_options]
url = "https://lb.cdn.vindral.com/api/edge/moq-publish-url/YOUR_STREAM_KEY"
channel_id = "YOUR_CHANNEL_ID"
transport_mode = "lookup"