Captures screenshots from a password-protected RTSP stream at regular intervals. This is perfect for collecting a series of images over time to create a timelapse video.
You can also run this application inside a Docker container.
It's recommended to pass configuration using environment variables and mount a volume for the screenshots. Use the pre-built image from GHCR:
docker run -d --name rtsp-capture-app \
--restart unless-stopped \
-e RTSP_HOST="<your_rtsp_host>:<port>" \
-e RTSP_PATH="<your_rtsp_path>" \
-e RTSP_USERNAME="<your_username>" \
-e RTSP_PASSWORD="<your_password>" \
-e RTSP_SCHEDULE="*/15 * * * *" \
-v "$(pwd)/screenshots:/app/screenshots" \
ghcr.io/moweme/rtsp-capture:latest # Use the appropriate tag (e.g., latest, develop)Alternatively, you can use Docker Compose. Create a docker-compose.yml file with the following content:
services:
app:
image: ghcr.io/moweme/rtsp-capture:latest # Or specify a different tag like :develop
restart: unless-stopped
environment:
- RTSP_HOST="<your_rtsp_host>:<port>"
- RTSP_PATH="<your_rtsp_path>"
- RTSP_USERNAME="<your_username>"
- RTSP_PASSWORD="<your_password>"
- RTSP_SCHEDULE="*/15 * * * *" # Adjust schedule as needed
volumes:
- ./screenshots:/app/screenshotsDocker images are automatically built and pushed to the GitHub Container Registry (GHCR) for every push to the main and develop branches.
- Main Branch (
latesttag):ghcr.io/moweme/rtsp-capture:latest - Develop Branch (
developtag):ghcr.io/moweme/rtsp-capture:develop
You can pull these images using docker pull ghcr.io/moweme/rtsp-capture:<tag>.
The script requires the RTSP stream URL, username, password, and capture schedule. Configuration is handled in the following order of priority:
- Environment Variables:
RTSP_HOST: The hostname and port of the RTSP stream (e.g.,192.168.1.100:554).RTSP_PATH: The path of the RTSP stream (e.g.,/stream1).RTSP_USERNAME: The username for the RTSP stream.RTSP_PASSWORD: The password for the RTSP stream.RTSP_SCHEDULE: The capture schedule. Can be an integer number of minutes (e.g.,5) or a standard crontab string (e.g.,'*/15 * * * *'for every 15 minutes, or'0 9 * * 1-5'for 9 AM on weekdays).
- Configuration File (
config.yaml): If environment variables are not set, the script looks for aconfig.yamlfile in the same directory.RTSP: host: <your_rtsp_host>:<port> path: <your_rtsp_path> username: <your_username> password: <your_password> # Schedule can be minutes (integer) or crontab string schedule: '*/30 * * * *' # Example: every 30 minutes # schedule: 10 # Example: every 10 minutes
- User Input: If neither environment variables nor a complete
config.yamlfile are found, the script will prompt you to enter the required information during the first run. This information will be saved toconfig.yaml(except for the password if provided via environment variable). The default schedule if none is provided is every 5 minutes (*/5 * * * *).
Run the script from your terminal:
python rtsp_capture.pyThe script will start capturing screenshots according to the defined schedule and save them to a screenshots directory. Press Ctrl+C to stop the script.
- Clone the repository or download the files.
- Install the required Python packages:
(This installs
pip install -r requirements.txt
opencv-python,PyYAML, andcroniter)
If you prefer to build the image locally:
docker build -t rtsp-capture .