Skip to main content

Overview

Ant Media Server can pull streams from IP cameras and re-stream them to viewers. This feature supports:
  • RTSP Camera Sources - Pull streams from any RTSP-enabled camera
  • ONVIF Protocol - Auto-discover and configure ONVIF cameras
  • PTZ Control - Pan, tilt, and zoom control for compatible cameras
  • Multiple Cameras - Manage hundreds of camera streams
  • Recording & Transcoding - Record camera feeds and create adaptive streams
IP camera streaming workflow

Supported Protocols

RTSP (Real-Time Streaming Protocol)

Most common protocol for IP cameras:
  • RTSP/TCP - Reliable, works through firewalls
  • RTSP/UDP - Lower latency, may have packet loss
  • RTSP/HTTP - Tunnels through port 80/443
Example RTSP URLs:
rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0
rtsp://192.168.1.101/stream1
rtsp://camera.example.com:8554/live.sdp

ONVIF (Open Network Video Interface Forum)

Standardized protocol for IP cameras:
  • Auto-discovery of cameras on network
  • Retrieve camera capabilities
  • Get RTSP stream URLs automatically
  • Control PTZ (Pan-Tilt-Zoom)
  • Configure camera settings

ONVIF Integration

Ant Media Server includes a full ONVIF client implementation:
public class OnvifCamera implements IOnvifCamera {
    public static final int CONNECTION_SUCCESS = 0;
    public static final int CONNECT_ERROR = -1;
    public static final int AUTHENTICATION_ERROR = -2;
    
    private OnvifDevice nvt;
    private PtzDevices ptzDevices;
    private List<Profile> profiles;
    private String profileToken;
    
    @Override
    public int connect(String address, String username, String password) {
        // Extract IP from address (may include http:// or https://)
        String camIP = getIPAddress(address);
        String protocol = getProtocol(address);
        
        nvt = new OnvifDevice(camIP, protocol, username, password);
        nvt.getSoap().setLogging(false);
        
        // Get device capabilities
        nvt.getDevices().getCapabilities().getDevice();
        nvt.getDevices().getServices(false);
        
        // Initialize PTZ if available
        ptzDevices = nvt.getPtz();
        profiles = nvt.getDevices().getProfiles();
        
        // Find profile with PTZ support
        for (Profile profile : profiles) {
            if (profile.getPTZConfiguration() != null) {
                profileToken = profile.getToken();
                break;
            }
        }
        
        return CONNECTION_SUCCESS;
    }
    
    @Override
    public String getRTSPStreamURI() {
        return nvt.getMedia().getRTSPStreamUri(profileToken);
    }
}

Connection Methods

The ONVIF client supports both HTTP and HTTPS:
public String getProtocol(String address) {
    if (address.startsWith("http://")) {
        return "http";
    } else if (address.startsWith("https://")) {
        return "https";  
    }
    return null;
}

Adding IP Cameras

Via Web Panel

1

Navigate to Streams

Go to LiveApp → Streams in the web dashboard
2

Add IP Camera

Click New Live Stream → IP Camera
3

Enter Camera Details

  • Name: Friendly name for the camera
  • RTSP URL: Full RTSP URL with credentials
  • ONVIF Address: (Optional) ONVIF device address
  • Username: Camera admin username
  • Password: Camera admin password
4

Configure Options

  • Enable recording if needed
  • Set up transcoding profiles
  • Configure preview generation
5

Start Streaming

Click Create - the stream will start automatically

Via REST API

Add a camera programmatically:
curl -X POST "http://localhost:5080/LiveApp/rest/v2/broadcasts/create" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Front Door Camera",
    "type": "ipCamera",
    "ipAddr": "rtsp://admin:[email protected]:554/stream1",
    "streamId": "camera-front-door"
  }'

PTZ Control

Control pan, tilt, and zoom on ONVIF cameras:

PTZ Movement Types

Move continuously until stop command:
public boolean moveContinuous(float x, float y, float zoom) {
    return ptzDevices.continuousMove(profileToken, x, y, zoom);
}
Parameters:
  • x: Pan speed (-1.0 to 1.0)
  • y: Tilt speed (-1.0 to 1.0)
  • zoom: Zoom speed (-1.0 to 1.0)

REST API for PTZ

# Continuous move (pan right)
curl -X POST "http://localhost:5080/LiveApp/rest/v2/broadcasts/{streamId}/ptz/move" \
  -H "Content-Type: application/json" \
  -d '{"x": 0.5, "y": 0, "zoom": 0}'

# Stop movement  
curl -X POST "http://localhost:5080/LiveApp/rest/v2/broadcasts/{streamId}/ptz/stop"

Stop Movement

public boolean moveStop() {
    return ptzDevices.stopMove(profileToken);
}

Camera Settings

Image Settings

Adjust brightness, contrast, etc.:
public boolean setBrightness(float brightness) {
    ImagingSettings20 imageSettings = nvt.getImaging()
                                        .getImagingSettings(profileToken);
    imageSettings.setBrightness(brightness);
    return nvt.getImaging().setImagingSettings(profileToken, imageSettings);
}
Available settings:
  • Brightness - 0.0 to 100.0
  • Contrast - 0.0 to 100.0
  • Saturation - 0.0 to 100.0
  • Sharpness - 0.0 to 100.0
  • Focus Mode - Auto / Manual

Get Camera Time

public java.util.Date getTime() {
    return nvt.getDate();
}

Streaming Configuration

Stream Pull Settings

Configure how AMS pulls from cameras:
{
  "ipCameraPullPeriod": 10000,
  "ipCameraRestartPeriod": 30000,  
  "ipCameraAutoStart": true
}
SettingDescriptionDefault
ipCameraPullPeriodHow often to check camera availability (ms)10000
ipCameraRestartPeriodWait time before reconnecting after failure (ms)30000
ipCameraAutoStartAuto-start camera streams on server startuptrue

Transport Protocol

Choose between TCP and UDP for RTSP:
{
  "rtspPullTransportType": "tcp"
}
Options:
  • tcp - More reliable, works through NAT/firewalls
  • udp - Lower latency, may drop packets
  • http - Tunnel through HTTP (port 80/443)

Recording Camera Streams

Enable recording for camera streams:
curl -X PUT "http://localhost:5080/LiveApp/rest/v2/broadcasts/{streamId}" \
  -H "Content-Type: application/json" \
  -d '{
    "mp4Enabled": 1,
    "hlsEnabled": 1
  }'
Use scheduled recording to save storage by only recording during specific hours (e.g., business hours).

Multi-Camera Management

Bulk Operations

Manage multiple cameras efficiently:
curl -X POST "http://localhost:5080/LiveApp/rest/v2/broadcasts/bulk/start" \
  -H "Content-Type: application/json" \
  -d '{"streamIds": ["camera-1", "camera-2", "camera-3"]}'

Camera Groups

Organize cameras by location or purpose:
{
  "name": "Building A Cameras",
  "streamIds": [
    "camera-entrance",
    "camera-lobby",  
    "camera-parking"
  ]
}

Playback Options

HLS Streaming

Camera feeds available as HLS:
<video id="camera" controls>
  <source src="http://localhost:5080/LiveApp/streams/camera-front-door.m3u8" type="application/x-mpegURL">
</video>

<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script>
  const video = document.getElementById('camera');
  const hls = new Hls();
  hls.loadSource('http://localhost:5080/LiveApp/streams/camera-front-door.m3u8');
  hls.attachMedia(video);
</script>

WebRTC Playback

Ultra-low latency viewing:
const webRTCAdaptor = new WebRTCAdaptor({
  websocket_url: 'ws://localhost:5080/LiveApp/websocket',
  streamId: 'camera-front-door',
  callback: (info, obj) => {
    if (info === 'play_started') {
      console.log('Camera stream started');
    }
  }
});

webRTCAdaptor.play('camera-front-door');

Troubleshooting

Common causes:
  • Wrong IP address or port
  • Incorrect username/password
  • Camera not on same network
  • Firewall blocking RTSP (port 554)
Debugging:
# Test RTSP connection
ffplay rtsp://admin:[email protected]:554/stream1

# Check network connectivity
ping 192.168.1.100
telnet 192.168.1.100 554
Possible issues:
  • Network instability
  • Camera firmware issues
  • Resource limits on AMS server
  • TCP/UDP protocol mismatch
Solutions:
  • Increase ipCameraRestartPeriod
  • Switch between TCP/UDP transport
  • Check camera logs for errors
  • Monitor server resources (CPU/memory)
Reasons:
  • Camera doesn’t support ONVIF
  • ONVIF disabled in camera settings
  • Different subnet
  • Authentication required
Fix:
  • Verify ONVIF support in camera specs
  • Enable ONVIF in camera web interface
  • Use direct RTSP URL instead
  • Provide username/password in connection
Check:
  • Camera supports PTZ
  • ONVIF connection established
  • Correct profile selected
  • PTZ not locked by another client
Test:
# Verify PTZ capability
curl "http://localhost:5080/LiveApp/rest/v2/broadcasts/{streamId}/onvif/capabilities"

Best Practices

Use Substreams

Configure cameras to provide multiple streams. Use main stream for recording, substream for live viewing to reduce bandwidth.

Secure Credentials

Never hardcode camera passwords. Use environment variables or secure credential storage.

Monitor Health

Set up alerts for camera disconnections. Use webhooks to get notified when streams fail.

Optimize Storage

Use scheduled recording and configure retention policies to manage storage for camera recordings.

Build docs developers (and LLMs) love