A lightweight CLI tool for recording RTSP video streams to MP4 files
- RTSP Recording — Capture any RTSP stream to MP4 format
- Timelapse Mode — Condense hours of footage into seconds (e.g., 1 hour → 10 seconds)
- Flexible Stop Conditions — Stop by duration, file size, or manual interrupt (Ctrl+C)
- Real-time Progress — Live display of recording stats
- Auto-retry — Automatically reconnects on network errors
- Configuration — YAML config, CLI flags, or environment variables
- Lightweight — Minimal CPU usage with stream copy (no re-encoding for normal recordings)
git clone https://github.com/fieu/rtsp-recorder.git
cd rtsp-recorder
go build -o rtsp-recorder .# Record for 30 minutes
./rtsp-recorder record --duration 30m rtsp://camera.local/stream
# Output: recording_2025-04-02-14-30-00.mp4# Record 1 hour, output 10-second timelapse at 360x speed
./rtsp-recorder record --duration 1h --timelapse 10s rtsp://camera.local/stream
[INFO] Timelapse: 360x speed (1h -> 10s)
Recording: 30m elapsed | Output: ~5s | 360xCopy the example config file as a starting point:
cp rtsp-recorder.example.yml rtsp-recorder.ymlThen edit rtsp-recorder.yml with your settings:
url: rtsp://192.168.1.100:554/stream
duration: 1h
max_file_size: 1024
retry_attempts: 3Then simply run:
./rtsp-recorder recordrtsp-recorder record [RTSP_URL] [flags]
Flags:
-u, --url string RTSP stream URL
-d, --duration duration Recording duration (e.g., 30m, 1h, 2h30m)
-s, --max-file-size int Maximum file size in MB before stopping
-l, --timelapse duration Target output duration for timelapse (e.g., 10s)
-r, --retry-attempts int Number of retry attempts on connection failure (default 3)
-f, --ffmpeg-path string Path to ffmpeg binary (optional)
-t, --filename-template string Output filename template (optional)
-h, --help Help for record
Examples:
# Basic recording
rtsp-recorder record rtsp://camera.local/stream
# With duration and file size limits
rtsp-recorder record --duration 1h --max-file-size 500 rtsp://192.168.1.100:554/stream
# Timelapse (1 hour → 10 seconds)
rtsp-recorder record --duration 1h --timelapse 10s rtsp://camera.local/stream
# Short flags
rtsp-recorder record -d 30m -s 256 rtsp://camera.local/stream
Configuration precedence (highest to lowest):
- CLI flags
- Environment variables (
RTSP_RECORDER_*) - Config file (
rtsp-recorder.yml) - Defaults
# rtsp-recorder.yml
url: rtsp://192.168.1.100:554/stream
duration: 30m
max_file_size: 1024
retry_attempts: 3export RTSP_RECORDER_URL=rtsp://camera.local/stream
export RTSP_RECORDER_DURATION=1h
export RTSP_RECORDER_RETRY_ATTEMPTS=5- Home Security — Record IP camera footage with scheduled duration
- Time-lapse Videos — Create accelerated videos of construction, weather, or nature
- Stream Archiving — Backup live streams for later review
- Monitoring — Continuous recording with automatic rotation
┌─────────────────┐ ┌──────────────┐ ┌─────────────┐
│ CLI (Cobra) │────▶│ Recorder │────▶│ FFmpeg │
└─────────────────┘ └──────────────┘ └─────────────┘
│
▼
┌─────────────────┐
│ Config (Viper) │
└─────────────────┘
go test ./...This project is licensed under the MIT License - see the LICENSE file for details.