summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/ipcam-rtsp2hls.sh95
1 files changed, 95 insertions, 0 deletions
diff --git a/tools/ipcam-rtsp2hls.sh b/tools/ipcam-rtsp2hls.sh
new file mode 100755
index 0000000..d52fb8a
--- /dev/null
+++ b/tools/ipcam-rtsp2hls.sh
@@ -0,0 +1,95 @@
+#!/bin/bash
+
+PROGNAME="$0"
+OUTDIR=/var/ipcamfs # should be tmpfs
+PORT=554
+NAME=
+IP=
+USER=
+PASSWORD=
+DEBUG=0
+CHANNEL=1
+
+die() {
+ echo >&2 "error: $@"
+ exit 1
+}
+
+usage() {
+ cat <<EOF
+usage: $PROGNAME [OPTIONS] COMMAND
+
+Options:
+ --ip camera IP
+ --port RTSP port (default: 554)
+ --name camera name (chunks will be stored under $OUTDIR/{name}/)
+ --user
+ --password
+ --debug
+ --channel 1|2
+
+EOF
+ exit
+}
+
+validate_channel() {
+ local c="$1"
+ case "$c" in
+ 1|2)
+ :
+ ;;
+ *)
+ die "Invalid channel"
+ ;;
+ esac
+}
+
+[ -z "$1" ] && usage
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --ip|--port|--name|--user|--password)
+ _var=${1:2}
+ _var=${_var^^}
+ printf -v "$_var" '%s' "$2"
+ shift
+ ;;
+
+ --debug)
+ DEBUG=1
+ ;;
+
+ --channel)
+ CHANNEL="$2"
+ shift
+ ;;
+
+ *)
+ die "Unrecognized argument: $1"
+ ;;
+ esac
+ shift
+done
+
+[ -z "$IP" ] && die "You must specify camera IP address (--ip)."
+[ -z "$PORT" ] && die "Port can't be empty."
+[ -z "$NAME" ] && die "You must specify camera name (--name)."
+[ -z "$USER" ] && die "You must specify username (--user)."
+[ -z "$PASSWORD" ] && die "You must specify username (--password)."
+validate_channel "$CHANNEL"
+
+if [ ! -d "${OUTDIR}/${NAME}" ]; then
+ mkdir "${OUTDIR}/${NAME}" || die "Failed to create ${OUTDIR}/${NAME}!"
+fi
+
+if [ "$DEBUG" = "1" ]; then
+ ffmpeg_args="-v info"
+else
+ ffmpeg_args="-nostats -loglevel error"
+fi
+
+ffmpeg $ffmpeg_args -i rtsp://${USER}:${PASSWORD}@${IP}:${PORT}/Streaming/Channels/${CHANNEL} \
+ -c:v copy -c:a copy -bufsize 1835k \
+ -pix_fmt yuv420p \
+ -flags -global_header -hls_time 5 -hls_list_size 6 -hls_wrap 5 \
+ ${OUTDIR}/${NAME}/live.m3u8