summaryrefslogtreecommitdiff
path: root/bin/send-gst-rtp-v-a
blob: 0589963b72cb999fffe2b5e27ae5e30575b85369 (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. VFORMAT=${VFORMAT:-$3} # H264 VP8 RAW - default: H264
  9. AFORMAT=${AFORMAT:-$4} # AMR OPUS RAW - default: AMR
  10. set -u
  11. # set multicast groups (also for recorder host) if camera host is wildcard
  12. [ -n "$RECIP" ] || RECMIP=239.255.0.1
  13. [ -n "$RECIP" ] || CAMMIP=239.255.0.2
  14. RECHOST="${RECIP:+host=$RECIP}${RECMIP:+host=$RECMIP auto-multicast=true}"
  15. CAMHOST="${CAMMIP:+address=$CAMMIP auto-multicast=true}"
  16. HEIGHT=240
  17. FRAMERATE=25
  18. AUDIORATE=48000
  19. VCAPS=video/x-raw,height="$HEIGHT"
  20. ACAPS=audio/x-raw,rate="$AUDIORATE",channels=2,depth=16
  21. case "$VFORMAT" in
  22. H264|'')
  23. # * let x264 use low-latency sliced-threads (i.e. don't disable treads)
  24. 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"
  25. ;;
  26. VP8)
  27. VENC="vp8enc min_quantizer=10 max_quantizer=10 cpu-used=10 deadline=1000000 ! video/x-vp8 ! rtpvp8pay"
  28. ;;
  29. RAW)
  30. VENC="rtpvrawpay"
  31. ;;
  32. esac
  33. case "$AFORMAT" in
  34. AMR|'')
  35. AENC="amrnbenc ! rtpamrpay"
  36. ;;
  37. OPUS)
  38. AENC="opusenc ! rtpopuspay"
  39. ;;
  40. RAW)
  41. AENC="rtpL16pay"
  42. ;;
  43. esac
  44. stream() {
  45. ID=$1
  46. SRC=$2
  47. echo \
  48. $SRC \
  49. ! "rtpbin.send_rtp_sink_$ID" \
  50. rtpbin."send_rtp_src_$ID" ! queue \
  51. ! udpsink name="rtp_sink_$ID" port=$((5000+ID-1)) $RECHOST \
  52. rtpbin.send_rtcp_src_$ID \
  53. ! udpsink name="rtcp_sink_$ID" port=$((5010+ID-1)) $RECHOST sync=false async=false \
  54. udpsrc name="rtp_src_$ID" port=$((5020+ID-1)) $CAMHOST \
  55. ! rtpbin."recv_rtcp_sink_$ID"
  56. }
  57. n=0
  58. # * force threads using queues - see http://stackoverflow.com/a/30738533
  59. gst-launch-1.0 -v \
  60. rtpbin name=rtpbin \
  61. $(for dev in $VDEVICES; do n=$((n+1)); stream "$n" "v4l2src device=$dev ! queue ! videoconvert ! queue ! $VCAPS ! queue ! $VENC ! queue"; done; \
  62. for dev in $ADEVICES; do n=$((n+1)); stream "$n" "alsasrc device=$dev ! audioconvert ! $AENC ! queue"; done)
  63. set -e