summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2017-02-26 19:28:51 +0000
committerJonas Smedegaard <dr@jones.dk>2017-02-26 19:28:51 +0000
commit0e645bd9ddc20e8c57ae71882054d89b6192257b (patch)
tree70906337ce6106bb9ca7d2a7d57b49f3785dbaa7 /bin
parentc440b749d9c546e904d5a64fccfdbd83bdb0c228 (diff)
Initial RTP sender.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/send-gst-rtp-v-a73
1 files changed, 73 insertions, 0 deletions
diff --git a/bin/send-gst-rtp-v-a b/bin/send-gst-rtp-v-a
new file mode 100755
index 0000000..0589963
--- /dev/null
+++ b/bin/send-gst-rtp-v-a
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+# Send RTP video and audio streams
+
+set -e
+RECIP=${RECIP:-$1} # destination host - default: use multicast group
+VDEVICES=${1:-$(find /dev -maxdepth 1 -type c -name 'video*' | sort)}
+#ADEVICES=${2:-$(arecord -L | grep -Po '^hw:\S+')}
+#ADEVICES=${2:-$(arecord -L | grep -Pom1 '^hw:\S+')}
+VFORMAT=${VFORMAT:-$3} # H264 VP8 RAW - default: H264
+AFORMAT=${AFORMAT:-$4} # AMR OPUS RAW - default: AMR
+set -u
+
+# set multicast groups (also for recorder host) if camera host is wildcard
+[ -n "$RECIP" ] || RECMIP=239.255.0.1
+[ -n "$RECIP" ] || CAMMIP=239.255.0.2
+RECHOST="${RECIP:+host=$RECIP}${RECMIP:+host=$RECMIP auto-multicast=true}"
+CAMHOST="${CAMMIP:+address=$CAMMIP auto-multicast=true}"
+
+HEIGHT=240
+FRAMERATE=25
+AUDIORATE=48000
+
+VCAPS=video/x-raw,height="$HEIGHT"
+ACAPS=audio/x-raw,rate="$AUDIORATE",channels=2,depth=16
+
+case "$VFORMAT" in
+ H264|'')
+ # * let x264 use low-latency sliced-threads (i.e. don't disable treads)
+ 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"
+ ;;
+ VP8)
+ VENC="vp8enc min_quantizer=10 max_quantizer=10 cpu-used=10 deadline=1000000 ! video/x-vp8 ! rtpvp8pay"
+ ;;
+ RAW)
+ VENC="rtpvrawpay"
+ ;;
+esac
+
+case "$AFORMAT" in
+ AMR|'')
+ AENC="amrnbenc ! rtpamrpay"
+ ;;
+ OPUS)
+ AENC="opusenc ! rtpopuspay"
+ ;;
+ RAW)
+ AENC="rtpL16pay"
+ ;;
+esac
+
+stream() {
+ ID=$1
+ SRC=$2
+ echo \
+ $SRC \
+ ! "rtpbin.send_rtp_sink_$ID" \
+ rtpbin."send_rtp_src_$ID" ! queue \
+ ! udpsink name="rtp_sink_$ID" port=$((5000+ID-1)) $RECHOST \
+ rtpbin.send_rtcp_src_$ID \
+ ! udpsink name="rtcp_sink_$ID" port=$((5010+ID-1)) $RECHOST sync=false async=false \
+ udpsrc name="rtp_src_$ID" port=$((5020+ID-1)) $CAMHOST \
+ ! rtpbin."recv_rtcp_sink_$ID"
+}
+
+n=0
+# * force threads using queues - see http://stackoverflow.com/a/30738533
+gst-launch-1.0 -v \
+ rtpbin name=rtpbin \
+ $(for dev in $VDEVICES; do n=$((n+1)); stream "$n" "v4l2src device=$dev ! queue ! videoconvert ! queue ! $VCAPS ! queue ! $VENC ! queue"; done; \
+ for dev in $ADEVICES; do n=$((n+1)); stream "$n" "alsasrc device=$dev ! audioconvert ! $AENC ! queue"; done)
+
+set -e