A Node.js script that demonstrates PTZ (Pan, Tilt, Zoom) control of an Amcrest security camera using the ONVIF protocol, enhanced with AI vision capabilities using Ollama and Llama 3.2 Vision model.
- PTZ Control: Full pan, tilt, zoom control of your Amcrest camera
- Personality Gestures: "Yes" and "No" gestures with realistic movements
- AI Vision Analysis: Real-time object detection and scene analysis
- Audio Capability Detection: Checks for microphone and speaker support
- RTSP Stream Integration: Captures and analyzes video frames
- Node.js (version 14 or higher)
- An Amcrest security camera with ONVIF support
- Camera connected to your network with known IP address
- Ollama installed and running locally (for local AI)
- Llama 3.2 Vision model installed in Ollama (for local AI)
- OpenAI API key (optional, for ChatGPT integration)
The application uses environment variables for configuration. Copy .env.example to .env and configure:
CAMERA_HOSTNAME- Your camera's IP addressCAMERA_USERNAME- Camera username (usually "admin")CAMERA_PASSWORD- Camera passwordCAMERA_PORT- ONVIF port (usually 80)
AI_PROVIDER- "ollama" or "chatgpt" (default: "ollama")OPENAI_API_KEY- Required if using ChatGPTCAMERA_AUDIO_CHANNEL- Audio channel (default: 1)CAMERA_AUDIO_VOLUME- Speaker volume 0-100 (default: 80)WAKE_WORD_PHRASE- Wake word to trigger voice interaction (default: "jarvis")
-
Install dependencies:
npm install
-
Configure environment variables:
# Copy the example configuration file cp .env.example .env # Edit with your camera settings nano .env
-
Install Ollama (for local AI):
# macOS/Linux curl -fsSL https://ollama.ai/install.sh | sh # Start Ollama ollama serve
-
Install Llama 3.2 Vision model:
ollama pull llama3.2-vision
-
Configure environment variables:
# Copy the example configuration file cp .env.example .env # Edit the .env file with your camera settings nano .env
Update the following values in your
.envfile:# Camera Configuration (Required) CAMERA_HOSTNAME=192.168.0.42 # Your camera's IP address CAMERA_USERNAME=admin # Your camera's username CAMERA_PASSWORD=your_password # Your camera's password CAMERA_PORT=80 # ONVIF port (usually 80 or 8080) # AI Configuration AI_PROVIDER=ollama # Use "ollama" or "chatgpt" # ChatGPT (Required if using ChatGPT) OPENAI_API_KEY=your_api_key # Your OpenAI API key
Run the enhanced PTZ demo with AI vision:
npm startOr run directly:
node index.js- Never commit your
.envfile - it contains sensitive information - Use strong passwords for your camera
- Keep your API keys secure - especially OpenAI API keys
- Consider using a dedicated network for your camera
- Regularly update your camera firmware and dependencies
This project is licensed under the MIT License - see the LICENSE file for details.
The script will:
- Connect to your Amcrest camera using ONVIF
- Initialize Ollama and check for Llama 3.2 Vision model
- Display camera information (manufacturer, model, etc.)
- Check audio capabilities (microphones, speakers)
- Get the RTSP stream URL for video streaming
- Start AI Vision Analysis - analyzes video frames every 5 seconds
- Execute a sequence of PTZ movements with personality gestures
- Continue AI vision analysis after demo completion
- Captures frames from RTSP stream every 5 seconds
- Analyzes images using Llama 3.2 Vision model
- Provides detailed descriptions of what the camera sees
- Focuses on people, objects, activities, and security concerns
You can adjust AI vision settings in the AI_CONFIG object:
const AI_CONFIG = {
model: 'llama3.2-vision',
analysisInterval: 5000, // Analyze every 5 seconds
confidenceThreshold: 0.7,
maxRetries: 3
};- Pan (X-axis): -1.0 (left) to +1.0 (right)
- Tilt (Y-axis): -1.0 (down) to +1.0 (up)
- Zoom: -1.0 (zoom out) to +1.0 (zoom in)
The camera demonstrates personality through:
- "Yes" Gesture: Nods up and down (tilt movements)
- "No" Gesture: Shakes left and right (pan movements)
- Verify your camera's IP address is correct
- Ensure the camera supports ONVIF
- Check that the username and password are correct
- Try different ports (80, 8080, 554)
- Make sure Ollama is running:
ollama serve - Install the vision model:
ollama pull llama3.2-vision - Check available models:
ollama list
- Some cameras require ONVIF to be enabled in settings
- Check if your camera model supports PTZ functionality
- Verify the camera is not in recording mode
- Ensure RTSP stream is accessible
- Check that Ollama is running and accessible
- Verify the vision model is installed
ECONNREFUSED: Camera not reachable or wrong portUnauthorized: Wrong username/passwordNot Found: ONVIF service not availableFailed to connect to Ollama: Ollama not running
Press Ctrl+C to stop the demo at any time. The script will gracefully stop:
- Any ongoing camera movements
- AI vision analysis
- RTSP stream processing
onvif: ONVIF protocol implementation for Node.jsollama: JavaScript client for Ollama AI modelsnode-rtsp-stream: RTSP stream processingjimp: Image processing for frame capture
MIT