summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-05-29 21:10:38 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-05-29 21:10:38 +0300
commitad4565f784041b9901d69c9bda032c29bbbdfd8c (patch)
tree9408a6594559e781dafb71b98bf6a245009297f5 /tools
parent8b2088103a74e616ca82fe043de55cb7ed58e329 (diff)
ipcam_rtsp2hls.sh: reformat using tabs, add --custom-path
Diffstat (limited to 'tools')
-rwxr-xr-xtools/ipcam_rtsp2hls.sh137
1 files changed, 75 insertions, 62 deletions
diff --git a/tools/ipcam_rtsp2hls.sh b/tools/ipcam_rtsp2hls.sh
index 64e9121..324a17c 100755
--- a/tools/ipcam_rtsp2hls.sh
+++ b/tools/ipcam_rtsp2hls.sh
@@ -11,76 +11,83 @@ DEBUG=0
CHANNEL=1
FORCE_UDP=0
FORCE_TCP=0
+CUSTOM_PATH=
die() {
- echo >&2 "error: $@"
- exit 1
+ echo >&2 "error: $@"
+ exit 1
}
usage() {
- cat <<EOF
+ 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
- --force-tcp
- --force-udp
- --channel 1|2
+ --ip camera IP
+ --port RTSP port (default: 554)
+ --name camera name (chunks will be stored under $OUTDIR/{name}/)
+ --user
+ --password
+ --debug
+ --force-tcp
+ --force-udp
+ --channel 1|2
+ --custom-path PATH
EOF
- exit
+ exit
}
validate_channel() {
- local c="$1"
- case "$c" in
- 1|2)
- :
- ;;
- *)
- die "Invalid channel"
- ;;
- esac
+ 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
- ;;
-
- --force-tcp)
- FORCE_TCP=1
- ;;
-
- --force-udp)
- FORCE_UDP=1
- ;;
-
- --channel)
- CHANNEL="$2"
- shift
- ;;
-
- *)
- die "Unrecognized argument: $1"
- ;;
- esac
- shift
+ case "$1" in
+ --ip|--port|--name|--user|--password)
+ _var=${1:2}
+ _var=${_var^^}
+ printf -v "$_var" '%s' "$2"
+ shift
+ ;;
+
+ --debug)
+ DEBUG=1
+ ;;
+
+ --force-tcp)
+ FORCE_TCP=1
+ ;;
+
+ --force-udp)
+ FORCE_UDP=1
+ ;;
+
+ --channel)
+ CHANNEL="$2"
+ shift
+ ;;
+
+ --custom-path)
+ CUSTOM_PATH="$2"
+ shift
+ ;;
+
+ *)
+ die "Unrecognized argument: $1"
+ ;;
+ esac
+ shift
done
[ -z "$IP" ] && die "You must specify camera IP address (--ip)."
@@ -91,24 +98,30 @@ done
validate_channel "$CHANNEL"
if [ ! -d "${OUTDIR}/${NAME}" ]; then
- mkdir "${OUTDIR}/${NAME}" || die "Failed to create ${OUTDIR}/${NAME}!"
+ mkdir "${OUTDIR}/${NAME}" || die "Failed to create ${OUTDIR}/${NAME}!"
fi
args=
if [ "$DEBUG" = "1" ]; then
- args="-v info"
+ args="-v info"
else
- args="-nostats -loglevel error"
+ args="-nostats -loglevel error"
fi
if [ "$FORCE_TCP" = "1" ]; then
- args="$args -rtsp_transport tcp"
+ args="$args -rtsp_transport tcp"
elif [ "$FORCE_UDP" = "1" ]; then
- args="$args -rtsp_transport udp"
+ args="$args -rtsp_transport udp"
fi
-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 2 -hls_list_size 3 -hls_flags delete_segments \
- ${OUTDIR}/${NAME}/live.m3u8
+if [ -z "$CUSTOM_PATH" ]; then
+ PATH="/Streaming/Channels/${CHANNEL}"
+else
+ PATH="$CUSTOM_PATH"
+fi
+
+ffmpeg $args -i "rtsp://${USER}:${PASSWORD}@${IP}:${PORT}${CUSTOM_PATH}" \
+ -c:v copy -c:a copy -bufsize 1835k \
+ -pix_fmt yuv420p \
+ -flags -global_header -hls_time 2 -hls_list_size 3 -hls_flags delete_segments \
+ ${OUTDIR}/${NAME}/live.m3u8