Skip to content
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
51 changes: 3 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,7 @@
# RTSP Timelapse

Connects to an RTSP stream, takes a photo, and stitches it together to make a timelapse.
Then sends a the timelapse video to your favourite service [using Apprise](https://github.com/caronc/apprise).
Same as : https://github.com/AlanCunningham/rtsp-timelapse

## Hardware
- Personally, I have this running on a Raspberry Pi (any model will probably do)
- An IP camera that supports RTSP
But i replace ffmpeg with cv2

## Installation
- Create a python3 virtual environment and install the project's requirements:
```
$ python3 -m venv rtsp_timelapse
$ source rtsp_timelapse/bin/activate
(rtsp_timelapse) $ pip install -r requirements.txt
```
- You will also need [ffmpeg](https://ffmpeg.org/) installed on your machine. This can usually be
installed using a package manager. For example:
```
$ sudo apt-get install ffmpeg
```
- Open config.py and enter the camera's
- RTSP username
- RTSP password
- IP address
- Also in config.py, enter where you want your timelapse videos to be sent. See
[Apprise's github page](https://github.com/caronc/apprise) for examples. An
example for Telegram and Discord would look something like this:
```
# The list of services to notify
apprise_services = [
"tgram://bottoken/ChatID",
"discord://webhook_id/webhook_token",
]
```
- You should now be able to start the program:
```
(rtsp_timelapse) $ python main.py
```

# Creating the timelapses
The script is intended to be run regularly on a cronjob. It will connect to the IP camera, take a photo
and save the image to the **input** folder.

Once a week's worth of photos have been taken, the script will stitch the photos together using
[ffmpeg](https://ffmpeg.org/) and save the video to the **output** directory. Once saved, it will send the videos to
the Apprise services set in config.py. The images used to create the timelapse will then be
deleted.

Two copies of the timelapse will be created in the **output** directory.
- normal_timelapse - This contains timelapses at the default framerate - 24fps
- forced_fps - This contains timelapses at a framerate of 60fps
If you want to access an RTSP stream redirected from an Internet router, ffmpeg doesn't understand the redirection protocol (UDP/TCP/NAT).
11 changes: 10 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import subprocess
from datetime import datetime

import cv2

images_directory = "input"
timelapse_directory = "output"
Expand Down Expand Up @@ -64,6 +64,14 @@ def main():
rtsp_ip_address = config.rtsp_ip_address
rtsp_path = f"rtsp://{rtsp_username}:{rtsp_password}@{rtsp_ip_address}/stream1"


#Use cv2 insted of ffmpeg to be compatible with an RTSP flow redirected following a port opening
cap = cv2.VideoCapture(rtsp_path)
ret, frame = cap.read()
cv2.imwrite(f"{images_directory}/{datetime.now().strftime('%Y%m%d-%H%M%S')}.png", frame)
cap.release()

"""
# Use ffmpeg to connect to the rtsp stream and save 1 frame
# ffmpeg -i <stream> -vframes 1 <output>
subprocess.run(
Expand All @@ -76,6 +84,7 @@ def main():
f"{images_directory}/{datetime.now().strftime('%Y%m%d-%H%M%S')}.png",
]
)
"""

# Only create a timelapse once we have a weeks worth of photos
image_files = glob.glob1(images_directory, "*.png")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ typed-ast==1.5.4
typing-extensions==4.4.0
urllib3==1.26.12
zipp==3.10.0
opencv-python