diff --git a/active-stream-proxy/main.py b/active-stream-proxy/main.py index aa909ec..c24f4b9 100644 --- a/active-stream-proxy/main.py +++ b/active-stream-proxy/main.py @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 12132ed..8b1191f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,12 +8,16 @@ services: - "1935:1935" - "9997:9997" web-frontend: + ports: + - "4173:4173" build: context: ./tiling-frontend dockerfile: Dockerfile volumes: - tiling_frontend_build:/usr/src/app/dist live-stream: + ports: + - "1936:1936" depends_on: active_stream_proxy: condition: service_started @@ -22,8 +26,7 @@ services: dockerfile: Dockerfile volumes: - tiling_frontend_build:/html - environment: - YT_STREAM_KEY: ${YT_STREAM_KEY} + env_file: .stream.env backend: env_file: .backend.env ports: diff --git a/live-stream/Dockerfile b/live-stream/Dockerfile index 0ce2d99..16b42f4 100644 --- a/live-stream/Dockerfile +++ b/live-stream/Dockerfile @@ -1,10 +1,16 @@ -FROM alpine:3.20 +FROM ubuntu:22.04 -RUN apk add --no-cache gstreamer gstreamer-tools gst-plugins-bad +ARG DEBIAN_FRONTEND=noninteractive -RUN apk add --no-cache ffmpeg +RUN apt update -RUN apk add --no-cache bash libwpe libwpe-dev +RUN apt install -y ffmpeg + +RUN apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-wpe + +RUN rm -rf /var/lib/apt/lists/* + +RUN apt clean COPY run.sh / diff --git a/live-stream/run.sh b/live-stream/run.sh index a0f7b8f..a7f9df5 100755 --- a/live-stream/run.sh +++ b/live-stream/run.sh @@ -1,8 +1,14 @@ #!/bin/bash -gst-launch-1.0 -e wpesrc location="https://en.wikipedia.org/wiki/Main_Page" \ +sleep 1 + +LIBGL_ALWAYS_SOFTWARE=true gst-launch-1.0 -e wpesrc location="http://web-frontend:4173/" \ + ! queue \ ! videoconvert ! videoscale ! videorate \ - ! "video/x-raw, format=BGRA, width=854, height=480, framerate=30/1" \ + ! "video/x-raw, format=BGRA, width=1920, height=1080, framerate=30/1" \ ! videoconvert \ ! x264enc speed-preset=1 \ - ! 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 + ! filesink location=/dev/stdout | ffmpeg -re -y -i - -listen 1 -i rtmp://0.0.0.0:1936/active-input -c:v copy -c:a libmp3lame -map 0:v:0 -map 1:a:0 -g 90 -framerate 30 -movflags faststart -bufsize 14000k -f flv rtmp://x.rtmp.youtube.com/live2/$YT_STREAM_KEY + + + diff --git a/mediamtx/mediamtx.yml b/mediamtx/mediamtx.yml index 6ba7b24..db3e986 100644 --- a/mediamtx/mediamtx.yml +++ b/mediamtx/mediamtx.yml @@ -20,3 +20,6 @@ authInternalUsers: ips: [] permissions: - action: api + - action: publish + - action: playback + - action: read diff --git a/tiling-frontend/Dockerfile b/tiling-frontend/Dockerfile index 969c7b6..e766ca8 100644 --- a/tiling-frontend/Dockerfile +++ b/tiling-frontend/Dockerfile @@ -14,3 +14,5 @@ FROM base AS release COPY --from=install /temp/dev/node_modules node_modules COPY . . RUN bun --bun run build +ENTRYPOINT ["bun", "--bun", "run", "preview", "--host"] +