Skip to content

Instantly share code, notes, and snippets.

@andrewmackrodt
Created November 27, 2022 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewmackrodt/88c2233fb9cc4797ada93e6703c13d72 to your computer and use it in GitHub Desktop.
Save andrewmackrodt/88c2233fb9cc4797ada93e6703c13d72 to your computer and use it in GitHub Desktop.
#!/bin/bash
function finish {
if [[ "${rtspContainerId:-}" != "" ]]; then
docker kill "$rtspContainerId"
fi
if [[ "${ffmpegPid:-}" != "" ]]; then
kill "$ffmpegPid"
fi
}
trap finish EXIT
rtspContainerId=$( \
docker run --rm -it -d \
-e RTSP_PROTOCOLS=tcp \
-p 8554:8554 \
aler9/rtsp-simple-server \
)
while true; do
if nc -w1 127.0.0.1 8554; then
break
fi
done
resolution=$(xrandr | awk '$2 == "connected" && $3 == "primary" { print $4 }' | sed -E 's/\+.+//')
ffmpeg -f x11grab -i ${DISPLAY:-:0} -video_size "$resolution" \
-framerate 30 \
-vcodec libx264 \
-tune zerolatency \
-crf 18 \
-b:v 500k \
-bufsize 300k \
-vf scale=1280:-1 \
-f rtsp \
-rtsp_transport tcp \
rtsp://127.0.0.1:8554/stream &
ffmpegPid=$?
docker logs -f "$rtspContainerId"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment