Skip to content

Instantly share code, notes, and snippets.

@ploxiln
Created August 9, 2019 18:03
Show Gist options
  • Save ploxiln/520b99c055fd5b895332d01ccdfedc49 to your computer and use it in GitHub Desktop.
Save ploxiln/520b99c055fd5b895332d01ccdfedc49 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -eu
RTSP_URL=
RTSP_AUTH=
TRANSPORT=tcp
TLS_OPTS=
WITH_AUDIO=false
WITH_VIDEO=true
WITH_RTCP=false
VIDEOSINK=autovideosink
GST_SYNC=true
LATENCY=0
RTSP_DEBUG=
SHOW_HELP=false
while [ $# -gt 0 ]; do
PARAM=${1%%=*}
VALUE=${1#*=}
case "$PARAM" in
--rtsp-url) RTSP_URL=$VALUE ;;
--token) RTSP_AUTH="user-pw=$VALUE" ;;
--transport) TRANSPORT=$VALUE ;;
--insecure) TLS_OPTS="tls-validation-flags=0x58" ;; # only expired, revoked
--rtsp-debug) RTSP_DEBUG="--gst-debug=rtspsrc:6" ;;
--audio) WITH_AUDIO=$VALUE ;;
--video) WITH_VIDEO=$VALUE ;;
--rtcp) WITH_RTCP=$VALUE ;;
--videosink) VIDEOSINK=$VALUE ;;
--sync) GST_SYNC=$VALUE ;;
--latency) LATENCY=$VALUE ;;
--help | -h) SHOW_HELP=true ;;
*) printf "ERROR: unrecognized option '$1'\n" 1>&2 ; exit 1 ;;
esac
shift
done
if $SHOW_HELP || [ -z "$RTSP_URL" ]; then
echo "USAGE: $0 --rtsp-url=<url> [--token=<token>] [--transport=<type>] [--insecure] [--rtsp-debug]" \
"[--audio=true] [--video=false] [--rtcp=true] [--videosink=glimagesink] [--sync=false] [--latency=<ms>]" 1>&2
exit 1
fi
if [ true != "$WITH_AUDIO" ] && [ false != "$WITH_AUDIO" ]; then
printf "ERROR: audio must be true or false\n" 1>&2
exit 1
fi
if [ true != "$WITH_VIDEO" ] && [ false != "$WITH_VIDEO" ]; then
printf "ERROR: video must be true or false\n" 1>&2
exit 1
fi
VIDEO_PIPELINE="mux. ! rtph264depay ! avdec_h264 ! videoconvert ! $VIDEOSINK sync=$GST_SYNC"
AUDIO_PIPELINE="mux. ! decodebin ! autoaudiosink sync=$GST_SYNC"
if ! $WITH_AUDIO; then
AUDIO_PIPELINE=
fi
if ! $WITH_VIDEO; then
VIDEO_PIPELINE=
fi
echo "Video gst pipeline: ${VIDEO_PIPELINE:-None}"
echo "Audio gst pipeline: ${AUDIO_PIPELINE:-None}"
echo
exec gst-launch-1.0 --gst-debug-level=3 $RTSP_DEBUG \
rtspsrc name=mux location="$RTSP_URL" ${RTSP_AUTH:+user-id=tok} "$RTSP_AUTH" \
latency=$LATENCY protocols=$TRANSPORT $TLS_OPTS do-rtcp=$WITH_RTCP \
$VIDEO_PIPELINE $AUDIO_PIPELINE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment