From 5954c55413815f146013f3f22ad40916680f9f09 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 11 Jul 2021 16:01:06 +1000 Subject: [PATCH] stream_in_sync.py: ideas for streaming live two side-by-side syncronized streams --- stream_in_sync.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 stream_in_sync.py diff --git a/stream_in_sync.py b/stream_in_sync.py new file mode 100644 index 0000000..b5ad316 --- /dev/null +++ b/stream_in_sync.py @@ -0,0 +1,33 @@ + +from datetime import datetime, timedelta + + +def pipe_stream(racer, start): + """Returns a pipe streaming racer's video, starting from given start timestamp.""" + # TODO this is basically a specialized version of fast_cut_segments with no end point + # that polls for new segments. + + +def sync_stream(racer, start): + """Returns a pipe streaming racer's video, starting from the point they started. + Starts searching from given start timestamp. + Blocks until start found. + """ + # TODO send pipe_stream(racer, start) to ffmpeg until blackdetect found, + # then return pipe_stream(racer, start + blackdetect) + + +def main(racer1, racer2, start=0): + """ + start: + 0: now + < 0: seconds ago + > 0: unix timestamp + """ + if start > 0: + start = datetime.utcfromtimestamp(start) + else: + start = datetime.utcnow() + timedelta(seconds=start) + + stream1, stream2 = gevent.Pool.Group().map(lambda r: sync_stream(r, start), [racer1, racer2]) + # TODO multiplex stream1, stream2 and timer (using drawtext) into one video