summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtools/ipcam_capture.sh111
1 files changed, 60 insertions, 51 deletions
diff --git a/tools/ipcam_capture.sh b/tools/ipcam_capture.sh
index d1c13c2..91b7f48 100755
--- a/tools/ipcam_capture.sh
+++ b/tools/ipcam_capture.sh
@@ -8,14 +8,15 @@ DEBUG=0
CHANNEL=1
FORCE_UDP=0
FORCE_TCP=0
+EXTENSION="mp4"
die() {
- echo >&2 "error: $@"
- exit 1
+ echo >&2 "error: $@"
+ exit 1
}
usage() {
- cat <<EOF
+ cat <<EOF
usage: $PROGNAME [OPTIONS] COMMAND
Options:
@@ -29,54 +30,62 @@ Options:
--channel 1|2
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|--creds|--outdir)
- _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 | --creds | --outdir)
+ _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
+ ;;
+
+ --mov)
+ EXTENSION="mov"
+ ;;
+
+ --mpv)
+ EXTENSION="mpv"
+ ;;
+
+ *)
+ die "Unrecognized argument: $1"
+ ;;
+ esac
+ shift
done
[ -z "$OUTDIR" ] && die "You must specify output directory (--outdir)."
@@ -86,25 +95,25 @@ done
validate_channel "$CHANNEL"
if [ ! -d "${OUTDIR}" ]; then
- mkdir "${OUTDIR}" || die "Failed to create ${OUTDIR}/${NAME}!"
- echo "Created $OUTDIR."
+ mkdir "${OUTDIR}" || die "Failed to create ${OUTDIR}/${NAME}!"
+ echo "Created $OUTDIR."
fi
args=
if [ "$DEBUG" = "1" ]; then
- args="$args -v info"
+ args="$args -v info"
else
- args="$args -nostats -loglevel warning"
+ args="$args -nostats -loglevel warning"
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
[ ! -z "$CREDS" ] && CREDS="${CREDS}@"
ffmpeg $args -i rtsp://${CREDS}${IP}:${PORT}/Streaming/Channels/${CHANNEL} \
- -c copy -f segment -strftime 1 -segment_time 00:10:00 -segment_atclocktime 1 \
- "$OUTDIR/record_%Y-%m-%d-%H.%M.%S.mp4"
+ -c copy -f segment -strftime 1 -segment_time 00:10:00 -segment_atclocktime 1 \
+ "$OUTDIR/record_%Y%m-%d-%H.%M.%S.${EXTENSION}"