summaryrefslogtreecommitdiff
path: root/bin/send-gst-rtp-v-a
blob: 912100a28bc2fb357cab40645c7bae6da92432ea (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=${1:-$(find /dev -maxdepth 1 -type c -name 'video*' | sort)}
  6. #ADEVICES=${2:-$(arecord -L | grep -Po '^hw:\S+')}
  7. #ADEVICES=${2:-$(arecord -L | grep -Pom1 '^hw:\S+')}
  8. ADEVICES=${2:-} # FIXME: Detect/blacklist and skip faulty devices
  9. VFORMAT=${VFORMAT:-$3} # H264 VP8 RAW - default: RAW
  10. AFORMAT=${AFORMAT:-$4} # 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. case "$VFORMAT" in
  23. H264)
  24. # * let x264 use low-latency sliced-threads (i.e. don't disable treads)
  25. 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 ! rtph264pay"
  26. ;;
  27. VP8)
  28. VENC="vp8enc min_quantizer=10 max_quantizer=10 cpu-used=10 deadline=1000000 ! video/x-vp8 ! rtpvp8pay"
  29. ;;
  30. RAW|'')
  31. VENC="rtpvrawpay"
  32. ;;
  33. esac
  34. case "$AFORMAT" in
  35. AMR)
  36. AENC="amrnbenc ! rtpamrpay"
  37. ;;
  38. OPUS)
  39. AENC="opusenc ! rtpopuspay"
  40. ;;
  41. RAW|'')
  42. AENC="rtpL16pay"
  43. ;;
  44. esac
  45. stream() {
  46. ID=$1
  47. SRC=$2
  48. echo \
  49. $SRC \
  50. ! "rtpbin.send_rtp_sink_$ID" \
  51. rtpbin."send_rtp_src_$ID" ! queue \
  52. ! udpsink name="rtp_sink_$ID" port=$((5000+ID-1)) $RECHOST \
  53. rtpbin.send_rtcp_src_$ID \
  54. ! udpsink name="rtcp_sink_$ID" port=$((5010+ID-1)) $RECHOST sync=false async=false \
  55. udpsrc name="rtp_src_$ID" port=$((5020+ID-1)) $CAMHOST \
  56. ! rtpbin."recv_rtcp_sink_$ID"
  57. }
  58. n=0
  59. # * force threads using queues - see http://stackoverflow.com/a/30738533
  60. gst-launch-1.0 -v \
  61. rtpbin name=rtpbin \
  62. $(for dev in $VDEVICES; do n=$((n+1)); stream "$n" "v4l2src device=$dev ! queue ! videoconvert ! queue ! $VCAPS ! queue ! $VENC ! queue"; done; \
  63. for dev in $ADEVICES; do n=$((n+1)); stream "$n" "alsasrc device=$dev ! audioconvert ! $AENC ! queue"; done)
  64. set -e