kinda working

This commit is contained in:
Micha Albert 2024-09-10 13:32:34 -04:00
parent e468e0b9ab
commit 35c2a98835
No known key found for this signature in database
GPG key ID: 33149159A417BBCE
6 changed files with 36 additions and 17 deletions

View file

@ -2,9 +2,9 @@ import subprocess
import time
import requests
time.sleep(5)
time.sleep(10)
active_stream = requests.get("http://backend:8000/api/v1/active_stream").text
active_stream = requests.get("http://backend:8000/api/v1/active_stream").text.replace('"', '')
print(active_stream)
old_active_stream = active_stream
@ -12,19 +12,18 @@ old_active_stream = active_stream
proc = None
if active_stream != "":
proc = subprocess.Popen(["/bin/ffmpeg", "-re", "-i", f"rtmp://mediamtx:1935/{active_stream}", "-c:a copy", "rtmp://live-stream:1936/active-input"])
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(["/bin/ffmpeg", "-i", "anullsrc", "-c:a copy", "rtmp://live-stream:1936/active-input"])
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
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(["/bin/ffmpeg", "-re", "-i", f"rtmp://mediamtx:1935/{active_stream}", "-c:a copy", "rtmp://live-stream:1936/active-input"])
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(["/bin/ffmpeg", "-i", "anullsrc", "-c:a copy", "rtmp://live-stream:1936/active-input"])
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