mirror of
https://github.com/MichaByte/OnBoard-Live.git
synced 2025-12-06 04:03:42 -05:00
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
import subprocess
|
|
import time
|
|
import requests
|
|
|
|
time.sleep(8)
|
|
|
|
active_stream = requests.get("http://backend:8000/api/v1/active_stream").text.replace('"', '')
|
|
print(active_stream)
|
|
|
|
old_active_stream = active_stream
|
|
|
|
proc = None
|
|
|
|
if active_stream != "":
|
|
proc = subprocess.Popen(["ffmpeg", "-re", "-i", f"rtmp://mediamtx:1935/{active_stream}", "-c:a", "libmp3lame", "-f", "flv", "rtmp://host.containers.internal:1936/active-input"])
|
|
else:
|
|
proc = subprocess.Popen(["ffmpeg", "-f", "lavfi", "-i", "anullsrc", "-c:a", "libmp3lame", "-f", "flv", "rtmp://host.containers.internal:1936/active-input"])
|
|
|
|
while True:
|
|
time.sleep(3)
|
|
active_stream = requests.get("http://backend:8000/api/v1/active_stream").text.replace('""', '')
|
|
if old_active_stream is not active_stream:
|
|
if proc:
|
|
proc.terminate()
|
|
if active_stream != "":
|
|
proc = subprocess.Popen(["ffmpeg", "-re", "-i", f"rtmp://mediamtx:1935/{active_stream}", "-c:a", "libmp3lame", "-f", "flv", "rtmp://host.containers.internal:1936/active-input"])
|
|
else:
|
|
proc = subprocess.Popen(["ffmpeg", "-f", "lavfi", "-i", "anullsrc", "-c:a", "libmp3lame", "-f", "flv", "rtmp://host.containers.internal:1936/active-input"])
|
|
old_active_stream = active_stream
|