summaryrefslogtreecommitdiff
path: root/bin/send-gst-rtp-v-a
blob: f8b548b78407b42f9c812633131d5eb9ec0d50c3 (plain)
  1. #!/bin/sh
  2. # Send RTP video and audio streams
  3. set -e
  4. RECIP=${RECIP:-$1} # destination host - default: use multicast group
  5. VDEVICES=${2:-$(find /dev -maxdepth 1 -type c -name 'video*' | sort)}
  6. #ADEVICES=${3:-$(arecord -L | grep -Po '^hw:\S+')}
  7. #ADEVICES=${3:-$(arecord -L | grep -Pom1 '^hw:\S+')}
  8. ADEVICES=${3:-} # FIXME: Detect/blacklist and skip faulty devices
  9. VFORMAT=${VFORMAT:-$4} # H264 VP8 RAW - default: RAW
  10. AFORMAT=${AFORMAT:-$5} # AMR OPUS RAW - default: RAW
  11. set -u
  12. # set multicast groups (also for recorder host) if camera host is wildcard
  13. [ -n "$RECIP" ] || RECMIP=239.255.0.1
  14. [ -n "$RECIP" ] || CAMMIP=239.255.0.2
  15. RECHOST="${RECIP:+host=$RECIP}${RECMIP:+host=$RECMIP auto-multicast=true}"
  16. CAMHOST="${CAMMIP:+address=$CAMMIP auto-multicast=true}"
  17. HEIGHT=240
  18. FRAMERATE=25
  19. AUDIORATE=48000
  20. VCAPS=video/x-raw,height="$HEIGHT"
  21. ACAPS=audio/x-raw,rate="$AUDIORATE",channels=2,depth=16
  22. # * http://stackoverflow.com/a/42237307
  23. ABUFFERS=20000
  24. # * force threads using queues - see http://stackoverflow.com/a/30738533
  25. # * generous queue sizes inspired by https://wiki.xiph.org/GST_cookbook
  26. QUEUE=" queue max-size-bytes=100000000 max-size-time=0"
  27. case "$VFORMAT" in
  28. H264)
  29. # * let x264 use low-latency sliced-threads (i.e. don't disable treads)
  30. VENC="x264enc speed-preset=ultrafast tune=zerolatency bitrate=800 byte-stream=true key-int-max=15 intra-refresh=true option-string=\"slice-max-size=8192:vbv-maxrate=80:vbv-bufsize=10\" ! video/x-h264,profile=baseline ! $QUEUE ! rtph264pay"
  31. ;;
  32. VP8)
  33. VENC="vp8enc cpu-used=10 threads=2 deadline=10000 ! video/x-vp8 ! $QUEUE ! rtpvp8pay"
  34. ;;
  35. RAW|'')
  36. VENC="rtpvrawpay"
  37. ;;
  38. *)
  39. echo "ERROR: Unsupported video format: \"$VFORMAT\""
  40. exit 1
  41. ;;
  42. esac
  43. case "$AFORMAT" in
  44. AMR)
  45. AENC="amrnbenc ! $QUEUE ! rtpamrpay"
  46. ;;
  47. OPUS)
  48. AENC="opusenc ! $QUEUE ! rtpopuspay"
  49. ;;
  50. RAW|'')
  51. AENC="rtpL16pay"
  52. ;;
  53. *)
  54. echo "ERROR: Unsupported audio format: \"$AFORMAT\""
  55. exit 1
  56. ;;
  57. esac
  58. stream() {
  59. ID=$1
  60. SRC=$2
  61. echo \
  62. $SRC \
  63. ! "rtpbin.send_rtp_sink_$ID" \
  64. rtpbin."send_rtp_src_$ID" ! queue \
  65. ! udpsink name="rtp_sink_$ID" port=$((5000+ID-1)) $RECHOST \
  66. rtpbin.send_rtcp_src_$ID \
  67. ! udpsink name="rtcp_sink_$ID" port=$((5010+ID-1)) $RECHOST sync=false async=false \
  68. udpsrc name="rtp_src_$ID" port=$((5020+ID-1)) $CAMHOST \
  69. ! rtpbin."recv_rtcp_sink_$ID"
  70. }
  71. gst-launch-1.0 -v \
  72. rtpbin name=rtpbin \
  73. $(n=0;\
  74. for dev in $VDEVICES; do n=$((n+1)); stream "$n" "v4l2src device=$dev ! $QUEUE ! videoconvert ! $VCAPS ! $QUEUE ! $VENC ! $QUEUE"; done;\
  75. for dev in $ADEVICES; do n=$((n+1)); stream "$n" "alsasrc device=$dev buffer-time=$ABUFFERS ! $QUEUE ! audioconvert ! $QUEUE ! $AENC ! $QUEUE"; done;\
  76. )
  77. set -e