summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-05-22 23:38:33 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-05-23 00:35:46 +0300
commit225ad92fdac725060d0ecb0c82a046653782d182 (patch)
tree8b7759c514d3774bc6c2dfc85ba9e8ed066651f8 /tools
parent02f676029a5014e822598947b0ac2f12d183a7f1 (diff)
support street cameras
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