From eda90cb759da69e8b36fe3fefe989aae3bc441ec Mon Sep 17 00:00:00 2001 From: Helias Date: Tue, 6 Sep 2022 22:45:11 +0200 Subject: [PATCH 1/5] feat: add README and useful bash scripts --- README.md | 34 ++++++++++++++++++++++++++++++++++ clean_records.sh | 2 ++ download.sh | 16 ++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 README.md create mode 100644 clean_records.sh create mode 100644 download.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..bed322e --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +## Useful scripts + +This repository contains different bash scripts and commands for reolink camera. + +## download.sh + +This script uses `ffmpeg` to download via RTSP the video and audio from your camera saving it in the MP4 format, the name will start with the `date` of the day (ex. `2022-08-26--22-00-00-capture-0000.mp4`) and a file will be recorded and saved every `$TIME` seconds. +The name of the files starts with a date to make it easier the management of the files, like removing easily all the records of a specific month, day or year. + +### Why ffmpeg? + +I tried **openRTSP** ❌ but half of the video in the MP4 format is without audio and I don't know why. + +example: + +``` +openRTSP -D 1 -c -B 10000000 -b 10000000 -q -Q -F cam_eight -d 28800 -P 10 -t rtsp://"admin":"mypassword"@192.168.0.176:554 +``` + +source of command and explanation: https://superuser.com/questions/766437/capture-rtsp-stream-from-ip-camera-and-store + +I tried **VLC** ❌ but I got some issues saving the files with the audio and managing it. + +example command: + +``` +cvlc rtsp://admin:password@192.168.0.176:554//h264Preview_01_main --sout=file/ts:mystream.mpg +``` + +FFmpeg was the best, so I chose it. ✅ + +## clean_record.sh + +This script deletes all the records inside a `tmp` directory of the previous month. diff --git a/clean_records.sh b/clean_records.sh new file mode 100644 index 0000000..1b17729 --- /dev/null +++ b/clean_records.sh @@ -0,0 +1,2 @@ +LAST_MONTH=$(date --date='-1 month' +'%Y-%m') +rm "tmp/$LAST_MONTH-"* diff --git a/download.sh b/download.sh new file mode 100644 index 0000000..ffc5b3e --- /dev/null +++ b/download.sh @@ -0,0 +1,16 @@ +USERNAME="admin" +PASSWORD="mypassword" +TIME=60 # seconds +IP="192.168.1.197" +PORT=554 + +ffmpeg -i rtsp://$USERNAME:$PASSWORD@$IP:$PORT/h264Preview_01_main \ + -c copy \ + -map 0 \ + -reset_timestamps 1 \ + -f segment \ + -segment_time $TIME \ + -strftime 1 \ + -segment_format mp4 \ + "%Y-%m-%d--%H-%M-%S--capture-%04d.mp4" + From fa145c9a05f2557330aefd55e9d2080e0f8114c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefano=20Borz=C3=AC?= Date: Fri, 9 Sep 2022 22:00:41 +0200 Subject: [PATCH 2/5] Update README.md Co-authored-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bed322e..86290a5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Useful scripts +## Reolink Camera Utility Scripts This repository contains different bash scripts and commands for reolink camera. From 1e254cefacb11a57a1cedc29798a2cb26ab74c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefano=20Borz=C3=AC?= Date: Fri, 9 Sep 2022 22:00:47 +0200 Subject: [PATCH 3/5] Update README.md Co-authored-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86290a5..86a35a4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This repository contains different bash scripts and commands for reolink camera. -## download.sh +### Download RTSP Stream This script uses `ffmpeg` to download via RTSP the video and audio from your camera saving it in the MP4 format, the name will start with the `date` of the day (ex. `2022-08-26--22-00-00-capture-0000.mp4`) and a file will be recorded and saved every `$TIME` seconds. The name of the files starts with a date to make it easier the management of the files, like removing easily all the records of a specific month, day or year. From cacf6a5acf844010c6ff1b3596ed3858f55a1ec0 Mon Sep 17 00:00:00 2001 From: Helias Date: Sun, 11 Sep 2022 20:23:45 +0200 Subject: [PATCH 4/5] feat: add flags to download.sh, improve README --- README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++------- download.sh | 22 +++++++++++++------ 2 files changed, 69 insertions(+), 14 deletions(-) mode change 100644 => 100755 download.sh diff --git a/README.md b/README.md index bed322e..b11956f 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,24 @@ This repository contains different bash scripts and commands for reolink camera. -## download.sh +### Requirements -This script uses `ffmpeg` to download via RTSP the video and audio from your camera saving it in the MP4 format, the name will start with the `date` of the day (ex. `2022-08-26--22-00-00-capture-0000.mp4`) and a file will be recorded and saved every `$TIME` seconds. -The name of the files starts with a date to make it easier the management of the files, like removing easily all the records of a specific month, day or year. +These scripts use **ffmpeg**, to install it you can: + +```bash +apt install ffmpeg # linux debian-based +brew install ffmpeg # mac +``` -### Why ffmpeg? +If you are using Windows you can download it from [here](https://ffmpeg.org/download.html). -I tried **openRTSP** ❌ but half of the video in the MP4 format is without audio and I don't know why. +
+ Why ffmpeg? + I tried **openRTSP** ❌ but half of the video in the MP4 format is without audio and I don't know why. example: -``` +```bash openRTSP -D 1 -c -B 10000000 -b 10000000 -q -Q -F cam_eight -d 28800 -P 10 -t rtsp://"admin":"mypassword"@192.168.0.176:554 ``` @@ -23,12 +29,51 @@ I tried **VLC** ❌ but I got some issues saving the files with the audio and ma example command: -``` +```bash cvlc rtsp://admin:password@192.168.0.176:554//h264Preview_01_main --sout=file/ts:mystream.mpg ``` FFmpeg was the best, so I chose it. ✅ -## clean_record.sh +
+ +--- + +### Usage + +Download and use the script: + +```bash +git clone https://github.com/ReolinkCameraAPI/scripts +cd scripts +``` + +### download.sh + +How to use it: + +```bash +chmod +x download.sh +./download.sh -u myusername -p mypassowrd -i 192.168.1.197 -t 60 -n 554 -o tmp +``` + +- `-u` username of your camera +- `-p` password of your camera +- `-i` camera local IP address +- `-t` is the time in seconds that any file will contain (default value 60) +- `-n` is the port (default value 554) +- `-o` output directory path (default `.`, the current directory) + +To stop the execution you can type `Ctrl + C`. + +This script uses `ffmpeg` to download via RTSP the video and audio from your camera saving it in the MP4 format, the name will start with the `date` of the day (ex. `2022-08-26--22-00-00-capture-0000.mp4`) and a file will be recorded and saved every `$TIME` seconds. +The name of the files starts with a date to make it easier the management of the files, like removing easily all the records of a specific month, day or year. + +### clean_record.sh + +```bash +chmod +x clean_record.sh +./clean_record.sh +``` This script deletes all the records inside a `tmp` directory of the previous month. diff --git a/download.sh b/download.sh old mode 100644 new mode 100755 index ffc5b3e..8f18c3b --- a/download.sh +++ b/download.sh @@ -1,8 +1,19 @@ -USERNAME="admin" -PASSWORD="mypassword" -TIME=60 # seconds -IP="192.168.1.197" +# default parameters value +TIME=60 PORT=554 +OUTPUT_PATH="." + +while getopts u:p:i:t:n:o: flag +do + case "${flag}" in + u) USERNAME=${OPTARG};; + p) PASSWORD=${OPTARG};; + i) IP=${OPTARG};; + t) TIME=${OPTARG};; + n) PORT=${OPTARG};; + o) OUTPUT_PATH=${OPTARG};; + esac +done ffmpeg -i rtsp://$USERNAME:$PASSWORD@$IP:$PORT/h264Preview_01_main \ -c copy \ @@ -12,5 +23,4 @@ ffmpeg -i rtsp://$USERNAME:$PASSWORD@$IP:$PORT/h264Preview_01_main \ -segment_time $TIME \ -strftime 1 \ -segment_format mp4 \ - "%Y-%m-%d--%H-%M-%S--capture-%04d.mp4" - + "$OUTPUT_PATH/%Y-%m-%d--%H-%M-%S--capture-%04d.mp4" From b59bf4cee54a34216214e9713f6bfc9cfab92679 Mon Sep 17 00:00:00 2001 From: Helias Date: Tue, 13 Sep 2022 09:47:22 +0200 Subject: [PATCH 5/5] chore: add options in clean records.sh --- clean_records.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/clean_records.sh b/clean_records.sh index 1b17729..67ef7b6 100644 --- a/clean_records.sh +++ b/clean_records.sh @@ -1,2 +1,14 @@ -LAST_MONTH=$(date --date='-1 month' +'%Y-%m') -rm "tmp/$LAST_MONTH-"* +PATH="tmp/" +MONTHES=1 + +while getopts p:m: flag +do + case "${flag}" in + p) PATH=${OPTARG};; + m) MONTHES=${OPTARG};; + esac +done + + +LAST_MONTH=$(date --date='-$MONTHES month' +'%Y-%m') +rm "$PATH$LAST_MONTH-"*