berarr
This commit is contained in:
@@ -40,15 +40,22 @@ def receive_and_record(stream_url, output_path):
|
||||
|
||||
|
||||
def receive_record_and_relay(stream_url, output_path, relay_url):
|
||||
"""Receive TCP stream, write to MKV, and relay to UDP loopback for live display.
|
||||
"""Receive TCP stream, write to fragmented MP4, and relay to UDP loopback.
|
||||
|
||||
Uses ffmpeg tee via merge_outputs: one ffmpeg process handles both outputs
|
||||
from the same decoded input, keeping them in sync with identical timestamps.
|
||||
Fragmented MP4 (frag_keyframe+empty_moov) avoids MKV tail corruption:
|
||||
each keyframe boundary closes a self-contained fragment, so the file is
|
||||
always valid up to the last complete fragment (~1 keyframe interval ≈ 2s).
|
||||
This allows the scene detector to use a 2s safety margin instead of 6s.
|
||||
|
||||
Uses ffmpeg tee via merge_outputs: one process, identical timestamps.
|
||||
"""
|
||||
stream = ffmpeg.input(stream_url, fflags="nobuffer", flags="low_delay")
|
||||
file_out = ffmpeg.output(
|
||||
stream, str(output_path),
|
||||
c="copy", f="matroska", flush_packets=1,
|
||||
c="copy", f="mp4",
|
||||
movflags="frag_keyframe+empty_moov+default_base_moof",
|
||||
flush_packets=1,
|
||||
**{"bsf:a": "aac_adtstoasc"},
|
||||
)
|
||||
relay_out = ffmpeg.output(
|
||||
stream, relay_url,
|
||||
|
||||
Reference in New Issue
Block a user