Skip to content

Instantly share code, notes, and snippets.

@rasmusmerzin
Created October 30, 2025 01:35
Show Gist options
  • Select an option

  • Save rasmusmerzin/a81031b7a0329ac3aa13eb697c31d4c3 to your computer and use it in GitHub Desktop.

Select an option

Save rasmusmerzin/a81031b7a0329ac3aa13eb697c31d4c3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
[[ -z "$PORT" ]] && PORT=18181
[[ -z "$SAMPLING" ]] && SAMPLING=44100
help() {
printf 'Usage: ffstream %s\n' 'receive' 'send <address>'
}
operator=$1
shift
case "$operator" in
send)
address=$1
shift
[[ $# -gt 0 ]] && echo "Unused arguments: $@" >&2
if [[ -z "$address" ]]; then
echo "Destination address is required" >&2
exit 1
fi
exec ffmpeg \
-f pulse \
-i remote.monitor \
-ac 2 \
-acodec pcm_u8 \
-ar "$SAMPLING" \
-f u8 \
"udp://$address:$PORT"
;;
receive)
[[ $# -gt 0 ]] && echo "Unused arguments: $@" >&2
exec ffplay \
-nodisp \
-acodec pcm_u8 \
-ar "$((SAMPLING * 2))" \
-analyzeduration 0 \
-probesize 32 \
-f u8 \
-fflags nobuffer \
-fflags discardcorrupt \
-framedrop \
-strict experimental \
-sync ext \
"udp://0.0.0.0:$PORT" #?listen=1
;;
*)
help
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment