From e468e0b9ab9684579591f646d3cb083c7b2c48db Mon Sep 17 00:00:00 2001 From: Micha Albert Date: Tue, 10 Sep 2024 07:39:22 -0400 Subject: [PATCH] start fixing stream stuff --- active-stream-proxy/main.py | 10 +++++++--- live-stream/Dockerfile | 8 ++++++-- live-stream/run.sh | 4 +++- 3 files changed, 16 insertions(+), 6 deletions(-) mode change 100644 => 100755 live-stream/run.sh diff --git a/active-stream-proxy/main.py b/active-stream-proxy/main.py index 10d3453..aa909ec 100644 --- a/active-stream-proxy/main.py +++ b/active-stream-proxy/main.py @@ -12,7 +12,9 @@ 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://host.containers.internal:1936/active-input"]) + proc = subprocess.Popen(["/bin/ffmpeg", "-re", "-i", f"rtmp://mediamtx:1935/{active_stream}", "-c:a copy", "rtmp://live-stream:1936/active-input"]) +else: + proc = subprocess.Popen(["/bin/ffmpeg", "-i", "anullsrc", "-c:a copy", "rtmp://live-stream:1936/active-input"]) while True: @@ -21,6 +23,8 @@ while True: if old_active_stream is not active_stream: if proc: proc.terminate() - print("e") - proc = subprocess.Popen(["/bin/ffmpeg", "-re", "-i", f"rtmp://mediamtx:1935/{active_stream}", "-c:a copy", "rtmp://host.containers.internal:1936/active-input"]) + 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"]) + else: + proc = subprocess.Popen(["/bin/ffmpeg", "-i", "anullsrc", "-c:a copy", "rtmp://live-stream:1936/active-input"]) old_active_stream = active_stream diff --git a/live-stream/Dockerfile b/live-stream/Dockerfile index 60bc333..0ce2d99 100644 --- a/live-stream/Dockerfile +++ b/live-stream/Dockerfile @@ -1,7 +1,11 @@ FROM alpine:3.20 -RUN apk add --no-cache gstreamer gst-plugins-bad +RUN apk add --no-cache gstreamer gstreamer-tools gst-plugins-bad RUN apk add --no-cache ffmpeg -ENTRYPOINT [""] +RUN apk add --no-cache bash libwpe libwpe-dev + +COPY run.sh / + +ENTRYPOINT ["/run.sh"] diff --git a/live-stream/run.sh b/live-stream/run.sh old mode 100644 new mode 100755 index 35dc0f1..a0f7b8f --- a/live-stream/run.sh +++ b/live-stream/run.sh @@ -1,6 +1,8 @@ +#!/bin/bash + gst-launch-1.0 -e wpesrc location="https://en.wikipedia.org/wiki/Main_Page" \ ! videoconvert ! videoscale ! videorate \ ! "video/x-raw, format=BGRA, width=854, height=480, framerate=30/1" \ ! videoconvert \ ! x264enc speed-preset=1 \ - ! filesink location=/dev/stdout | ffmpeg -re -y -i - -listen 1 -i rtmp://127.0.0.1:1936/active-input -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 -t 10 -f flv rtmp://x.rtmp.youtube.com/live2/no-way-am-i-doing-that-again + ! filesink location=/dev/stdout | ffmpeg -re -y -i - -listen 1 -i rtmp://0.0.0.0:1936/active-input -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 -t 10 -f flv rtmp://x.rtmp.youtube.com/live2/no-way-am-i-doing-that-again