Add а camеra: Camera.Add
The method and its parameters
The Camera.Add
method adds a camera with the specified parameters.
string Camera.Add
(uid camera
, StreamsObject streams
, OnvifObject onvif
)
Parameters
uid camera
REQUIRED = camera-uid5065687
– a unique camera identifier within the installation. It’s required parameter.
StreamsObject streams
– sets stream parameters for a camera.
object StreamsObject
AccessObjectstreams.camera-uid5065687-primary.access
– specifies the permission access level to Live and DVR.
enum streams.camera-uid5065687-primary.access.allow
= private
– the parameter specifies the type of access.
stringstreams.camera-uid5065687-primary.access.password
= admin
– the password for authorization.
stringstreams.camera-uid5065687-primary.access.user
=admin
– the name of the authorization user.
arraystreams.camera-uid5065687-primary.access.whitelist
=
["192.168.100.200","192.168.100.201"]
– the list of IP4\IP6 addresses from which access is allowed without authorization.
uidstreams.camera-uid5065687-primary.camera
= camera-uid5065687
– sets a unique camera identifier.
ClusterObjectstreams.camera-uid5065687-primary.cluster
– the configuration of the stream capture in fault-tolerant mode.
stringstreams.camera-uid5065687-primary.cluster.primary
– the hostname of the cluster primary node that constantly captures a stream
DvrObjectstreams.camera-uid5065687-primary.dvr
– defines the parameters of recording and archive storage for a stream.
bytesstreams.camera-uid5065687-primary.dvr.buffer
= 1M
– the size of the internal buffer for caching read and write operations. A larger size reduces the number of disk accesses but increases RAM consumption.
secondsstreams.camera-uid5065687-primary.dvr.duration
=1d
– specifies the DVR storage period in seconds. After this period expires, older recordings are automatically deleted, ensuring continuous storage of new data. The storage period can be adjusted both upwards and downwards.
The following abbreviations can be used in this context: d
– days (example:30d
), h
– hours (example:120h
), m
– minutes (example: 20m
).
boolstreams.camera-uid5065687-primary.dvr.enable
= false
–defines if DVR recording is allowed. By default, it is false
– not allowed.
stringstreams.camera-uid5065687-primary.dvr.location
REQUIRED = file:///storage/
– when DVR recording is enabled, this parameter is required and defines the archive storage location.
bytesstreams.camera-uid5065687-primary.dvr.quota
= 0G
–
Sets the archive storage volume limit. If the parameter isn’t specified or equals 0
, the storage volume is unlimited.
The following abbreviations can be used in this context: G
– gigabyte (example: 30G
), M
– megabyte (example: 120M
), K
– kilobyte (example: 20K
).
In the current version, this parameter doesn't limit disk usage. When calling the API, this parameter can be used as a reference but doesn’t enforce any physical disk space constraints.
boolstreams.camera-uid5065687-primary.enable
=true
– whether the camera is allowed.
ReconnectParamsstreams.camera-uid5065687-primary.reconnect
– parameters for reconnecting to a stream upon network loss or disconnect.
numberstreams.camera-uid5065687-primary.reconnect.interval
= 10
– a minimum timeout in seconds between attempts to connect to the camera stream.
numberstreams.camera-uid5065687-primary.reconnect.period
= 1800
– a maximum time interval after which a connection to the camera will be attempted in case of consecutive failed reconnection attempts.
numberstreams.camera-uid5065687-primary.reconnect.total
=500
– a number of consecutive failed connection attempts, after which the Mediaserver will stop retrying and mark the stream as invalid
.
urlstreams.camera-uid5065687-primary.source
= rtsp://admin:admin@192.168.19.192:554/av0_0
– RTSP URL of a stream.
uidstreams.camera-uid5065687-primary.stream
REQUIRED=camera-uid5065687-primary
– a unique stream identifier within the installation.
arraystreams.camera-uid5065687-primary.tracks
="audio","video"]
– the list of media streams to capture. If it’s not specified, the video
stream will be captured.
video
– capture the stream with video data. Will be constantly captured regardless the settings. Supports H.264 and H.265 codecs.audio
– capture the audio stream. If there is no stream in the initial RTSP, the stream won’t be created and captured. Supports the following codecs: PCMU, PCMA, MPA, AAC.application
– capture the metadata stream. Supports ONVIF.
OnvifObject onvif
– sets the ONVIF parameters for a camera.
object OnvifObject
EventObjectonvif.events
– the event handlers.
stringonvif.events.MotionAlarm
=dvr|live|capture|publish
– – the list of the MotionAlarm
event handlers.
stringonvif.events.PowerAlarm
=dvr|publish
– the list of the PowerAlarm
event handlers.
urlonvif.hostname
=192.168.19.192
– an address.
POST /api/ |
JSON-RPC
{
"jsonrpc": "2.0",
"method": "Camera.Add",
"params": {
"camera": "camera-uid5065687",
"streams": {
"camera-uid5065687-primary": {
"access": {
"allow": "private",
"password": "admin",
"user": "admin",
"whitelist": [
"192.168.100.200",
"192.168.100.201"
]
},
"camera": "camera-uid5065687",
"cluster": {
"primary": "string"
},
"reconnect": {
"interval": 10,
"period": 1800,
"total": 500
},
"dvr": {
"enable": true,
"location": "file:///storage/",
"duration": "1d",
"buffer": "1M",
"quota": "0G"
},
"enable": true,
"source": "rtsp://admin:admin@192.168.19.192:554/av0_0",
"stream": "camera-uid5065687-primary",
"tracks": [
"audio",
"video"
]
}
},
"onvif": {
"hostname": "192.168.19.192",
"events": {
"MotionAlarm": "dvr|live|capture|publish",
"PowerAlarm": "dvr|publish"
}
}
},
"id": 1
}
cURL
curl -k --request POST \
--url 'https://your-domain/api/' \
--header 'Content-Length: 1528' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <api-authorization-token>' \
--header 'Content-Length: <Data length>' \
--data '{
"jsonrpc": "2.0",
"method": "Camera.Add",
"params": {
"camera": "camera-uid5065687",
"streams": {
"camera-uid5065687-primary": {
"access": {
"allow": "private",
"password": "admin",
"user": "admin",
"whitelist": [
"192.168.100.200",
"192.168.100.201"
]
},
"camera": "camera-uid5065687",
"cluster": {
"primary": "string"
},
"reconnect": {
"interval": 10,
"period": 1800,
"total": 500
},
"dvr": {
"enable": true,
"location": "file:///storage/",
"duration": "1d",
"buffer": "1M",
"quota": "0G"
},
"enable": true,
"source": "rtsp://admin:admin@192.168.19.192:554/av0_0",
"stream": "camera-uid5065687-primary",
"tracks": [
"audio",
"video"
]
}
},
"onvif": {
"hostname": "192.168.19.192",
"events": {
"MotionAlarm": "dvr|live|capture|publish",
"PowerAlarm": "dvr|publish"
}
}
},
"id": 1
}'
PHP
$data = array (
'jsonrpc' => '2.0',
'method' => 'Camera.Add',
'params' =>
array (
'camera' => 'camera-uid5065687',
'streams' =>
array (
'camera-uid5065687-primary' =>
array (
'access' =>
array (
'allow' => 'private',
'password' => 'admin',
'user' => 'admin',
'whitelist' =>
array (
0 => '192.168.100.200',
1 => '192.168.100.201',
),
),
'camera' => 'camera-uid5065687',
'cluster' =>
array (
'primary' => 'string',
),
'reconnect' =>
array (
'interval' => 10,
'period' => 1800,
'total' => 500,
),
'dvr' =>
array (
'enable' => true,
'location' => 'file:///storage/',
'duration' => '1d',
'buffer' => '1M',
'quota' => '0G',
),
'enable' => true,
'source' => 'rtsp://admin:admin@192.168.19.192:554/av0_0',
'stream' => 'camera-uid5065687-primary',
'tracks' =>
array (
0 => 'audio',
1 => 'video',
),
),
),
'onvif' =>
array (
'hostname' => '192.168.19.192',
'events' =>
array (
'MotionAlarm' => 'dvr|live|capture|publish',
'PowerAlarm' => 'dvr|publish',
),
),
),
'id' => 1,
);
$context = stream_context_create([
'ssl'=>['verify_peer' => false],
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/json\r
Accept: application/json\r
Authorization: Bearer <api-authorization-token>\r
Content-Length: <Data length>",
'content'=>json_encode($data)
]
]);
$result = file_get_contents('https://your-domain/api/', false, $context);
200 |
The UID of an added stream
JSON
|
400 |
An error JSON-RPC
JSON
|
500 |