summaryrefslogtreecommitdiff
path: root/tools/ipcam_rtsp2hls.sh
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-05-24 22:16:33 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-05-24 22:16:35 +0300
commit00427d1b252474abde7de40588688ec2cea99185 (patch)
tree44f8aa2c1d24da2ed8c08c396e0ecfc57108c2a9 /tools/ipcam_rtsp2hls.sh
parentb8aa98899f14d90326bd10259aa69a0b4d6a139e (diff)
ipcam changes
Diffstat (limited to 'tools/ipcam_rtsp2hls.sh')
-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