Skip to main content

Publish live and record the same encode

Encode once, then feed two sinks: MPEG-TS over SRT for live delivery and HLS on a persistent filesystem for recording. Use the shared setup and the download below. Both sinks read encode, so this does not duplicate the H.264/AAC encoders.

Connect the live receiver:

bash
ffplay 'srt://127.0.0.1:10000?mode=caller&latency=120000'

The recording appears at /publish-and-record/multivariant.m3u8 on the playback server. It targets ten-second segments and a 17280-segment playlist, a nominal 48-hour window. This is a rolling recording, not an unlimited archive or a single finalized MP4. Size storage for the aggregate encoded bitrate and desired retention, and keep the output mount persistent.

Check both sink states and outputs. Stop the SRT receiver and confirm the recording continues to receive new segments; reconnect and inspect the live feed. Each sink has its own task state, so check both. For S3 storage, replace only the recording destination using S3 recording and review playlist and object retention. If expanding to a rendition ladder, explicitly select the tracks wanted by each destination rather than assuming every destination accepts all renditions.

Complete configuration​

Download publish-and-record.toml.

toml
# Vindral Bridge Packager example
# Send one encode over SRT and record it as HLS on local disk.

version = "3"

[[sources]]
id = "input"
source_type = "file"
realtime_pacing = true
protocol_options = { url = "/media/camera-a.mp4" }

[[transcoders]]
id = "encode"
source_ids = ["input"]
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.tracks]]
id = "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 = "live"
sink_type = "srt"
source_ids = ["encode"]
wait_for_all_sources = true
protocol_options = { url = "srt://0.0.0.0:10000?mode=listener&latency=120000" }

[[sinks]]
id = "recording"
sink_type = "hls"
source_ids = ["encode"]
wait_for_all_sources = true
protocol_options = { url = "file:///output/publish-and-record/" }

[sinks.muxer_options]
target_segment_duration = { type = "u_int", value = 10_000 }
segment_list_size = { type = "u_int", value = 17_280 }