This commit is contained in:
Micha Albert 2024-09-11 16:10:23 -04:00
parent c7746071fc
commit 1c91c56d30
4 changed files with 45 additions and 32 deletions

View file

@ -12,18 +12,18 @@ old_active_stream = active_stream
proc = None proc = None
if active_stream != "": 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"]) proc = subprocess.Popen(["ffmpeg", "-re", "-i", f"rtmp://host.containers.internal:1935/{active_stream}", "-c:a", "libmp3lame", "-f", "flv", "rtmp://host.containers.internal:1936/active-input"])
else: else:
proc = subprocess.Popen(["ffmpeg", "-f", "lavfi", "-i", "anullsrc", "-c:a", "libmp3lame", "-f", "flv", "rtmp://host.containers.internal: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.replace('""', '') 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(["ffmpeg", "-re", "-i", f"rtmp://mediamtx:1935/{active_stream}", "-c:a", "libmp3lame", "-f", "flv", "rtmp://host.containers.internal:1936/active-input"]) proc = subprocess.Popen(["ffmpeg", "-re", "-i", f"rtmp://host.containers.internal:1935/{active_stream}", "-c:a", "libmp3lame", "-f", "flv", "rtmp://host.containers.internal:1936/active-input"])
else: else:
proc = subprocess.Popen(["ffmpeg", "-f", "lavfi", "-i", "anullsrc", "-c:a", "libmp3lame", "-f", "flv", "rtmp://host.containers.internal: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

@ -1,12 +1,13 @@
services: services:
mediamtx: mediamtx:
network_mode: "host"
build: build:
context: ./mediamtx context: ./mediamtx
dockerfile: Dockerfile dockerfile: Dockerfile
ports: # ports:
- "8889:8889" # - "8889:8889"
- "1935:1935" # - "1935:1935"
- "9997:9997" # - "9997:9997"
web-frontend: web-frontend:
ports: ports:
- "4173:4173" - "4173:4173"
@ -16,8 +17,6 @@ services:
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
@ -36,17 +35,17 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
volumes: volumes:
- ./backend/db:/usr/src/app/db - ./backend/db:/usr/src/app/db
active-stream-proxy: # active-stream-proxy:
build: # build:
context: ./active-stream-proxy # context: ./active-stream-proxy
dockerfile: Dockerfile # dockerfile: Dockerfile
depends_on: # depends_on:
web-frontend: # web-frontend:
condition: service_completed_successfully # condition: service_completed_successfully
mediamtx: # mediamtx:
condition: service_started # condition: service_started
backend: # backend:
condition: service_started # condition: service_started
volumes: volumes:
mediamtx_recordings: mediamtx_recordings:
tiling_frontend_build: tiling_frontend_build:

View file

@ -1,17 +1,19 @@
FROM ubuntu:22.04 FROM ubuntu:latest
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update RUN apt update
RUN apt install -y ffmpeg RUN apt install -y ffmpeg xvfb software-properties-common dbus-x11
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 add-apt-repository -y ppa:xtradeb/apps
RUN apt update
RUN apt install -y chromium
RUN rm -rf /var/lib/apt/lists/* RUN rm -rf /var/lib/apt/lists/*
RUN apt clean RUN apt clean
COPY run.sh / COPY run.sh .
ENTRYPOINT ["/run.sh"] ENTRYPOINT ["./run.sh"]

View file

@ -1,8 +1,20 @@
#!/bin/bash #!/bin/bash
sleep 1 export CHROMIUM_FLAGS="--disable-software-rasterizer --disable-dev-shm-usage"
dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address
export LIBGL_ALWAYS_INDIRECT=1
LIBGL_ALWAYS_SOFTWARE=true gst-launch-1.0 -e wpesrc location="http://web-frontend:4173/" \ bash -c "sleep 5 && DISPLAY=:99 ffmpeg -f x11grab -r 30 -s 1920x1080 -draw_mouse 0 -i :99.0 -f alsa -ac 2 -i hw:0 -vcodec libx264 -preset medium -b:v 7000k -framerate 30 -g 2 -pix_fmt yuv420p -acodec aac -f flv rtmp://x.rtmp.youtube.com/live2/$YT_STREAM_KEY" &
! videoconvert ! videoscale ! videorate \
! "video/x-raw, format=NV12, width=1920, height=1080, framerate=30/1" \ DISPLAY=:99 xvfb-run \
! filesink location=/dev/stdout | ffmpeg -re -y -f rawvideo -pixel_format nv12 -video_size 1920x1080 -framerate 30 -i - -listen 1 -i rtmp://0.0.0.0:1936/active-input -filter_complex "[0:v][0:v]overlay=-50:0[bg]; [bg][0:v]overlay=-50-W,format=nv12[out]" -map "[out]" -c:v libx264 -x264-params keyint=60 -preset ultrafast -b:v 6800k -c:a copy -map 1:a:0 -movflags faststart -f flv -pix_fmt nv12 rtmp://x.rtmp.youtube.com/live2/$YT_STREAM_KEY --server-num 99 \
-s "-nocursor -ac -screen 0 1920x1080x24" \
dbus-launch chromium \
--temp-profile \
--window-size=1920,1080 \
--disable-gpu \
--window-position=0,0 \
--no-sandbox \
--hide-scrollbars \
--disable-setuid-sandbox \
--app=http://web-frontend:4173