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 time
import requests 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) print(active_stream)
old_active_stream = active_stream old_active_stream = active_stream
@ -12,19 +12,18 @@ old_active_stream = active_stream
proc = None proc = None
if active_stream != "": 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: 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: while True:
time.sleep(3) 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 old_active_stream is not active_stream:
if proc: if proc:
proc.terminate() proc.terminate()
if active_stream != "": 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: 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 old_active_stream = active_stream

View file

@ -8,12 +8,16 @@ services:
- "1935:1935" - "1935:1935"
- "9997:9997" - "9997:9997"
web-frontend: web-frontend:
ports:
- "4173:4173"
build: build:
context: ./tiling-frontend context: ./tiling-frontend
dockerfile: Dockerfile dockerfile: Dockerfile
volumes: volumes:
- tiling_frontend_build:/usr/src/app/dist - tiling_frontend_build:/usr/src/app/dist
live-stream: live-stream:
ports:
- "1936:1936"
depends_on: depends_on:
active_stream_proxy: active_stream_proxy:
condition: service_started condition: service_started
@ -22,8 +26,7 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
volumes: volumes:
- tiling_frontend_build:/html - tiling_frontend_build:/html
environment: env_file: .stream.env
YT_STREAM_KEY: ${YT_STREAM_KEY}
backend: backend:
env_file: .backend.env env_file: .backend.env
ports: ports:

View file

@ -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 / COPY run.sh /

View file

@ -1,8 +1,14 @@
#!/bin/bash #!/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 \ ! 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 \ ! videoconvert \
! x264enc speed-preset=1 \ ! 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

View file

@ -20,3 +20,6 @@ authInternalUsers:
ips: [] ips: []
permissions: permissions:
- action: api - action: api
- action: publish
- action: playback
- action: read

View file

@ -14,3 +14,5 @@ FROM base AS release
COPY --from=install /temp/dev/node_modules node_modules COPY --from=install /temp/dev/node_modules node_modules
COPY . . COPY . .
RUN bun --bun run build RUN bun --bun run build
ENTRYPOINT ["bun", "--bun", "run", "preview", "--host"]