mirror of
https://github.com/GoodStartLabs/AI_Diplomacy.git
synced 2026-04-19 12:58:09 +00:00
optimizations and sound for stream!
This commit is contained in:
parent
48c9ff51b6
commit
8521881c9d
5 changed files with 104 additions and 35 deletions
|
|
@ -16,10 +16,16 @@ COPY . .
|
||||||
# Accept build arguments for environment variables
|
# Accept build arguments for environment variables
|
||||||
ARG VITE_ELEVENLABS_API_KEY
|
ARG VITE_ELEVENLABS_API_KEY
|
||||||
ARG VITE_WEBHOOK_URL
|
ARG VITE_WEBHOOK_URL
|
||||||
|
ARG VITE_STREAMING_MODE
|
||||||
|
ARG VITE_DEBUG_MODE
|
||||||
|
ARG VITE_INSTANT_MODE
|
||||||
|
|
||||||
# Set environment variables for the build
|
# Set environment variables for the build
|
||||||
ENV VITE_ELEVENLABS_API_KEY=$VITE_ELEVENLABS_API_KEY
|
ENV VITE_ELEVENLABS_API_KEY=$VITE_ELEVENLABS_API_KEY
|
||||||
ENV VITE_WEBHOOK_URL=$VITE_WEBHOOK_URL
|
ENV VITE_WEBHOOK_URL=$VITE_WEBHOOK_URL
|
||||||
|
ENV VITE_STREAMING_MODE=$VITE_STREAMING_MODE
|
||||||
|
ENV VITE_DEBUG_MODE=$VITE_DEBUG_MODE
|
||||||
|
ENV VITE_INSTANT_MODE=$VITE_INSTANT_MODE
|
||||||
|
|
||||||
# Build the production-ready files (dist/)
|
# Build the production-ready files (dist/)
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@ services:
|
||||||
args:
|
args:
|
||||||
- VITE_ELEVENLABS_API_KEY=${VITE_ELEVENLABS_API_KEY}
|
- VITE_ELEVENLABS_API_KEY=${VITE_ELEVENLABS_API_KEY}
|
||||||
- VITE_WEBHOOK_URL=${VITE_WEBHOOK_URL}
|
- VITE_WEBHOOK_URL=${VITE_WEBHOOK_URL}
|
||||||
|
- VITE_STREAMING_MODE=True
|
||||||
|
- VITE_DEBUG_MODE=False
|
||||||
|
- VITE_INSTANT_MODE=False
|
||||||
env_file: "./ai_animation/.env"
|
env_file: "./ai_animation/.env"
|
||||||
ports:
|
ports:
|
||||||
- "4173:4173"
|
- "4173:4173"
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
pulseaudio \
|
pulseaudio \
|
||||||
fluxbox \
|
fluxbox \
|
||||||
dbus dbus-x11 \
|
dbus dbus-x11 \
|
||||||
|
xdotool \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install Google Chrome
|
# Install Google Chrome
|
||||||
|
|
@ -38,10 +39,8 @@ ENV SCREEN_GEOMETRY=1920x1080x24
|
||||||
RUN mkdir /twitch-streamer/
|
RUN mkdir /twitch-streamer/
|
||||||
COPY pulse-virtual-audio.sh /twitch-streamer/pulse-virtual-audio.sh
|
COPY pulse-virtual-audio.sh /twitch-streamer/pulse-virtual-audio.sh
|
||||||
COPY entrypoint.sh /twitch-streamer/entrypoint.sh
|
COPY entrypoint.sh /twitch-streamer/entrypoint.sh
|
||||||
RUN chmod +x /twitch-streamer/pulse-virtual-audio.sh /twitch-streamer/entrypoint.sh
|
COPY chrome-launcher.sh /twitch-streamer/chrome-launcher.sh
|
||||||
|
RUN chmod +x /twitch-streamer/pulse-virtual-audio.sh /twitch-streamer/entrypoint.sh /twitch-streamer/chrome-launcher.sh
|
||||||
WORKDIR /twitch-streamer/
|
WORKDIR /twitch-streamer/
|
||||||
|
|
||||||
# Switch to non-root user
|
|
||||||
USER chrome
|
|
||||||
|
|
||||||
ENTRYPOINT ["/twitch-streamer/entrypoint.sh"]
|
ENTRYPOINT ["/twitch-streamer/entrypoint.sh"]
|
||||||
|
|
|
||||||
65
twitch-streamer/chrome-launcher.sh
Normal file
65
twitch-streamer/chrome-launcher.sh
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Chrome launcher with restart capability
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
echo "Starting Chrome browser..."
|
||||||
|
|
||||||
|
# Set PulseAudio environment for Chrome
|
||||||
|
export PULSE_RUNTIME_PATH=/tmp/pulse
|
||||||
|
export PULSE_SERVER=unix:/tmp/pulse/native
|
||||||
|
|
||||||
|
DISPLAY=$DISPLAY google-chrome \
|
||||||
|
--remote-debugging-port=9222 \
|
||||||
|
--no-sandbox \
|
||||||
|
--disable-setuid-sandbox \
|
||||||
|
--disable-dev-shm-usage \
|
||||||
|
--no-first-run \
|
||||||
|
--disable-background-timer-throttling \
|
||||||
|
--disable-renderer-backgrounding \
|
||||||
|
--disable-backgrounding-occluded-windows \
|
||||||
|
--disable-features=TranslateUI \
|
||||||
|
--disable-ipc-flooding-protection \
|
||||||
|
--disable-frame-rate-limit \
|
||||||
|
--enable-precise-memory-info \
|
||||||
|
--max-gum-fps=30 \
|
||||||
|
--user-data-dir=/home/chrome/chrome-data \
|
||||||
|
--window-size=1600,900 --window-position=0,0 \
|
||||||
|
--kiosk \
|
||||||
|
--autoplay-policy=no-user-gesture-required \
|
||||||
|
--disable-features=AudioServiceSandbox,RendererCodeIntegrity,IsolateOrigins \
|
||||||
|
--disable-site-isolation-trials \
|
||||||
|
--use-fake-ui-for-media-stream \
|
||||||
|
--enable-usermedia-screen-capturing \
|
||||||
|
--enable-gpu \
|
||||||
|
--use-gl=swiftshader \
|
||||||
|
--disable-gpu-vsync \
|
||||||
|
--force-device-scale-factor=1 \
|
||||||
|
--disable-web-security \
|
||||||
|
--disable-features=VizDisplayCompositor \
|
||||||
|
--enable-features=NetworkService \
|
||||||
|
--disable-background-networking \
|
||||||
|
--disable-background-mode \
|
||||||
|
--disable-client-side-phishing-detection \
|
||||||
|
--disable-component-update \
|
||||||
|
--disable-default-apps \
|
||||||
|
--disable-domain-reliability \
|
||||||
|
--disable-features=AudioServiceOutOfProcess \
|
||||||
|
--disable-hang-monitor \
|
||||||
|
--disable-popup-blocking \
|
||||||
|
--disable-prompt-on-repost \
|
||||||
|
--disable-sync \
|
||||||
|
--metrics-recording-only \
|
||||||
|
--no-default-browser-check \
|
||||||
|
--no-pings \
|
||||||
|
--password-store=basic \
|
||||||
|
--use-mock-keychain \
|
||||||
|
--force-color-profile=srgb \
|
||||||
|
--disable-features=Translate \
|
||||||
|
--disable-features=BlinkGenPropertyTrees \
|
||||||
|
--max_old_space_size=512 \
|
||||||
|
--js-flags="--max-old-space-size=512" \
|
||||||
|
"http://diplomacy:4173"
|
||||||
|
|
||||||
|
echo "Chrome exited with code $?. Restarting in 5 seconds..."
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
@ -10,8 +10,8 @@ fi
|
||||||
# Start PulseAudio (virtual audio) in the background
|
# Start PulseAudio (virtual audio) in the background
|
||||||
/twitch-streamer/pulse-virtual-audio.sh &
|
/twitch-streamer/pulse-virtual-audio.sh &
|
||||||
|
|
||||||
# Start Xvfb (the in-memory X server) in the background
|
# Start Xvfb (the in-memory X server) in the background with optimizations
|
||||||
Xvfb $DISPLAY -screen 0 1920x1080x24 &
|
Xvfb $DISPLAY -screen 0 1600x900x24 -ac -nolisten tcp &
|
||||||
echo "Display is ${DISPLAY}"
|
echo "Display is ${DISPLAY}"
|
||||||
|
|
||||||
# Give Xvfb a moment to start
|
# Give Xvfb a moment to start
|
||||||
|
|
@ -19,46 +19,42 @@ sleep 2
|
||||||
|
|
||||||
mkdir -p /home/chrome
|
mkdir -p /home/chrome
|
||||||
|
|
||||||
# Launch Chrome in the background, pointing at your site.
|
# Launch Chrome with restart capability
|
||||||
# --disable-background-timer-throttling & related flags to prevent fps throttling in headless/Xvfb
|
/twitch-streamer/chrome-launcher.sh &
|
||||||
DISPLAY=$DISPLAY google-chrome \
|
|
||||||
--remote-debugging-port=9222 \
|
|
||||||
--no-sandbox \
|
|
||||||
--disable-setuid-sandbox \
|
|
||||||
--disable-dev-shm-usage \
|
|
||||||
--no-first-run \
|
|
||||||
--disable-background-timer-throttling \
|
|
||||||
--disable-renderer-backgrounding \
|
|
||||||
--disable-backgrounding-occluded-windows \
|
|
||||||
--disable-features=TranslateUI \
|
|
||||||
--disable-ipc-flooding-protection \
|
|
||||||
--disable-frame-rate-limit \
|
|
||||||
--enable-precise-memory-info \
|
|
||||||
--max-gum-fps=30 \
|
|
||||||
--user-data-dir=/home/chrome/chrome-data \
|
|
||||||
--window-size=1920,1080 --window-position=0,0 \
|
|
||||||
--kiosk \
|
|
||||||
--autoplay-policy=no-user-gesture-required \
|
|
||||||
--enable-gpu \
|
|
||||||
--use-gl=swiftshader \
|
|
||||||
--disable-gpu-vsync \
|
|
||||||
--force-device-scale-factor=1 \
|
|
||||||
"http://diplomacy:4173" &
|
|
||||||
|
|
||||||
sleep 5 # let the page load or animations start
|
sleep 10 # let the page load or animations start
|
||||||
|
|
||||||
|
# Simulate multiple clicks to enable audio and move mouse to corner
|
||||||
|
echo "Simulating clicks for audio autoplay..."
|
||||||
|
# Click on the play button area
|
||||||
|
xdotool mousemove 960 540 # Move to center
|
||||||
|
sleep 1
|
||||||
|
xdotool click 1 # Left click
|
||||||
|
sleep 0.5
|
||||||
|
# Click multiple times to ensure audio starts
|
||||||
|
xdotool click 1 # Second click
|
||||||
|
sleep 0.2
|
||||||
|
xdotool click 1 # Third click
|
||||||
|
sleep 0.2
|
||||||
|
# Try clicking on chat area in case it helps
|
||||||
|
xdotool mousemove 300 300
|
||||||
|
xdotool click 1
|
||||||
|
sleep 0.5
|
||||||
|
xdotool mousemove 1599 899 # Move to bottom right corner
|
||||||
|
|
||||||
# Set PulseAudio environment
|
# Set PulseAudio environment
|
||||||
export PULSE_RUNTIME_PATH=/tmp/pulse
|
export PULSE_RUNTIME_PATH=/tmp/pulse
|
||||||
export PULSE_SERVER=unix:/tmp/pulse/native
|
export PULSE_SERVER=unix:/tmp/pulse/native
|
||||||
|
export PULSE_SINK=dummy_sink
|
||||||
|
|
||||||
# Start streaming with FFmpeg.
|
# Start streaming with FFmpeg.
|
||||||
# - For video: x11grab at 30fps
|
# - For video: x11grab at 30fps
|
||||||
# - For audio: pulse from the dummy sink monitor
|
# - For audio: pulse from the dummy sink monitor
|
||||||
exec ffmpeg -y \
|
exec ffmpeg -y \
|
||||||
-f x11grab -video_size 1920x1080 -framerate 30 -thread_queue_size 1024 -i $DISPLAY \
|
-f x11grab -video_size 1600x900 -framerate 15 -thread_queue_size 4096 -i $DISPLAY \
|
||||||
-f pulse -thread_queue_size 1024 -i dummy_sink.monitor \
|
-f pulse -thread_queue_size 1024 -i dummy_sink.monitor \
|
||||||
-c:v libx264 -preset fast -tune animation -b:v 4500k -maxrate 4500k -bufsize 9000k \
|
-c:v libx264 -preset ultrafast -tune zerolatency -b:v 1000k -maxrate 1500k -bufsize 300k -profile:v baseline -level 3.0 -crf 32 -threads 1 -x264-params "nal-hrd=cbr:force-cfr=1:keyint=30" \
|
||||||
-g 60 -keyint_min 60 \
|
-g 40 -keyint_min 20 \
|
||||||
-pix_fmt yuv420p \
|
-pix_fmt yuv420p \
|
||||||
-c:a aac -b:a 128k \
|
-c:a aac -b:a 128k \
|
||||||
-vsync cfr \
|
-vsync cfr \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue