Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add README and useful bash scripts #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
## Reolink Camera Utility Scripts

This repository contains different bash scripts and commands for reolink camera.

Helias marked this conversation as resolved.
Show resolved Hide resolved
### Requirements

These scripts use **ffmpeg**, to install it you can:

```bash
apt install ffmpeg # linux debian-based
brew install ffmpeg # mac
```

If you are using Windows you can download it from [here](https://ffmpeg.org/download.html).

<details>
<summary>Why ffmpeg?</summary>
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
```

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:

```bash
cvlc rtsp://admin:[email protected]:554//h264Preview_01_main --sout=file/ts:mystream.mpg
```

FFmpeg was the best, so I chose it. ✅

</details>

---

### 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.
14 changes: 14 additions & 0 deletions clean_records.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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-"*
26 changes: 26 additions & 0 deletions download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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 \
Helias marked this conversation as resolved.
Show resolved Hide resolved
-c copy \
-map 0 \
-reset_timestamps 1 \
-f segment \
-segment_time $TIME \
-strftime 1 \
-segment_format mp4 \
"$OUTPUT_PATH/%Y-%m-%d--%H-%M-%S--capture-%04d.mp4"