stream.sh is a Bash script designed to stream multiple video sources to multiple screens using ffplay. This script ensures that each video stream is displayed on a specified monitor and restarts the stream if it fails. The script is optimized for real-time playback by using various ffplay options to reduce latency and handle frame drops effectively.
- Streams multiple video sources to multiple screens.
- Ensures each stream is displayed on the specified monitor.
- Restarts streams automatically if they fail.
- Optimized for real-time playback with minimal latency.
- Detailed logging and debugging output.
ffplay: Part of theffmpegsuite. Installffmpegto getffplay.wmctrl: A command-line tool to interact with X Window Manager.
On Ubuntu/Debian:
sudo apt-get update
sudo apt-get install ffmpegOn macOS using Homebrew:
brew install ffmpegOn Ubuntu/Debian:
sudo apt-get install wmctrlOn macOS using Homebrew:
brew install wmctrlYou can download the stream.sh script directly from the gist URL:
curl -o stream.sh https://gist.githubusercontent.com/troykelly/9c9e33390931d3d97ff1d888a6eb7ae1/raw/stream.sh
chmod +x stream.sh./stream.sh URL1 URL2 ...- Replace
URL1,URL2, etc., with the URLs of the video streams you want to display. - The script will automatically detect connected screens and map the provided URLs to the screens in the order they are provided.
./stream.sh "https://example.com/stream1" "https://example.com/stream2"This command will start streaming https://example.com/stream1 on the first detected screen and https://example.com/stream2 on the second detected screen.
- The script detects the connected screens using
xrandr. - It starts an
ffplayprocess for each provided URL, positioning theffplaywindow on the specified screen. - If an
ffplayprocess fails, the script automatically restarts the stream on the same screen. - The script optimizes
ffplayfor real-time playback by using options to reduce latency and handle frame drops.
The script uses the following ffplay options to optimize for real-time playback:
-fflags nobuffer: Reduces the buffering time.-flags low_delay: Sets low delay for decoding.-strict experimental: Enables experimental features.-fast: Enables faster but less accurate decoding.-framedrop: Allows dropping frames if the decoder is too slow.-sync ext: Synchronizes to the external clock.
The script handles the following signals:
SIGHUP: Terminates all streams and exits cleanly.SIGUSR1: Restarts the stream on the first screen.SIGUSR2: Restarts the stream on the second screen.
To have the script autostart if autologin is enabled, you can place the script in ~/.config/autostart-scripts/ and ensure it is executable. Additionally, you need to create a .desktop file to run the script on startup.
-
Create the autostart-scripts directory (if it doesn't already exist):
mkdir -p ~/.config/autostart-scripts -
Move the script to the autostart-scripts directory:
mv stream.sh ~/.config/autostart-scripts/ -
Make sure the script is executable:
chmod +x ~/.config/autostart-scripts/stream.sh -
Create a
.desktopfile in the~/.config/autostart/directory:nano ~/.config/autostart/stream.sh.desktopAdd the following content to the file:
[Desktop Entry] Type=Application Exec=/home/YOUR_USERNAME/.config/autostart-scripts/stream.sh "https://example.com/stream1" "https://example.com/stream2" Hidden=false NoDisplay=false X-GNOME-Autostart-enabled=true Name[en_US]=Stream.sh Name=Stream.sh Comment=Start Stream.sh at login
Replace
YOUR_USERNAMEwith your actual username and update theExecline with the correct paths and URLs. -
Save and exit the file.
Press
CTRL+X, thenY, and thenEnter.
- Ensure
ffplayandwmctrlare installed and available in your system's PATH. - Make sure the URLs provided are accessible and valid video streams.
- Check the script's output for any error messages or debugging information.